ryefoxlime
commited on
Commit
•
a583b5e
1
Parent(s):
54cac64
FER Working on RPi with ~30sec predict time
Browse files- FER/data_preprocessing/__pycache__/sam.cpython-311.pyc +0 -0
- FER/detectfaces.py +5 -6
- FER/models/PosterV2_7cls.py +1 -1
- FER/models/checkpoints/raf-db-model_best.pth +0 -3
- FER/prediction.py +1 -26
- camera.py +15 -0
- pyproject.toml +3 -0
FER/data_preprocessing/__pycache__/sam.cpython-311.pyc
DELETED
Binary file (4.7 kB)
|
|
FER/detectfaces.py
CHANGED
@@ -6,8 +6,10 @@ import time
|
|
6 |
from PIL import Image
|
7 |
from main import RecorderMeter1, RecorderMeter # noqa: F401
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Determine the available device for model execution
|
13 |
if torch.backends.mps.is_available():
|
@@ -86,9 +88,6 @@ def imagecapture(model):
|
|
86 |
cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
|
87 |
).detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5, minSize=(30, 30))
|
88 |
|
89 |
-
# Display the current frame
|
90 |
-
cv2.imshow("Webcam", frame)
|
91 |
-
|
92 |
# If faces are detected, proceed with prediction
|
93 |
if len(faces) > 0:
|
94 |
currtimeimg = time.strftime("%H:%M:%S")
|
@@ -107,7 +106,7 @@ def imagecapture(model):
|
|
107 |
starttime = time.strftime("%H:%M:%S")
|
108 |
print(f"-->Prediction starting at {starttime}")
|
109 |
# Perform emotion prediction
|
110 |
-
|
111 |
# Record the prediction end time
|
112 |
endtime = time.strftime("%H:%M:%S")
|
113 |
print(f"-->Done prediction at {endtime}")
|
|
|
6 |
from PIL import Image
|
7 |
from main import RecorderMeter1, RecorderMeter # noqa: F401
|
8 |
|
9 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
10 |
+
|
11 |
+
# Construct the full path to the model file
|
12 |
+
model_path = os.path.join(script_dir,"models","checkpoints","raf-db-model_best.pth")
|
13 |
|
14 |
# Determine the available device for model execution
|
15 |
if torch.backends.mps.is_available():
|
|
|
88 |
cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
|
89 |
).detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5, minSize=(30, 30))
|
90 |
|
|
|
|
|
|
|
91 |
# If faces are detected, proceed with prediction
|
92 |
if len(faces) > 0:
|
93 |
currtimeimg = time.strftime("%H:%M:%S")
|
|
|
106 |
starttime = time.strftime("%H:%M:%S")
|
107 |
print(f"-->Prediction starting at {starttime}")
|
108 |
# Perform emotion prediction
|
109 |
+
face_detection(model, image_path=face_pil_image)
|
110 |
# Record the prediction end time
|
111 |
endtime = time.strftime("%H:%M:%S")
|
112 |
print(f"-->Done prediction at {endtime}")
|
FER/models/PosterV2_7cls.py
CHANGED
@@ -309,7 +309,7 @@ class pyramid_trans_expr2(nn.Module):
|
|
309 |
mobilefacenet_path = os.path.join(
|
310 |
script_dir, "pretrain", "mobilefacenet_model_best.pth.tar"
|
311 |
)
|
312 |
-
ir50_path = os.path.join(script_dir,
|
313 |
|
314 |
print(mobilefacenet_path)
|
315 |
face_landback_checkpoint = torch.load(
|
|
|
309 |
mobilefacenet_path = os.path.join(
|
310 |
script_dir, "pretrain", "mobilefacenet_model_best.pth.tar"
|
311 |
)
|
312 |
+
ir50_path = os.path.join(script_dir, "pretrain","ir50.pth")
|
313 |
|
314 |
print(mobilefacenet_path)
|
315 |
face_landback_checkpoint = torch.load(
|
FER/models/checkpoints/raf-db-model_best.pth
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:d9bf1d0d88238966ce0d1a289a2bb5f927ec2fe635ef1ec4396c323028924701
|
3 |
-
size 238971279
|
|
|
|
|
|
|
|
FER/prediction.py
CHANGED
@@ -23,7 +23,7 @@ model = model.to(device)
|
|
23 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
24 |
|
25 |
# Construct the full path to the model file
|
26 |
-
model_path = os.path.join(script_dir,
|
27 |
|
28 |
image_arr = []
|
29 |
for foldername, subfolders, filenames in os.walk("../FER/Images/"):
|
@@ -32,27 +32,6 @@ for foldername, subfolders, filenames in os.walk("../FER/Images/"):
|
|
32 |
file_path = os.path.join(foldername, filename)
|
33 |
image_arr.append(f"{file_path}")
|
34 |
|
35 |
-
|
36 |
-
def main():
|
37 |
-
if model_path is not None:
|
38 |
-
if os.path.isfile(model_path):
|
39 |
-
print("=> loading checkpoint '{}'".format(model_path))
|
40 |
-
checkpoint = torch.load(model_path, map_location=device)
|
41 |
-
best_acc = checkpoint["best_acc"]
|
42 |
-
best_acc = best_acc.to()
|
43 |
-
print(f"best_acc:{best_acc}")
|
44 |
-
model.load_state_dict(checkpoint["state_dict"])
|
45 |
-
print(
|
46 |
-
"=> loaded checkpoint '{}' (epoch {})".format(
|
47 |
-
model_path, checkpoint["epoch"]
|
48 |
-
)
|
49 |
-
)
|
50 |
-
else:
|
51 |
-
print("[!] prediction.py => no checkpoint found at '{}'".format(model_path))
|
52 |
-
predict(model, image_path=image_arr)
|
53 |
-
return
|
54 |
-
|
55 |
-
|
56 |
def predict(model, image_path):
|
57 |
from face_detection import face_detection
|
58 |
|
@@ -102,7 +81,3 @@ def predict(model, image_path):
|
|
102 |
f"-->Image Path {image_path} [!] The predicted labels are {y_pred} and the label is {labels}"
|
103 |
)
|
104 |
return
|
105 |
-
|
106 |
-
|
107 |
-
if __name__ == "__main__":
|
108 |
-
main()
|
|
|
23 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
24 |
|
25 |
# Construct the full path to the model file
|
26 |
+
model_path = os.path.join(script_dir,"models","checkpoints","raf-db-model_best.pth")
|
27 |
|
28 |
image_arr = []
|
29 |
for foldername, subfolders, filenames in os.walk("../FER/Images/"):
|
|
|
32 |
file_path = os.path.join(foldername, filename)
|
33 |
image_arr.append(f"{file_path}")
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
def predict(model, image_path):
|
36 |
from face_detection import face_detection
|
37 |
|
|
|
81 |
f"-->Image Path {image_path} [!] The predicted labels are {y_pred} and the label is {labels}"
|
82 |
)
|
83 |
return
|
|
|
|
|
|
|
|
camera.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
|
3 |
+
# initialize the camera
|
4 |
+
cap = cv2.VideoCapture(0, cv2.CAP_V4L2)
|
5 |
+
|
6 |
+
# capture a frame
|
7 |
+
ret, frame = cap.read()
|
8 |
+
|
9 |
+
# release the camera
|
10 |
+
cap.release()
|
11 |
+
|
12 |
+
# save the captured frame
|
13 |
+
cv2.imwrite('captured_image.jpg', frame)
|
14 |
+
|
15 |
+
|
pyproject.toml
CHANGED
@@ -134,3 +134,6 @@ dependencies = [
|
|
134 |
|
135 |
[[tool.uv.index]]
|
136 |
url = "https://download.pytorch.org/whl/cu124"
|
|
|
|
|
|
|
|
134 |
|
135 |
[[tool.uv.index]]
|
136 |
url = "https://download.pytorch.org/whl/cu124"
|
137 |
+
|
138 |
+
[[tool.uv.index]]
|
139 |
+
url = "https://pypi.org/simple"
|