torch2coreml icon indicating copy to clipboard operation
torch2coreml copied to clipboard

ValueError: expected 5D input (got 4D input)

Open usingcsharp opened this issue 7 years ago • 4 comments

Hello!,how to solve this problem,thank you very much!

Preparing models for conversion Converting models to CoreML Converting prepared_models/candy.t7 Traceback (most recent call last): File "convert-fast-neural-style.py", line 176, in main() File "convert-fast-neural-style.py", line 162, in main unknown_layer_converter_fn=convert_instance_norm File "/home/sharp/.local/lib/python2.7/site-packages/torch2coreml/_torch_converter.py", line 211, in convert input_shapes File "/home/sharp/.local/lib/python2.7/site-packages/torch2coreml/_torch_converter.py", line 67, in _infer_torch_output_shapes is_batch=True File "/home/sharp/.local/lib/python2.7/site-packages/torch2coreml/_torch_converter.py", line 30, in _forward_torch_random_input result = torch_model.forward(input_tensors[0]) File "/home/sharp/.local/lib/python2.7/site-packages/torch/legacy/nn/Module.py", line 33, in forward return self.updateOutput(input) File "/home/sharp/.local/lib/python2.7/site-packages/torch/legacy/nn/Sequential.py", line 36, in updateOutput currentOutput = module.updateOutput(currentOutput) File "convert-fast-neural-style.py", line 45, in updateOutput return self._instance_norm.forward(Variable(input)).data File "/home/sharp/.local/lib/python2.7/site-packages/torch/nn/modules/instancenorm.py", line 46, in forward self._check_input_dim(input) File "/home/sharp/.local/lib/python2.7/site-packages/torch/nn/modules/instancenorm.py", line 242, in _check_input_dim .format(input.dim())) ValueError: expected 5D input (got 4D input)

usingcsharp avatar Jul 12 '18 16:07 usingcsharp

The CoreML model can be generated after you reshape (N,C,H,W) to (N,C,1,H,W), but the result was terrible, at last I used 'Batch Normalization' instead of 'Instance Normalization' and it worked well.

GordonRen avatar Aug 22 '18 16:08 GordonRen

Hello!Thank you for your reply,’'Batch Normalization' instead of 'Instance Normalization' ‘,how to do that?Can you explain it in detail or show it with pictures,thank you very much!

发自我的 iPhone

在 2018年8月23日,上午12:05,GordonRen [email protected] 写道:

'Batch Normalization' instead of 'Instance Normalization'

usingcsharp avatar Aug 22 '18 16:08 usingcsharp

1.find 'train.lua' 2.set cmd:option('-use_instance_norm', 1) to cmd:option('-use_instance_norm', 0) 3.train Notice:the trained model uses 'Instance Normalization' which has something wrong when converting it to CoreML model, but you can trian your model using ‘Batch Normalization' and Convert it to CoreML model successfully.

GordonRen avatar Aug 22 '18 16:08 GordonRen

Ok, thank you very much! I try it now.

发自我的 iPhone

在 2018年8月23日,上午12:19,GordonRen <[email protected]mailto:[email protected]> 写道:

1.find 'train.lua' 2.set cmd:option('-use_instance_norm', 1) to cmd:option('-use_instance_norm', 0) 3.train Notice:the trained model uses 'Instance Normalization' which has something wrong when converting it to CoreML model, but you can trian your model using ‘Batch Normalization' and Convert it to CoreML model successfully.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/prisma-ai/torch2coreml/issues/27#issuecomment-415091202, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AFb83Z469sVIrbNJneckQtG1R38Pzpl3ks5uTYR6gaJpZM4VNXFc.

usingcsharp avatar Aug 22 '18 16:08 usingcsharp