WongKinYiu / PyTorch_YOLOv4

PyTorch implementation of YOLOv4
1.88k stars 585 forks source link

Exporting pytorch model to ONNX #443

Open KamalNathSasken opened 1 week ago

KamalNathSasken commented 1 week ago

Hi, I am trying to export this model to ONNX format using models/export.py script. But running into below error. yolov4-csp.pt is not available locally or in the github link mentioned below. Any suggestion would be appreciated. Or any suggestion on an alternate approach to convert to ONNX format is also welcome.

Namespace(weights='./yolov4-csp.pt', img_size=[640, 640], batch_size=1) Downloading https://github.com/WongKinYiu/ScaledYOLOv4/releases/download/v1.0/yolov4-csp.pt to ./yolov4-csp.pt... ERROR: Download failure.

\yolov4\PyTorch_YOLOv4-master\models\export.py:21: FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float() Traceback (most recent call last): File "\yolov4\PyTorch_YOLOv4-master\models\export.py", line 21, in model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\serialization.py", line 1065, in load with _open_file_like(f, 'rb') as opened_file: ^^^^^^^^^^^^^^^^^^^^^^^^ File "\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\serialization.py", line 468, in _open_file_like return _open_file(name_or_buffer, mode) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\serialization.py", line 449, in init super().init(open(name, mode)) ^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: './yolov4-csp.pt'

Regards, Kamalnath