ibaigorordo / onnx-yolov7-object-detection Goto Github PK
View Code? Open in Web Editor NEWPython scripts performing object detection using the YOLOv7 model in ONNX.
License: MIT License
Python scripts performing object detection using the YOLOv7 model in ONNX.
License: MIT License
When I run image_object_detection.py on cpu, it will give error:
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (tensor(float)) , expected: (tensor(float16))
change
input_tensor = input_img[np.newaxis, :, :, :].astype(np.float32) to
input_tensor = input_img[np.newaxis, :, :, :].astype(np.float16) will solve this problem.
So can you fix it?
how to convert pt to onnx? what about the shell codes?
python export.py --weights yolov7.pt --grid --end2end --simplify
--topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640
It appears that onnxruntime-gpu is bugged or something... as while running inference the CPU goes to 100%, the only way to reduce cpu usage is to reduce the framerate of the camera to something like 5fps. Is this happening to anyone else ?
P.S. providers seems to be right : ['CUDAExecutionProvider', 'CPUExecutionProvider'] cuda does actually get detected by python
Hi,
image_object_detection.py.
Lina 8: yolov7_detector = YOLOv7(model_path, conf_thres=0.2, iou_thres=0.3, official_nms=True)
Called:
Line 19: combined_img = yolov7_detector.draw_detections(img)
Yolov7.py.
line 105: def parse_processed_output(self, outputs):
Crash:
line 116: predictions = predictions[valid_scores, :]
IndexError: boolean index did not match indexed array along dimension 1; dimension is 6 but corresponding boolean dimension is 85
Thank
Stephen
First off, thank you for such a helpful repo!
I followed the the instructions on https://github.com/WongKinYiu/yolov7 to convert a .pt model to a .onnx model. The model runs fine, it produces the same results as the original .pt model. The problem is the .onnx model is twice the size as the .pt model. I think it's due to different floating point sizes. Any suggestions on converting fp16 .pt model to fp16 .onnx model?
Thanks in advance
I have a question about the processing of low score in process_output, which is a def block in yolov7.py.
About the following part:
# Filter out the objects with a low score
predictions = predictions[obj_conf > self.conf_threshold]
scores = scores[scores > self.conf_threshold]
I think the calculation to obtain predictions is as follows.
predictions = predictions[**scores** > self.conf_threshold]
(obj_conf -> scores)
``
Traceback (most recent call last):
File "image_object_detection.py", line 15, in
boxes, scores, class_ids = yolov7_detector(img)
File "/home/berat/berat-projects/ekin/ONNX-YOLOv7-Object-Detection/yolov7/YOLOv7.py", line 20, in call
return self.detect_objects(image)
File "/home/berat/berat-projects/ekin/ONNX-YOLOv7-Object-Detection/yolov7/YOLOv7.py", line 44, in detect_objects
self.boxes, self.scores, self.class_ids = self.process_output(outputs)
File "/home/berat/berat-projects/ekin/ONNX-YOLOv7-Object-Detection/yolov7/YOLOv7.py", line 78, in process_output
predictions = predictions[obj_conf > self.conf_threshold]
IndexError: boolean index did not match indexed array along dimension 2; dimension is 80 but corresponding boolean
dimension is 85
`
How can I fix that? I just tested the default yolov7.onnx
File "/home/melissacolin/anaconda3/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 424, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from models/best.onnx failed:Fatal error: TRT:EfficientNMS_TRT(-1) is not a registered function/op
my model trained on 8 classes but i want to detect only 2 classes .How to do that ?
Hello,
I'm studying how the export to .onnx and .trt works and found your code that export the result of a .onnx file to a format that Yolov7 can read. It was very helpful, but I have some doubts about the nms (non maximum suppression).
At first, I found that the detection boxes didn't display properly unless I set official_nms to True, I found an issue in another project that said that too, but looking at the code It calls a nms function from the files yolov7.utils when official_nms is set to False.
So, I would like to ask what is the purpose and meaning of the variable official_nms in the code.
I still have doubts about it, but I have seen that you can add nms when you export a .pt file to .onnx files (You can see it in the YoloV7 official repository, in the export section ). Is the nms function used to apply nms when you don't apply it at the moment of exporting to .onnx or has any other purpose?
Thank you so much.
You mention to download the onnx files from https://github.com/PINTO0309/PINTO_model_zoo/tree/main/307_YOLOv7 , but I see a bunch of "nms_yolov7_10080.onnx" and so files there, and it's not clear at all which one would work. Any hints on how to get it to run?
Thanks
I'm trying to use this code with yolov7 trained on a custom dataset, but for some reason I can't get the boxes to line up. Works great with the models trained on the coco dataset (from pinto's model zoo) though.
How did you export the trained yolov7 models to onnx?
This was the command I used to export:
python export.py --weights runs/train/yolov73/weights/best.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 480 --max-wh 640 --dynamic-batch
Sorry if this is a dumb question, I'm new to yolo and onnx.
I inferenced the model with both CPU and GPU, but it seems the only difference between the is just 4 ms. With CPU reaches almost 26ms and with CUDA 21 ms. I don't unterstand why is running so bad. I suppose the export in onnx form was not so successful.
def inference(self, input_tensor):
input_name = self.session.get_inputs()[0].name
output_name = self.session.get_outputs()[0].name
iobinding = self.session.io_binding()
ortvalue = onnxruntime.OrtValue.ortvalue_from_numpy(input_tensor, 'cuda', 0)
iobinding.bind_input(input_name, 'cuda', 0, np.float32, ortvalue.shape(), ortvalue.data_ptr())
iobinding.bind_output(output_name, 'cuda', 0)
start = time.perf_counter()
#outputs = self.session.run(self.output_names, {self.input_names[0]: input_tensor})
self.session.run_with_iobinding(iobinding)
print(f"Inference time: {(time.perf_counter() - start)*1000:.2f} ms")
outputs = iobinding.copy_outputs_to_cpu()
return outputs
I am a new player. These questions may be stupid. Sorry for that.
As the repo said I git clone the repo and down load the yolov7_Nx3x256x320.onnx
and try to run the python file all of the 3 detection files do not work and give this error.
Thanks in advance for the help
Hi, thanks for sharing, I also convert original yolov7 .pt model to onnx, while, the exported model is not work well,
could you tell me the method how to convert the model?
Thanks a lot
Does the yolov7 have any change for decode and preprocess?
How can I change Onnx-Runtime Yolov7 bbox to OpenCV -Roi ?
How to run yolo library in onnx format on my GPU ?
How to use yolo in onnx format with dynamic batch size in js environment ?
Can i make objects tracking with yolo libraries in js environment , if i can , How ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.