diff --git a/automation/assets_manager.py b/automation/assets_manager.py index 703c955b..ecbd94ef 100644 --- a/automation/assets_manager.py +++ b/automation/assets_manager.py @@ -137,7 +137,7 @@ def merge(self, fd: Path, td: Path): def run(): - sources = "https://github.com/QIN2DIM/hcaptcha-challenger/issues/872" + sources = "https://github.com/QIN2DIM/hcaptcha-challenger/issues/826" am = AssetsManager.from_sources(sources) am.execute() diff --git a/automation/auto_labeling.py b/automation/auto_labeling.py index 0582488e..55de204b 100644 --- a/automation/auto_labeling.py +++ b/automation/auto_labeling.py @@ -137,7 +137,7 @@ def run(): for card in flow_card: # Filter out the task cards we care about - if "sedan_car" not in card["joined_dirs"]: + if "nested_smallest_turtle" not in card["joined_dirs"]: continue # Generating a dataclass from serialized data dl = DataLake( diff --git a/automation/check_yolo_model.py b/automation/check_yolo_det_model.py similarity index 100% rename from automation/check_yolo_model.py rename to automation/check_yolo_det_model.py diff --git a/automation/check_yolo_seg_model.py b/automation/check_yolo_seg_model.py new file mode 100644 index 00000000..c254334f --- /dev/null +++ b/automation/check_yolo_seg_model.py @@ -0,0 +1,67 @@ +import os +import shutil +import sys +from pathlib import Path + +import cv2 +import hcaptcha_challenger as solver +from hcaptcha_challenger.onnx.modelhub import ModelHub +from hcaptcha_challenger.onnx.yolo import YOLOv8Seg +from tqdm import tqdm + +solver.install(upgrade=True) + +# Initialize model index +modelhub = ModelHub.from_github_repo() +modelhub.parse_objects() + +db_dir = Path(__file__).parent.parent.joinpath("database2309") +input_dirname = "click_on_the_star_with_a_texture_of_bricks_default" + +# Select model +model_name = "star_with_a_texture_of_bricks_2309_yolov8s-seg.onnx" +classes = ["star-bricks"] + + +def yolov8_segment(images_dir: Path, output_dir: Path): + session = modelhub.match_net(model_name) + yoloseg = YOLOv8Seg.from_pluggable_model(session, classes) + + # Initialize progress bar + desc_in = f'"{images_dir.parent.name}/{images_dir.name}"' + with tqdm(total=len(os.listdir(images_dir)), desc=f"Labeling | {desc_in}") as progress: + for image_name in os.listdir(images_dir): + image_path = images_dir.joinpath(image_name) + if not image_path.is_file(): + progress.total -= 1 + continue + # Find all the circles in the picture + yoloseg(image_path, shape_type="point") + + # Draw a bounding box and mask region for all circles + img = cv2.imread(str(image_path)) + combined_img = yoloseg.draw_masks(img, mask_alpha=0.5) + output_path = output_dir.joinpath(image_path.name) + cv2.imwrite(str(output_path), combined_img) + + progress.update(1) + + if "win32" in sys.platform and "PYTEST_RUN_CONFIG" not in os.environ: + os.startfile(output_dir) + print(f">> View at {output_dir}") + + +def demo(): + images_dir = db_dir.joinpath(input_dirname) + + output_dir = Path(__file__).parent.joinpath( + "yolo_mocker", "figs-star-bricks-seg-out", images_dir.name + ) + shutil.rmtree(output_dir, ignore_errors=True) + output_dir.mkdir(parents=True, exist_ok=True) + + yolov8_segment(images_dir, output_dir) + + +if __name__ == "__main__": + demo() diff --git a/automation/flow_card.py b/automation/flow_card.py index 32971138..fb6f4df6 100644 --- a/automation/flow_card.py +++ b/automation/flow_card.py @@ -21,4 +21,9 @@ "negative_labels": ["bicycle", "off-road vehicle"], "joined_dirs": ["sedan_car"], }, + { + "positive_labels": ["turtle"], + "negative_labels": ["horse", "bear", "giraffe", "dolphins"], + "joined_dirs": ["please_click_on_the_smallest_animal", "nested_smallest_turtle"], + }, ] diff --git a/automation/mini_workflow.py b/automation/mini_workflow.py index 0da11d46..f0ee8e66 100644 --- a/automation/mini_workflow.py +++ b/automation/mini_workflow.py @@ -88,11 +88,12 @@ def upgrade_objects(aid_): # fmt:off focus_flags = { # "": "" - "sedan_car": "sedan_car2309", + # "sedan_car": "sedan_car2309", + "nested_smallest_turtle": "nested_smallest_turtle2309", } # fmt:on quick_train() aid = quick_development() - upgrade_objects(aid) + # upgrade_objects(aid) print(aid)