Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

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

Open
usingcsharp opened this issue Jul 12, 2018 · 4 comments
Open

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

usingcsharp opened this issue Jul 12, 2018 · 4 comments

Comments

@usingcsharp
Copy link

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)

@GordonRen
Copy link

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.

@usingcsharp
Copy link
Author

usingcsharp commented Aug 22, 2018 via email

@GordonRen
Copy link

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.

@usingcsharp
Copy link
Author

usingcsharp commented Aug 22, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants