在写一个印章检测代码的时候出现了问题
```python
import os
import base64
import torch.hub
root_path = os.getcwd()
yolo_model_path = root_path + '/yolov5/models/seal_detect_best.pt'
class Infer_main:
def __init__(self, yolo_model_path):
self.seal_infer = self.yolo_model_load()
self.model_path = yolo_model_path
def yolo_model_load(self):
model = torch.hub.load('D:/workspace/seal/yolov5', 'custom', path=self.model_path, source='local',
force_reload=True)
model.conf = 0.4
model.eval()
return model
def predict(self, images):
result = {'seal_page': []}
seal_page = []
for i in range(len(images)):
yolo_res = self.seal_infer(images[i], size=640)
yolo_res_list = yolo_res.pandas().xyxy[0].values.tolist()
if yolo_res_list:
for a in range(len(yolo_res_list)):
seal_page.append(str(i+1))
print(type(result['seal_page']))
result['seal_page'] = seal_page
print(type(seal_page))
if __name__ == '__main__':
pic = open("8.png", "rb")
yolo_model_path='D:/workspace/seal/yolov5/models'
a = Infer_main(yolo_model_path)
a.predict(pic.read())
我在写下面的测试代码时出现了一些错误,报错信息如下:
```python
Traceback (most recent call last):
File "D:\workspace\seal\seal_detection.py", line 37, in <module>
a = Infer_main(yolo_model_path)
File "D:\workspace\seal\seal_detection.py", line 11, in __init__
self.seal_infer = self.yolo_model_load()
File "D:\workspace\seal\seal_detection.py", line 15, in yolo_model_load
model = torch.hub.load('D:/workspace/seal/yolov5', 'custom', path=self.model_path, source='local',
AttributeError: 'Infer_main' object has no attribute 'model_path'
我的最终目的是正确的把图片传递给AI能力检测是否有印章