Error trying to convert simple convolutional model to CoreML
I'm trying to convert a simple GAN generator (from ClusterGAN):

self.name = 'generator'
self.latent_dim = latent_dim
self.n_c = n_c
self.x_shape = x_shape
self.ishape = (128, 7, 7)
self.iels = int(np.prod(self.ishape))
self.verbose = verbose

self.model = nn.Sequential(
    # Fully connected layers
    torch.nn.Linear(self.latent_dim + self.n_c, 1024),
    nn.BatchNorm1d(1024),
    nn.LeakyReLU(0.2, inplace=True),
    torch.nn.Linear(1024, self.iels),
    nn.BatchNorm1d(self.iels),
    nn.LeakyReLU(0.2, inplace=True),

    # Reshape to 128 x (7x7)
    Reshape(self.ishape),

    # Upconvolution layers
    nn.ConvTranspose2d(128, 64, 4, stride=2, padding=1, bias=True),
    nn.BatchNorm2d(64),
    nn.LeakyReLU(0.2, inplace=True),

    nn.ConvTranspose2d(64, 1, 4, stride=2, padding=1, bias=True),
    nn.Sigmoid()
)


But onnx-coreml fails with Error while converting op of type: BatchNormalization. Error message: provided number axes 2 not supported

I thought it was the BatchNorm2d, so I tried reshaping and applying BatchNorm1d, but I get the same error. Any thoughts? I'm very surprised that I'm having problems converting such a simple model, so I'm assuming that I must be missing something obvious.

I'm targeting iOS 13 and using Opset v10 for the onnx conversion.

Core ML does not have 1-dimensional batch norm. The tensor must have at least rank 3.

If you want to convert this model, you should fold the batch norm weights into those of the preceding layer and remove the batch norm layer. (I don't think PyTorch has a way to automatically do this for you.)
