Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -41,19 +41,20 @@ async def predict_api(
|
|
41 |
# last_seen: Union[UploadFile, None] = File(None),
|
42 |
last_seen: Optional[str] = Form(None),
|
43 |
):
|
|
|
44 |
total_time = time.time()
|
45 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
46 |
image = read_image_file(await file.read())
|
47 |
-
print("Read image", time.time() - start_time)
|
48 |
-
start_time = time.time()
|
49 |
results = model.predict(image, show=False)[0]
|
50 |
-
print("Model predict", time.time() - start_time)
|
51 |
masks, boxes = results.masks, results.boxes
|
52 |
area_image = image.width * image.height
|
53 |
-
|
54 |
-
|
55 |
-
diff_value = 0.5
|
56 |
-
start_time = time.time()
|
57 |
if boxes is not None:
|
58 |
for xyxy, conf, cls in zip(boxes.xyxy, boxes.conf, boxes.cls):
|
59 |
if int(cls) != 0:
|
@@ -64,7 +65,8 @@ async def predict_api(
|
|
64 |
out_img = image.crop(tuple(box)).resize((64, 64))
|
65 |
most_close = area_rate
|
66 |
print("Get face time", time.time() - start_time)
|
67 |
-
|
|
|
68 |
start_time = time.time()
|
69 |
if last_seen is not None:
|
70 |
if type(last_seen) == str:
|
@@ -74,7 +76,8 @@ async def predict_api(
|
|
74 |
if out_img is not None:
|
75 |
diff_value = dist.euclidean(get_hist(out_img), get_hist(last_seen))
|
76 |
print("Hist time", time.time() - start_time)
|
77 |
-
|
|
|
78 |
start_time = time.time()
|
79 |
print(f"Distance: {most_close}. Different value: {diff_value}")
|
80 |
if most_close >= area_thres and diff_value >= 0.5:
|
|
|
41 |
# last_seen: Union[UploadFile, None] = File(None),
|
42 |
last_seen: Optional[str] = Form(None),
|
43 |
):
|
44 |
+
# parameters
|
45 |
total_time = time.time()
|
46 |
start_time = time.time()
|
47 |
+
most_close = 0
|
48 |
+
out_img = None
|
49 |
+
diff_value = 0.5
|
50 |
+
|
51 |
+
# read image and predict
|
52 |
image = read_image_file(await file.read())
|
|
|
|
|
53 |
results = model.predict(image, show=False)[0]
|
|
|
54 |
masks, boxes = results.masks, results.boxes
|
55 |
area_image = image.width * image.height
|
56 |
+
|
57 |
+
# select and crop face image
|
|
|
|
|
58 |
if boxes is not None:
|
59 |
for xyxy, conf, cls in zip(boxes.xyxy, boxes.conf, boxes.cls):
|
60 |
if int(cls) != 0:
|
|
|
65 |
out_img = image.crop(tuple(box)).resize((64, 64))
|
66 |
most_close = area_rate
|
67 |
print("Get face time", time.time() - start_time)
|
68 |
+
|
69 |
+
# check with previous image if have
|
70 |
start_time = time.time()
|
71 |
if last_seen is not None:
|
72 |
if type(last_seen) == str:
|
|
|
76 |
if out_img is not None:
|
77 |
diff_value = dist.euclidean(get_hist(out_img), get_hist(last_seen))
|
78 |
print("Hist time", time.time() - start_time)
|
79 |
+
|
80 |
+
# return results
|
81 |
start_time = time.time()
|
82 |
print(f"Distance: {most_close}. Different value: {diff_value}")
|
83 |
if most_close >= area_thres and diff_value >= 0.5:
|