Align task API and add FunCaptcha support
This commit is contained in:
68
cli.py
68
cli.py
@@ -18,6 +18,8 @@ CaptchaBreaker 命令行入口
|
||||
python cli.py train-solver rotate
|
||||
python cli.py solve slide --bg bg.png [--tpl tpl.png]
|
||||
python cli.py solve rotate --image img.png
|
||||
python cli.py train-funcaptcha --question 4_3d_rollball_animals
|
||||
python cli.py predict-funcaptcha image.jpg --question 4_3d_rollball_animals
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -125,6 +127,7 @@ def cmd_export(args):
|
||||
"3d_text": "threed_text",
|
||||
"3d_rotate": "threed_rotate",
|
||||
"3d_slider": "threed_slider",
|
||||
"4_3d_rollball_animals": "funcaptcha_rollball_animals",
|
||||
}
|
||||
name = alias.get(args.model, args.model)
|
||||
_load_and_export(name)
|
||||
@@ -284,6 +287,52 @@ def cmd_solve(args):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def cmd_train_funcaptcha(args):
|
||||
"""训练 FunCaptcha 专项模型。"""
|
||||
from config import FUN_CAPTCHA_TASKS
|
||||
from training.train_funcaptcha_rollball import main as train_rollball
|
||||
|
||||
question = args.question
|
||||
if question not in FUN_CAPTCHA_TASKS:
|
||||
print(f"未知 FunCaptcha question: {question} 可选: {', '.join(FUN_CAPTCHA_TASKS)}")
|
||||
sys.exit(1)
|
||||
|
||||
if question == "4_3d_rollball_animals":
|
||||
train_rollball(question=question)
|
||||
return
|
||||
|
||||
print(f"暂未实现该 FunCaptcha 训练入口: {question}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def cmd_predict_funcaptcha(args):
|
||||
"""专项 FunCaptcha 预测。"""
|
||||
from config import FUN_CAPTCHA_TASKS
|
||||
from inference.fun_captcha import FunCaptchaRollballPipeline
|
||||
|
||||
image_path = args.image
|
||||
question = args.question
|
||||
if not Path(image_path).exists():
|
||||
print(f"文件不存在: {image_path}")
|
||||
sys.exit(1)
|
||||
if question not in FUN_CAPTCHA_TASKS:
|
||||
print(f"未知 FunCaptcha question: {question} 可选: {', '.join(FUN_CAPTCHA_TASKS)}")
|
||||
sys.exit(1)
|
||||
|
||||
if question == "4_3d_rollball_animals":
|
||||
pipeline = FunCaptchaRollballPipeline(question=question)
|
||||
else:
|
||||
print(f"暂未实现该 FunCaptcha 预测入口: {question}")
|
||||
sys.exit(1)
|
||||
|
||||
result = pipeline.solve(image_path)
|
||||
print(f"文件: {image_path}")
|
||||
print(f"question: {result['question']}")
|
||||
print(f"objects: {result['objects']}")
|
||||
print(f"result: {result['result']}")
|
||||
print(f"耗时: {result['time_ms']:.1f} ms")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="captcha-breaker",
|
||||
@@ -352,6 +401,23 @@ def main():
|
||||
p_solve.add_argument("--tpl", default=None, help="模板图路径 (slide 可选)")
|
||||
p_solve.add_argument("--image", help="图片路径 (rotate 必需)")
|
||||
|
||||
# ---- train-funcaptcha ----
|
||||
p_train_fun = subparsers.add_parser("train-funcaptcha", help="训练 FunCaptcha 专项模型")
|
||||
p_train_fun.add_argument(
|
||||
"--question",
|
||||
required=True,
|
||||
help="专项 question,如: 4_3d_rollball_animals",
|
||||
)
|
||||
|
||||
# ---- predict-funcaptcha ----
|
||||
p_pred_fun = subparsers.add_parser("predict-funcaptcha", help="识别单张 FunCaptcha challenge")
|
||||
p_pred_fun.add_argument("image", help="图片路径")
|
||||
p_pred_fun.add_argument(
|
||||
"--question",
|
||||
required=True,
|
||||
help="专项 question,如: 4_3d_rollball_animals",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command is None:
|
||||
@@ -368,6 +434,8 @@ def main():
|
||||
"generate-solver": cmd_generate_solver,
|
||||
"train-solver": cmd_train_solver,
|
||||
"solve": cmd_solve,
|
||||
"train-funcaptcha": cmd_train_funcaptcha,
|
||||
"predict-funcaptcha": cmd_predict_funcaptcha,
|
||||
}
|
||||
|
||||
cmd_map[args.command](args)
|
||||
|
||||
Reference in New Issue
Block a user