CycleGAN icon indicating copy to clipboard operation
CycleGAN copied to clipboard

pythorch to onnx conversion

Open Bea07 opened this issue 1 year ago • 1 comments

Hi, I have tried to convert a sat2map model to onnx and I found a relevant decrease of accuracy. Anyone with some advice, suggestions and if you experienced something similar. I have tried many tests, different parameters for torch.onnx.export() but no improvements. During training phase I specified --norm istance, hence the reported batch normalization problem is excluded. Generator network is unet_256. Have you come into something similar? thks Bea

Bea07 avatar Jan 16 '23 14:01 Bea07

The issue of accuracy loss is due to batch normalization layer. BN in inference mode performs differently than training. The test.py script is not launching an inference however you set --eval parameter at the command line. In inference mode the pytorch function model.eval() is called (a step that is needed to export in onnx too) and it changes the behave of BN. If your B size is 1 at inference, if possible retrain your model with instance normalization, this can solve this difference of outputs. It worked for me.

Bea07 avatar Mar 17 '23 11:03 Bea07