Add `--face-confidence-threshold`
This commit is contained in:
parent
eedc2783c9
commit
32d523b727
|
@ -83,7 +83,7 @@ def main():
|
||||||
# May be better to check every iteration, but this also works
|
# May be better to check every iteration, but this also works
|
||||||
if path_to_faces_exists:
|
if path_to_faces_exists:
|
||||||
if face_details := utils.recognize_face(
|
if face_details := utils.recognize_face(
|
||||||
path_to_directory=path_to_faces, run_frame=run_frame
|
path_to_directory=path_to_faces, run_frame=run_frame, min_confidence=args.face_confidence_threshold
|
||||||
):
|
):
|
||||||
plot_boxes.append(face_details)
|
plot_boxes.append(face_details)
|
||||||
objects_and_peoples = notify.thing_detected(
|
objects_and_peoples = notify.thing_detected(
|
||||||
|
@ -132,7 +132,7 @@ def main():
|
||||||
# print("---")
|
# print("---")
|
||||||
|
|
||||||
# Now do stuff (if conf > 0.5)
|
# Now do stuff (if conf > 0.5)
|
||||||
if conf < args.confidence_threshold or (
|
if conf < args.object_confidence_threshold or (
|
||||||
class_id not in args.detect_object and args.detect_object != []
|
class_id not in args.detect_object and args.detect_object != []
|
||||||
):
|
):
|
||||||
# If the confidence is too low
|
# If the confidence is too low
|
||||||
|
|
|
@ -20,7 +20,9 @@ def set_argparse():
|
||||||
epilog=":)",
|
epilog=":)",
|
||||||
)
|
)
|
||||||
|
|
||||||
# required='RUN_SCALE' not in os.environ,
|
|
||||||
|
# One important thing to consider is that most function parameters are optional and have a default value
|
||||||
|
# However, with argparse, those are never used since a argparse always passes something, even if it's None
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--run-scale",
|
"--run-scale",
|
||||||
|
@ -53,7 +55,7 @@ def set_argparse():
|
||||||
)
|
)
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--confidence-threshold",
|
"--object-confidence-threshold",
|
||||||
default=os.environ["CONFIDENCE_THRESHOLD"]
|
default=os.environ["CONFIDENCE_THRESHOLD"]
|
||||||
if "CONFIDENCE_THRESHOLD" in os.environ
|
if "CONFIDENCE_THRESHOLD" in os.environ
|
||||||
and os.environ["CONFIDENCE_THRESHOLD"] != ""
|
and os.environ["CONFIDENCE_THRESHOLD"] != ""
|
||||||
|
@ -61,7 +63,15 @@ def set_argparse():
|
||||||
type=float,
|
type=float,
|
||||||
help="The confidence threshold to use",
|
help="The confidence threshold to use",
|
||||||
)
|
)
|
||||||
|
argparser.add_argument(
|
||||||
|
"--face-confidence-threshold",
|
||||||
|
default=os.environ["FACE_CONFIDENCE_THRESHOLD"]
|
||||||
|
if "FACE_CONFIDENCE_THRESHOLD" in os.environ
|
||||||
|
and os.environ["FACE_CONFIDENCE_THRESHOLD"] != ""
|
||||||
|
else 0.3,
|
||||||
|
type=float,
|
||||||
|
help="The confidence (currently cosine similarity) threshold to use for face recognition",
|
||||||
|
)
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--faces-directory",
|
"--faces-directory",
|
||||||
default=os.environ["FACES_DIRECTORY"]
|
default=os.environ["FACES_DIRECTORY"]
|
||||||
|
|
|
@ -68,6 +68,7 @@ def recognize_face(
|
||||||
path_to_directory: Path = Path("faces"),
|
path_to_directory: Path = Path("faces"),
|
||||||
# opencv image
|
# opencv image
|
||||||
run_frame: np.ndarray = None,
|
run_frame: np.ndarray = None,
|
||||||
|
min_confidence: float = 0.3,
|
||||||
) -> np.ndarray:
|
) -> np.ndarray:
|
||||||
"""
|
"""
|
||||||
Accepts a path to a directory of images of faces to be used as a refference
|
Accepts a path to a directory of images of faces to be used as a refference
|
||||||
|
@ -149,15 +150,13 @@ def recognize_face(
|
||||||
"y2": df.iloc[-1]["source_y"] + df.iloc[-1]["source_h"],
|
"y2": df.iloc[-1]["source_y"] + df.iloc[-1]["source_h"],
|
||||||
}
|
}
|
||||||
# After some brief testing, it seems positive matches are > 0.3
|
# After some brief testing, it seems positive matches are > 0.3
|
||||||
distance = df.iloc[-1]["ArcFace_cosine"]
|
cosine_similarity = df.iloc[-1]["ArcFace_cosine"]
|
||||||
# TODO: Make this a CLI argument
|
if cosine_similarity < min_confidence:
|
||||||
if distance < 0.3:
|
|
||||||
return None
|
return None
|
||||||
# if 0.5 < distance < 0.7:
|
|
||||||
# label = "Unknown"
|
# label = "Unknown"
|
||||||
to_return = dict(label=label, **coordinates)
|
to_return = dict(label=label, **coordinates)
|
||||||
print(
|
print(
|
||||||
f"Confindence: {distance}, filname: {path_to_image.name}, to_return: {to_return}"
|
f"Cosine similarity: {cosine_similarity}, filname: {path_to_image.name}, to_return: {to_return}"
|
||||||
)
|
)
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue