sovit-123 / fasterrcnn-pytorch-training-pipeline

PyTorch Faster R-CNN Object Detection on Custom Dataset
MIT License
223 stars 75 forks source link

How to using program onnx_inference_image.py #68

Open darnilasariaulia opened 1 year ago

darnilasariaulia commented 1 year ago

I tried to run this program, but the program can't run or error. Please to give me using onnx_inference_image.py

I try program:

fasterrcnn_mobilenetv3_large_fpn

!onnx_inference_image.py --weights outputs/training/fasterrcnn_resnet50_fpn_2/best_model.pth --input ../test/60rpm_sedikit --no-labels

But Error: /bin/bash: onnx_inference_image.py: command not found

sovit-123 commented 1 year ago

You need to do !python onnx_inference_image.py <rest of the command> Also, onnx inference scripts take .onnx file for --weights and not .pth file. You will first need to convert the weights to ONNX format using export.py

sovit-123 commented 1 year ago

Please let me if you face any issues.

darnilasariaulia commented 1 year ago

How to export to onnx inference scripts take .onnx

darnilasariaulia commented 1 year ago

I'm trying to call a program to export my data using the command:

!python export.py

But I have the following problem:

usage: export. py [-h] [-w WEIGHTS] [-d DEVICE] [--data DATA] --out OUT [--width WIDTH] [--height HEIGHT] export.py: error: the following arguments are required: --out

Please, give me an example program to export .pth tp .onnx files

sovit-123 commented 1 year ago

You can use a command similar to the following to export the model. python export.py --weights outputs/training/fasterrcnn_resnet18_train/best_model.pth --data data_configs/coco.yaml --out model.onnx

Remember to change the --weights and --data according to your requirements.

darnilasariaulia commented 1 year ago

I try to run the program:

!python onnx_inference_image.py --weights weights/model.onnx --input ../test/60rpm_bit

for testing the data that I have prepared in the ../test/60rpm_bit folder.

But the following error occurs:

/usr/local/lib/python3.10/dist-packages/onnxruntime/capi/onnxruntime_inference_collection.py:54: UserWarning: Specified provider 'CUDAExecutionProvider' is not in available provider names.Available providers: 'CPUExecutionProvider' warnings. warn( Traceback (most recently last call): File "/content/drive/MyDrive/Faster RCNN/fasterrcnn-pytorch-training-pipeline/onnx_inference_image.py", line 189, in main(args) File "/content/drive/MyDrive/Faster RCNN/fasterrcnn-pytorch-training-pipeline/onnx_inference_image.py", line 100, in main with open(args['data']) as file: TypeError: expected str, bytes or os. PathLike object, not NoneType

Please, give solution for using testing image in folder using model .onnx

sovit-123 commented 1 year ago

You also need to provide the path to your dataset YAML file. This is an example command in the python onnx_inference_image.py. Please have a look at the script in the codebase in case you face argument errors. python onnx_inference_image.py --input ../inference_data/ --weights weights/fasterrcnn_resnet18.onnx --data data_configs/voc.yaml --imgsz 640