mirror of
https://github.com/luguoyixiazi/test_nine.git
synced 2025-12-06 14:52:49 +08:00
Compare commits
13 Commits
6ab2d64bb0
...
89c20e5e8a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89c20e5e8a | ||
|
|
b8137a656f | ||
|
|
b360624837 | ||
|
|
34590d2ed4 | ||
|
|
3aacad3be1 | ||
|
|
ac6f4056bb | ||
|
|
422384800e | ||
|
|
8cde7fcb57 | ||
|
|
4579be58c9 | ||
|
|
513f9dd247 | ||
|
|
aeaab3277d | ||
|
|
6f95139a37 | ||
|
|
5c7e3ec5d4 |
18
README.md
18
README.md
@@ -14,7 +14,7 @@ api:https://github.com/ravizhan/geetest-v3-click-crack
|
||||
|
||||
## 运行步骤
|
||||
|
||||
### 1.安装依赖
|
||||
### 1.安装依赖(本地必选,使用docker跳至[5-b](#docker))
|
||||
|
||||
(可选)a.如果要训练paddle的话还得安装paddlex及图像分类模块,安装看项目https://github.com/PaddlePaddle/PaddleX
|
||||
|
||||
@@ -24,6 +24,11 @@ api:https://github.com/ravizhan/geetest-v3-click-crack
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
仅推理
|
||||
```
|
||||
pip install -r requirements_without_train.txt
|
||||
```
|
||||
|
||||
### 2.自行准备数据集,V3和V4有区别(可选)
|
||||
|
||||
##### a. 训练resnet18(可选)
|
||||
@@ -55,11 +60,16 @@ pip install -r requirements.txt
|
||||
- 运行 `python convert.py`(自行进去修改需要转换的模型,一般是选loss小的)
|
||||
- paddle模型转换要装paddle2onnx,详情参见https://www.paddlepaddle.org.cn/documentation/docs/guides/advanced/model_to_onnx_cn.html
|
||||
|
||||
### 5.启动fastapi服务(必须要有训练完成的onnx格式模型)
|
||||
### 5-a.启动fastapi服务(必须要有训练完成的onnx格式模型)
|
||||
|
||||
运行 `python main.py`(默认用的paddle的onnx模型,如果要用resnet18可以自己改注释)
|
||||
|
||||
由于轨迹问题,可能会出现验证正确但是结果失败,所以建议增加retry次数,训练后的paddle模型正确率在99.9%以上
|
||||
### 5-b.使用docker启动服务
|
||||
|
||||
镜像地址为<span id="docker">luguoyixiazi/test_nine:25.3.21</span>
|
||||
|
||||
运行时只需指定绑定的port即可
|
||||
|
||||
### 6.api调用
|
||||
|
||||
@@ -69,13 +79,15 @@ python调用如:
|
||||
import httpx
|
||||
|
||||
def game_captcha(gt: str, challenge: str):
|
||||
res = httpx.get("http://127.0.0.1:9645/pass_nine",params={'gt':gt,'challenge':challenge,'use_v3_model':True},timeout=10)
|
||||
res = httpx.get("http://127.0.0.1:9645/pass_nine",params={'gt':gt,'challenge':challenge,'use_v3_model':True,"save_result":False},timeout=10)
|
||||
datas = res.json()['data']
|
||||
if datas['result'] == 'success':
|
||||
return datas['validate']
|
||||
return None # 失败返回None 成功返回validate
|
||||
```
|
||||
|
||||
具体调用代码看使用项目,此处示例仅为API url和参数示例
|
||||
|
||||
#### --宣传--
|
||||
|
||||
欢迎大家支持我的其他项目喵~~~~~~~~
|
||||
|
||||
10
main.py
10
main.py
@@ -18,7 +18,8 @@ app = FastAPI()
|
||||
def get_pic(gt: str = Query(...),
|
||||
challenge: str = Query(...),
|
||||
point: str = Query(default=None),
|
||||
use_v3_model = Query(default=True)
|
||||
use_v3_model = Query(default=True),
|
||||
save_result = Query(default=False)
|
||||
):
|
||||
print(f"开始获取:\ngt:{gt}\nchallenge:{challenge}")
|
||||
t = time.time()
|
||||
@@ -47,9 +48,10 @@ def get_pic(gt: str = Query(...),
|
||||
result_list = predict_onnx(icon_image, bg_image, point)
|
||||
|
||||
point_list = [f"{col}_{row}" for row, col in result_list]
|
||||
wait_time = 4.0 - (time.time() - t)
|
||||
wait_time = max(0,4.0 - (time.time() - t))
|
||||
time.sleep(wait_time)
|
||||
result = json.loads(crack.verify(point_list))
|
||||
if save_result:
|
||||
shutil.move(os.path.join(validate_path,pic_name),os.path.join(save_path,pic_name))
|
||||
if 'validate' in result['data']:
|
||||
path_2_save = os.path.join(save_pass_path,pic_name.split('.')[0])
|
||||
@@ -68,6 +70,6 @@ def get_pic(gt: str = Query(...),
|
||||
if __name__ == "__main__":
|
||||
from predict import predict_onnx,predict_onnx_pdl
|
||||
import uvicorn
|
||||
print(f"{' '*10}api: http://127.0.0.1:{port}/pass_nine{' '*10}")
|
||||
print(f"{' '*10}api: http://0.0.0.0:{port}/pass_nine{' '*10}")
|
||||
print(f"{' '*10}api所需参数:gt、challenge、point(可选){' '*10}")
|
||||
uvicorn.run(app,port=port)
|
||||
uvicorn.run(app,host="0.0.0.0",port=port)
|
||||
|
||||
@@ -2,9 +2,9 @@ import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
from train import MyResNet18, data_transform
|
||||
|
||||
from crop_image import crop_image, convert_png_to_jpg,draw_points_on_image
|
||||
import torch
|
||||
|
||||
import time
|
||||
import cv2
|
||||
from PIL import Image
|
||||
@@ -13,6 +13,8 @@ import onnxruntime as ort
|
||||
|
||||
|
||||
def predict(icon_image, bg_image):
|
||||
from train import MyResNet18, data_transform
|
||||
import torch
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
model_path = os.path.join(current_dir, 'model', 'resnet18_38_0.021147585306924.pth')
|
||||
coordinates = [
|
||||
@@ -193,6 +195,7 @@ def predict_onnx_pdl(images_path):
|
||||
target = result[-1]
|
||||
answer = [coordinates[index] for index in range(9) if result[index] == target]
|
||||
print(f"识别完成{answer},耗时: {time.time() - start}")
|
||||
if os.path.exists(os.path.join(images_path,"nine.jpg")):
|
||||
with open(os.path.join(images_path,"nine.jpg"),'rb') as f:
|
||||
bg_image = f.read()
|
||||
draw_points_on_image(bg_image, answer)
|
||||
|
||||
@@ -8,4 +8,5 @@ torchvision
|
||||
Pillow
|
||||
matplotlib
|
||||
tqdm
|
||||
shutil
|
||||
uvicorn
|
||||
fastapi
|
||||
|
||||
10
requirements_without_train.txt
Normal file
10
requirements_without_train.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
httpx
|
||||
cryptography
|
||||
onnxruntime
|
||||
opencv-python
|
||||
numpy
|
||||
Pillow
|
||||
matplotlib
|
||||
tqdm
|
||||
fastapi
|
||||
uvicorn
|
||||
Reference in New Issue
Block a user