Skip to content
This repository has been archived by the owner on Mar 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from robmarkcole/add-confidence-filter-to-face
Browse files Browse the repository at this point in the history
Update deepstack-ui.py
  • Loading branch information
robmarkcole committed Jan 3, 2021
2 parents 184e41f + af900e7 commit eb0e580
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions app/deepstack-ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def process_image_face(pil_image, dsface):


deepstack_mode = st.selectbox("Select Deepstack mode:", [OBJECT, FACE])
## Setup sidebar
st.sidebar.title("Parameters")
st.text("Adjust parameters to select what is displayed")
CONFIDENCE_THRESHOLD = st.sidebar.slider(
"Confidence threshold",
MIN_CONFIDENCE_THRESHOLD,
MAX_CONFIDENCE_THRESHOLD,
DEFAULT_CONFIDENCE_THRESHOLD,
)

if deepstack_mode == FACE:
st.title("Deepstack Face recogntion")
Expand All @@ -74,26 +83,37 @@ def process_image_face(pil_image, dsface):
)
predictions = process_image_face(pil_image, dsface)
faces = utils.get_faces(predictions, pil_image.width, pil_image.height)
recognised_faces = [
face for face in faces if face["confidence"] > CONFIDENCE_THRESHOLD
]

# Draw object boxes
draw = ImageDraw.Draw(pil_image)
for face in faces:
name = face["name"]
confidence = face["confidence"]
box = face["bounding_box"]
name = face["name"]
box_label = f"{name}"
box = face["bounding_box"]
if confidence < CONFIDENCE_THRESHOLD or name == "unknown":
box_colour = const.YELLOW
else:
box_colour = const.GREEN

utils.draw_box(
draw,
(box["y_min"], box["x_min"], box["y_max"], box["x_max"]),
pil_image.width,
pil_image.height,
text=box_label,
color=const.YELLOW,
color=box_colour,
)
st.image(
np.array(pil_image), caption=f"Processed image", use_column_width=True,
)

st.subheader("All recognised faces")
st.write(recognised_faces)

st.subheader("All faces")
st.write(faces)

Expand Down Expand Up @@ -123,16 +143,6 @@ def process_image_face(pil_image, dsface):
else:
st.text(f"Using custom model named {DEEPSTACK_CUSTOM_MODEL}")

## Setup sidebar
st.sidebar.title("Parameters")
st.text("Adjust parameters to select what is displayed")
CONFIDENCE_THRESHOLD = st.sidebar.slider(
"Confidence threshold",
MIN_CONFIDENCE_THRESHOLD,
MAX_CONFIDENCE_THRESHOLD,
DEFAULT_CONFIDENCE_THRESHOLD,
)

# Get ROI info
st.sidebar.title("ROI")
ROI_X_MIN = st.sidebar.slider("x_min", 0.0, 1.0, DEFAULT_ROI_X_MIN)
Expand Down

0 comments on commit eb0e580

Please sign in to comment.