尝试将简单的卷积模型转换为CoreML时出错

问题描述 投票:0回答:1

我正在尝试转换一个简单的GAN生成器(来自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()
)

但是onnx-coreml失败,并显示Error while converting op of type: BatchNormalization. Error message: provided number axes 2 not supported

我以为这是BatchNorm2d,所以我尝试重塑并应用BatchNorm1d,但出现相同的错误。有什么想法吗?对于转换这样一个简单的模型时遇到问题,我感到非常惊讶,因此我假设我肯定会丢失一些明显的东西。

我的目标是iOS 13,并使用Opset v10进行onnx转换。

pytorch coreml gan
1个回答
0
投票

Core ML没有一维批处理规范。张量必须至少具有等级3。

如果要转换此模型,则应将批处理规范权重折叠为上一层的权重,然后删除批处理规范权重层。 (我认为PyTorch无法自动为您执行此操作。)

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.