Skip to content

Commit

Permalink
perf
Browse files Browse the repository at this point in the history
  • Loading branch information
QIN2DIM committed Sep 28, 2023
1 parent cfaf48a commit 499dc10
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
15 changes: 11 additions & 4 deletions automation/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
from github.GitReleaseAsset import GitReleaseAsset
from github.Repository import Repository
from hcaptcha_challenger import ModelHub
from hcaptcha_challenger.onnx.modelhub import request_resource
from loguru import logger
import hcaptcha_challenger as solver


if not os.getenv("GITHUB_TOKEN"):
logger.warning("Skip model deployment, miss GITHUB TOKEN")
Expand Down Expand Up @@ -58,6 +57,13 @@ def to_asset(repo: Repository, data_tmp_path: Path, message: str = ""):
)


def upgrade_objects(modelhub: ModelHub):
objects_url = (
"https://raw.githubusercontent.com/QIN2DIM/hcaptcha-challenger/main/src/objects.yaml"
)
request_resource(objects_url, modelhub.objects_path)


class Annotator:
auth = Auth.Token(os.getenv("GITHUB_TOKEN"))
repo = Github(auth=auth).get_repo("QIN2DIM/hcaptcha-challenger")
Expand All @@ -68,9 +74,10 @@ def __init__(self, asset_id: int, matched_label: str = ""):

self._asset: GitReleaseAsset | None = None

solver.install(upgrade=True)

self.modelhub = ModelHub.from_github_repo()

upgrade_objects(modelhub=self.modelhub)

self.modelhub.parse_objects()

self.data: Objects = Objects.from_modelhub(modelhub=self.modelhub)
Expand Down
2 changes: 1 addition & 1 deletion automation/assets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def merge(self, fd: Path, td: Path):


def run():
sources = "https://github.com/QIN2DIM/hcaptcha-challenger/issues/725"
sources = "crow"
am = AssetsManager.from_sources(sources)
am.execute()

Expand Down
11 changes: 4 additions & 7 deletions automation/continue_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from pathlib import Path
from typing import List, Tuple, Literal

import cv2
import hcaptcha_challenger as solver
from hcaptcha_challenger import ResNetControl
from hcaptcha_challenger import LocalBinaryClassifier


@dataclass
Expand All @@ -34,7 +33,6 @@ def __post_init__(self):
]

if not self.model_path or not self.model_path.exists():
print("NOT Found Model_Path, switch to remote mode")
self.branch = "remote"

@classmethod
Expand Down Expand Up @@ -74,11 +72,10 @@ def execute(self):
elif result is False:
shutil.move(self._images[i], bad_dir)
elif self.branch == "local":
net = cv2.dnn.readNetFromONNX(str(self.model_path))
control = ResNetControl.from_pluggable_model(net)
lbc = LocalBinaryClassifier(self.model_path)
for i, image_path in enumerate(self._images):
image = image_path.read_bytes()
result = control.binary_classify(image)
result = lbc.parse_once(image)
if result is True:
shutil.move(self._images[i], yes_dir)
elif result is False:
Expand Down Expand Up @@ -112,4 +109,4 @@ def run(prompt: str, model_name: str | None = None):


if __name__ == "__main__":
run("crane")
run("crow")
2 changes: 1 addition & 1 deletion automation/datasets_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
collected = []
per_times = 50
tmp_dir = Path(__file__).parent.joinpath("tmp_dir")
sitekey = SiteKey.discord
sitekey = SiteKey.user_easy


async def collete_datasets(context: ASyncContext):
Expand Down
2 changes: 2 additions & 0 deletions automation/mini_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def roll_upgrade(asset_id):
# "plant": "plant2315",
# "river": "river2310" # 1
# "crane": "crane2300",
"snowman": "snowman2310",
# "crow": "crow2309",
}
# fmt:on

Expand Down
2 changes: 1 addition & 1 deletion automation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
hcaptcha-challenger[sentinel]==0.8.2-post1
hcaptcha-challenger[sentinel]==0.8.3
bs4

0 comments on commit 499dc10

Please sign in to comment.