Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 17, 2024
1 parent 0850ba5 commit fb96474
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions aaaaaa/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ def detection(w: Widgets, n: int, is_img2img: bool):
elem_id=eid("ad_confidence"),
)
w.ad_mask_filter_method = gr.Radio(
choices=["Area", "Confidence"],
choices=["Area", "Confidence"],
value="Area",
label="Method to filter top k masks by (confidence or area)",
visible=True,
elem_id=eid("ad_mask_filter_method")
elem_id=eid("ad_mask_filter_method"),
)
w.ad_mask_k = gr.Slider(
label="Mask only the top k (0 to disable)" + suffix(n),
Expand Down
2 changes: 2 additions & 0 deletions adetailer/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def filter_k_largest(pred: PredictOutput[T], k: int = 0) -> PredictOutput[T]:
pred.masks = [pred.masks[i] for i in idx]
return pred


def filter_k_most_confident(pred: PredictOutput[T], k: int = 0) -> PredictOutput[T]:
if not pred.bboxes or not pred.confidences or k == 0:
return pred
Expand All @@ -247,6 +248,7 @@ def filter_k_most_confident(pred: PredictOutput[T], k: int = 0) -> PredictOutput
pred.masks = [pred.masks[i] for i in idx]
return pred


# Merge / Invert
def mask_merge(masks: list[Image.Image]) -> list[Image.Image]:
arrs = [np.array(m) for m in masks]
Expand Down
6 changes: 4 additions & 2 deletions adetailer/mediapipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def mediapipe_face_detection(
masks = create_mask_from_bbox(bboxes, image.size)
preview = Image.fromarray(preview_array)

return PredictOutput(bboxes=bboxes, masks=masks, confidences=confidences, preview=preview)
return PredictOutput(
bboxes=bboxes, masks=masks, confidences=confidences, preview=preview
)


def mediapipe_face_mesh(
Expand Down Expand Up @@ -157,7 +159,7 @@ def mediapipe_face_mesh_eyes_only(
for outline in (left_outline, right_outline):
draw.polygon(outline, fill="white")
masks.append(mask)

bboxes = create_bbox_from_mask(masks, image.size)
preview = draw_preview(preview, bboxes, masks)
return PredictOutput(bboxes=bboxes, masks=masks, preview=preview)
Expand Down
4 changes: 3 additions & 1 deletion adetailer/ultralytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def ultralytics_predict(
preview = cv2.cvtColor(preview, cv2.COLOR_BGR2RGB)
preview = Image.fromarray(preview)

return PredictOutput(bboxes=bboxes, masks=masks, confidences=confidences, preview=preview)
return PredictOutput(
bboxes=bboxes, masks=masks, confidences=confidences, preview=preview
)


def apply_classes(model: YOLO | YOLOWorld, model_path: str | Path, classes: str):
Expand Down

0 comments on commit fb96474

Please sign in to comment.