Skip to content

Commit

Permalink
ffe
Browse files Browse the repository at this point in the history
  • Loading branch information
QIN2DIM committed Oct 27, 2023
1 parent c402644 commit e144cf0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion automation/assets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion automation/auto_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions automation/check_yolo_seg_model.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions automation/flow_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
]
5 changes: 3 additions & 2 deletions automation/mini_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ def upgrade_objects(aid_):
# fmt:off
focus_flags = {
# "<diagnosed_label_name>": "<model_name[flag]>"
"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)

0 comments on commit e144cf0

Please sign in to comment.