Closed habjoel closed 2 years ago
MMDetection would convert image to rgb like this. And you have convert the image to bgr (image = np.array(image)[:, :, [2, 1, 0]].astype('float32')
). I guess it would change the data distribution.
Thank you @grimoire. I removed the line where I convert to bgr... the output is different but still wrong... I'l try to remove the other preprocessing steps (scaling and padding) when I work on it again and come back to you with results.
Hey @grimoire. Just wanted to confirm that the whole thing worked! Didn't realize that I also had to divide through the std at first but once I've done that it worked like a charm :)
Thanks a lot!
@habjoel hey, just wondering how did you make it work and can you provide the snippet you used for post processing.
Hi there, I exported the Swin-S model using tools/deploy.py from MMDeploy to onnx format using tools/deploy.py (I know that it is not supported yet but it worked flawlessly nonetheless). I used the following 2 configs and they led to the same results: instance-seg_onnxruntime_dynamic.py and instance-seg_onnxruntime_static.py. Proof is shown in the two images below showing the test result of the conversion. The predictions are almost identical for pytorch and onnx. (Note that I customized the model to detect 7 classes of waste using transfer learning)
Pytorch:
ONNX:
Now, I tried to run the converted .onnx model in a ONNX runtime python script on a Nvidia Jetson AGX Xavier. However, it does not output the same results as above and performs far worse.
Here is the output of the script I wrote:
It seems to detect some things but not really correctly. To me it seems as if the pretrained weights were somehow lost. For clarity, I converted the model to .onnx on my laptop which uses slightly different versions of onnx and onnx runtime than the Jetson. But I doubt that this really is an issue...? Also, I doubt that the issue comes from the swin transformer model architecture as I did the same steps with the mask_rcnn_r50_fpn_1x model pretrained on COCO and tested on the mmdetection/demo/demo.jpg.
I attach the python script belowl if you want to reproduce. I copied the pre- and postprocessing steps mostly from here: https://github.com/onnx/models/tree/main/vision/object_detection_segmentation/mask-rcnn and modified them a little to fit my model. I marked the steps I am not 100% sure about with a comment consisting of "*" above the respective step.
I would be very glad if someone could help me out!!