在调用类中函数的时候出现问题,代码如下:
import torch
import json
import base64
from seal_bak.seal_recognition import work
import os
import numpy as np
import cv2
root_path = os.getcwd()
model_path = root_path + '/models/seal_detect_best.pt'
class Infer_main:
def __init__(self, yolo_model_path):
self.model_path = yolo_model_path
self.seal_infer = self.yolo_model_load()
def yolo_model_load(self):
model = torch.hub.load('D:/test11/yolov5',
'custom',
path=model_path,
source='local',
force_reload=True) # local repo
model.conf = 0.4
model.eval()
return model
def predict(self,images):
result = {
"base64": images,
"debug": False # debug模式将可视化各环节,否则只输出结果
}
# for item, i in enumerate(images):
yolo_res = self.seal_infer(images, size=640)
# print(f'yolo_res:{yolo_res}')
yolo_res_list = yolo_res.pandas().xyxy[0].values.tolist()
if yolo_res_list:
for i in range(len(yolo_res_list)):
# print(yolo_res_list[i])
yolo_res_liststr = json.dumps(yolo_res_list[i])
# print(type(yolo_res_liststr))
base64str = base64.b64encode(yolo_res_liststr.encode('utf-8')).decode('utf-8')
# img_array = np.fromstring(base64str, np.uint8)
print(type(base64str))
result['base64'] = base64str
result_rec = work(result)
print(result_rec)
return result_rec
if __name__ == '__main__':
from PIL import Image
#
model_path = 'D:/test11/yolov5/models/seal_detect_best.pt'
#
image = cv2.imread('D:/test11/yolov5/8.png')
a = Infer_main(model_path)
Infer_main.predict(image)
报错如下:
YOLOv5 v6.1-275-g29d79a6 Python-3.7.16 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3070 Ti Laptop GPU, 8192MiB)
Fusing layers...
YOLOv5s summary: 213 layers, 7015519 parameters, 0 gradients
Adding AutoShape...
Traceback (most recent call last):
File "D:\test11\yolov5\test1.py", line 57, in <module>
Infer_main.predict(image)
TypeError: predict() missing 1 required positional argument: 'images'
为啥我给了他image 但是他还说我缺少参数