This is the error I am getting. I was trying to implement yolov7 object detection code using this repo - https://github.com/WongKinYiu/yolov7
And I got the yolov7.pt weight file, which is pre trained model.
And converted .pt into .onnx using this https://github.com/WongKinYiu/yolov7/blob/u5/export.py
After that I used object detection code with input as .onnx weight file.
import os, timeimport cv2import matplotlib.pyplot as pltcoco_classes = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light','fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow','elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee','skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard','tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple','sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch','potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone','microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear','hair drier', 'toothbrush']# net = cv2.dnn.readNet("yolov7.onnx")net = cv2.dnn.readNet("/content/1-yolov7.onnx")model = cv2.dnn_DetectionModel(net)model.setInputParams(size=(416, 416), scale=1 / 255, swapRB=True)path = './testimg/'for fn in os.listdir(path): image = cv2.imread(path + fn) t = time.time() c, v, b = model.detect(image, 0.2, 0.4) t = time.time() - t c = [coco_classes[x] for x in c] for (classid, score, box) in zip(c, v, b): if classid == 0 or classid == 2: lx, ly, cw, ch = box x=cv2.rectangle(image, box, (255, 0, 255), 3) plt.imshow(cv2.cvtColor(x, cv2.COLOR_BGR2RGB)) plt.waitforbuttonpress()
I used google Collab. it has OpenCV 4.6.0, pytorch version was 1.12, I tried using pytorch 1.11 also but it didn't solve the issue
ERROR--
yolov7_detector = YOLOv7(args.modelpath, conf_thres=args.confThreshold, iou_thres=args.nmsThreshold) File "F:/REPO/code/yolov7-u5/detect.py", line 13, in __init__ self.net = cv2.dnn.readNet(path)cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:255: error: (-5:Bad argument) Can't read ONNX file: models/yolov7_640x640.onnx in function 'cv::dnn::dnn4_v20220524::ONNXImporter::ONNXImporter'
instead of sharing some random solved question URL can someone kindly guide me exactly what I should do. I am very new to this and been googling for two days to solve this error [yolov5 had same issue but that solution was to change torch version to 1.11 which I tried and didn't work for me] NOTE - i am using yolov7