Closed ani-mal closed 8 months ago
With the same checkpoint I am able to use convert_to_onnx()
method to convert to onnx:
model =
models.get(model_name="yolo_nas_s", checkpoint_path=checkpoint_path, num_classes=num_classes)
actual_output_path = convert_to_onnx(
model=model,
out_path='yolo_nas.onnx',
input_shape = [3,640,640])
However, I am interested in getting the new API to work to leverage the pre and post processing NMS.
Seems like I am having issues with the pre-processing step. Once, I turned that off, I was able to get the nms postprocessing working:
export_result = model.export("yolo_nas_s_coco_training.onnx", input_image_shape =[640,640], input_image_channels=3, preprocessing=False, nms_threshold=0.5, confidence_threshold=0.5)
The original error indicates that checkpoint contains no preprocessing params saved. Can you please share what version of SG are you using? If it's not 3.3.1 I suggest to train a model for 1 epoch with a new version and trying to do model.export() again as it should work.
Can you also do torch.load() on your checkpoint and print keys? I especially interested in seeing whether preprocessing_params
is present in that checkpoint.
Indeed, when you don't have preprocessing_params
in the checkpoint you cannot use preprocessing (which for yolo nas is just RGB -> BGR and input/255
) step baked in the model graph. So exporting with preprocessing=False is a right way to do, just don't forget to change channels order, resize and/or pad images to 640x640 and divide by 255.
@BloodAxe thanks for the additional clarification, I just verified the clusters that are training the model and it is indeed using SG 3.2.0
. I will updated that to 3.3.1
to verify that this should fix the pre-processing step.
@ani-mal does it work well when moving to 3.3.1
?
@Louis-Dupont I was unable to have it working when updating to 3.3.1
so I kept the alternative solution @BloodAxe proposed.
@Louis-Dupont closing this issue. The issue was that we were not using the weights saved by SG, but instead, we were creating a .pth
file from the model object ourselves, causing the .pth
file not to have the metadata SG expects when loaded.
💡 Your Question
Description
Unable to export finetuned model to
onnx
using latest export API. I was able to reproduce the simple example described here on the documentation. However, when I load a checkpoint and try to export the model to onnx, I run into the following error:code:
I was running into other issues where the input shape was not being automatically inferred from model, hence why I am providing those additional parameters.
Is there anything different that needs to be done to properly initialize the finetuned model prior to exporting it through the new API?
relevant packages on the windows conda env:
I also inspected with netron the
.pth
file I loaded to the default example that is pulling themodels.get(Models.YOLO_NAS_S, pretrained_weights="coco")
. I am not sure what to look for here, but just wanted to inspect if the weight files structure was similar.Versions
No response