You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to convert a custom-trained model into an onnx file. Unfortunately, I did not find specific instructions for this. Therefore I tried to rework your example on a yolomodel. (Found here: notebooks/export-onnx-inference-onnxruntime.ipynb)
I managed to work out how to load my custom model, yet it runs into errors:
`def export_yolo_to_onnx(path_model, onnx_output_path):
# Load the YOLO model using torch.hub
model = torch.hub.load('ultralytics/yolov5', 'custom', path=path_model) # Use the local model
model.eval() # Set model to evaluation mode
# Parameters for ONNX export
size = (640, 640)# Resize image to this size for export
size_divisible= 32 # Ensure the size is divisible by 32
score_thresh= 0.25 # Score threshold for NMS
nms_thresh= 0.45 # NMS threshold
opset_version= 12 # ONNX opset version
batch_size= 1 # Batch size for export
# Export the model to ONNX format with NMS enabled
export_onnx(
onnx_path=onnx_output_path,
model=model,
size=size,
size_divisible=size_divisible,
score_thresh=score_thresh,
nms_thresh=nms_thresh,
opset_version=opset_version,
batch_size=batch_size,
)
print(f"Model successfully exported to ONNX at: {onnx_output_path}")`
TypeError Traceback (most recent call last) in <cell line: 40>()
38
39 # Run the export function
---> 40 export_yolo_to_onnx(path_model, onnx_output_path)
19 frames /content/yolov5/models/common.py in forward(self, ims, size, augment, profile)
878 files.append(Path(f).with_suffix(".jpg").name)
879 if im.shape[0] < 5: # image in CHW
--> 880 im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)
881 im = im[..., :3] if im.ndim == 3 else cv2.cvtColor(im, cv2.COLOR_GRAY2BGR) # enforce 3ch input
882 s = im.shape[:2] # HWC
TypeError: transpose() received an invalid combination of arguments - got (tuple), but expected one of:
(int dim0, int dim1)
(name dim0, name dim1)
Maybe you can advise and as soon as it works I can supply you with the notebook and you could add it to the documentation:)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
First of all thanks for your great work!
I tried to convert a custom-trained model into an onnx file. Unfortunately, I did not find specific instructions for this. Therefore I tried to rework your example on a yolomodel. (Found here: notebooks/export-onnx-inference-onnxruntime.ipynb)
I managed to work out how to load my custom model, yet it runs into errors:
`def export_yolo_to_onnx(path_model, onnx_output_path):
# Load the YOLO model using torch.hub
model = torch.hub.load('ultralytics/yolov5', 'custom', path=path_model) # Use the local model
model.eval() # Set model to evaluation mode
TypeError Traceback (most recent call last)
in <cell line: 40>()
38
39 # Run the export function
---> 40 export_yolo_to_onnx(path_model, onnx_output_path)
19 frames
/content/yolov5/models/common.py in forward(self, ims, size, augment, profile)
878 files.append(Path(f).with_suffix(".jpg").name)
879 if im.shape[0] < 5: # image in CHW
--> 880 im = im.transpose((1, 2, 0)) # reverse dataloader .transpose(2, 0, 1)
881 im = im[..., :3] if im.ndim == 3 else cv2.cvtColor(im, cv2.COLOR_GRAY2BGR) # enforce 3ch input
882 s = im.shape[:2] # HWC
TypeError: transpose() received an invalid combination of arguments - got (tuple), but expected one of:
Maybe you can advise and as soon as it works I can supply you with the notebook and you could add it to the documentation:)
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions