torch2coreml icon indicating copy to clipboard operation
torch2coreml copied to clipboard

Can't convert model.t7 to mlmodel

Open markzhong88 opened this issue 7 years ago • 2 comments

Great open source project.

I trained some .t7 model form the DmitryUlyanov texture nets, it's same method with Justin Johnson's fast feed forward. https://github.com/DmitryUlyanov/texture_nets#credits

Here is a sample model download link: https://yadi.sk/d/GwL9jNJovBwQg

When I tried to convert it to mlmodel using convert-fast-neural-style.py, it shows me NotType Error, or unknown Torch class <nn.TVLoss>...

markzhong88 avatar Nov 15 '17 18:11 markzhong88

You need to prepare your model for inference. Loss layer is not needed for inference, you can safely remove it from the model. I made a script for fast-neural-style which modifies models: https://github.com/prisma-ai/torch2coreml/blob/master/example/fast-neural-style/prepare_model.lua You can implement something similar for your model. Please note, that currently not all torch7 layers are supported and you cannot convert model with custom Lua layers inside. Please refer to example with custom layer implementation https://github.com/prisma-ai/torch2coreml/blob/master/example/fast-neural-style/convert-fast-neural-style.py#L12 if you need some unknown layers to be converted.

opedge avatar Nov 17 '17 00:11 opedge

Hi @opedge , I have a model from Justin Johnson and want to convert it to coreml model. So I first tried to prepare the model using prepare_model.lua but it gave following error. Please let me know how can I solve this problem, no file './fast-neural-style/fast_neural_style/ShaveImage.lua' no file '/home/torch/install/share/luajit-2.1.0-beta1/fast-neural-style/fast_neural_style/ShaveIma ge.lua' no file '/usr/local/share/lua/5.1/fast-neural-style/fast_neural_style/ShaveImage.lua' no file '/usr/local/share/lua/5.1/fast-neural-style/fast_neural_style/ShaveImage/init.lua' no file '/home/.luarocks/lib/lua/5.1/fast-neural-style/fast_neural_style/ShaveImage.so' no file '/home/torch/install/lib/lua/5.1/fast-neural-style/fast_neural_style/ShaveImage.so' no file '/home/torch/install/lib/fast-neural-style/fast_neural_style/ShaveImage.so' no file './fast-neural-style/fast_neural_style/ShaveImage.so' no file '/usr/local/lib/lua/5.1/fast-neural-style/fast_neural_style/ShaveImage.so' no file '/usr/local/lib/lua/5.1/loadall.so' no file '/home/.luarocks/lib/lua/5.1/fast-neural-style.so' no file '/home/torch/install/lib/lua/5.1/fast-neural-style.so' no file '/home/torch/install/lib/fast-neural-style.so' no file './fast-neural-style.so' no file '/usr/local/lib/lua/5.1/fast-neural-style.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'error' /home/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require' example/fast-neural-style/prepare_model.lua:4: in main chunk [C]: in function 'dofile' ...eena/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x55917c228470

The command which I used to run the code for preparing model is: th example/f ast-neural-style/prepare_model.lua -input example/fast-neural-style/candy.t7 -output example/fast-neural-style/p ytorch_models/candy1.t7

Please guide me in this. Thank you

theheena avatar Nov 28 '17 02:11 theheena