starimeL/PytorchConverter

Cycle-GAN model convert to caffemodel

Closed this issue · 2 comments

I want to convert to my trained horse2zebra cycle-gan model to caffemodel with your code like this:
InputShape = [1, 3, 256, 256]
for i, data in enumerate(dataset):
if i >= 1:
break
CycleGan_model.set_input(data)
# model.real_A = Variable(model.input_A)
# model.fake_B = model.netG(model.real_A)
CycleGan_model.test()
m = CycleGan_model.netG
print('Converting...')
if dst == 'caffe':
text_net, binary_weights = ConvertModel_caffe(m, InputShape, softmax=False)

There is an error
File "/home/mi/Project/PyTorch/PyTorch2Caffe_01_09/PytorchConverter/code/ConvertModel.py", line 321, in ConvertModel_caffe
DFS(out.grad_fn)
File "/home/mi/Project/PyTorch/PyTorch2Caffe_01_09/PytorchConverter/code/ConvertModel.py", line 83, in DFS

ValueError: Unknown layer type: ReflectionPad2d, known types: ['LeakyReLU', 'Index', 'BatchNorm', 'AddConstant', 'UpsamplingBilinear2d', 'Tanh', 'MulConstant', 'Dropout', 'PReLU', 'Add', 'MaxPool2d', 'AvgPool2d', 'Addmm', 'Softmax', 'Threshold', 'ConvNd', 'Cmax', 'data', 'Concat', 'ELU']

how to modify and add the parameter ReflectionPad2d? thank you.

I've tried on CycleGAN before. The main reason of this problem is that caffe doesn't have a layer or padding parameter to make the reflection padding. Caffe can only pad tensors with constant value.

If you can train the GAN model by yourself, I suggest you to modify the original net, by replacing the ReflectionPad layers with normal zero padding or just drop them.

thank you so much, I will have try it.