New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to convert tensorflow model to caffe model? #59
Comments
Have the same problem. I want to convert tensorflow model to caffe model. |
@ethereon could you provide some advises? |
The reverse conversion is fairly similar:
Things are slightly trickier for step 1 when going from tf to caffe, since the equivalent of a caffe layer might be split into multiple tf sub ops. So pattern matching against the op signatures / scopes might be one approach for tackling this. For certain ops like convolutions, you can avoid the transformation in step 2 by specifying a Caffe compatible ordering (eg: |
@ethereon @cyh24 Thank you for your help. I am trying to convert inception-resnet-v2 model to caffe, and not sure about the param of BatchNorm layer. |
@catsdogone I tried the same thing and my activation is off, and cannot get the same accuracy. I also specified the scale parameter in scale layer to 1, and set BatchNorm's moving average factor to 1. :( |
Same issue. Want to convert Tensorflow Inception V3 and ResNet model to Caffe. That will be great! |
Okay, I was able to achieve similar performance after changing the padding for the 1x7 and 7x1 filter to (0,3) and (3,0) instead of (1,2) and (2,1) |
@Jerryzcn @catsdogone |
@nyyznyyz1991 I use pycaffe to generate the prototxt based on tensorflow. I cannot share it though. |
@Jerryzcn is it hard to code the conversion script with pycaffe? |
@neobarney took me about 1 week. |
@Jerryzcn wow that's long, you're not planning to release it on github ? would be helpful to lots of peoples ! :) |
@neobarney it should only take u 2-3 days, I spend half a week on figuring out why my activation does not match the original network. |
cool, I'll try then, thanks for sharing Jerry !!!
|
@Jerryzcn If I use tf.contrib.layers.batch_norm(input, scale=False) in Tensorflow, the "scale =False" means whether the gamma is zero in "y = gamma*x+beta". And how to set the param in batchnormlayer in Caffe to make the result same between tensorflow and caffe. |
@zmlmanly set scale to 1 on caffe should work |
@Jerryzcn Thank you very much. I’m converting tensorflow to caffe. I use tf.contrib.layers.batch_norm(input, scale=False) in Tensorflow, so there is only beta param in checkpoint, in your view, |
@catsdogone Hi, I want to know how to save the moving_mean and the moving_variance param in tensorflow/batchnormlayer. I have check the param in my trained model of tensorflow, but there is no mean and variance in batchnormlayer. Thank you for your help. |
@zmlmanly I think I set them either to zero or one. I forgot which exactly. |
@zmlmanly @neobarney Were you able to get it running? |
Convert batch normalization layer in tensorflow to caffe: 1 batchnorm layer in tf is equivalent to a successive of two layer : batchNorm + Scale: |
@jzhaosc Be careful of the epsilon guys. |
@catsdogone May I learn if you have successfully converted inception_resnet_v2 from tensorflow to caffe? Thank you. |
when you are using tf.nn.batch_normalization, |
Maybe you can see another open source library called MMdnn by Microsoft,it is the link:https://github.com/Microsoft/MMdnn |
@giticaniup yes I‘ve already down it with MMdnn, which is much easier and intuitive. The only question exists is how to make the image pre-process in tensorflow equals to that in caffe? |
I'm now converting tf mobilenet-v2 to caffe model. Do I miss any detail? |
@cjerry1243 I have tried that before thus strongly recommend not to waste time using this repository on training Mobilenet in caffe. This repository uses caffe built-in group convolution, where the depthwise convolution implementation is a non-parallel 'for loop', also do not have a good cuda/cudnn support. The training process was very slow, so that it will take a lot of time to tune hyperparameters. Maybe you should try https://github.com/yonghenglh6/DepthwiseConvolution or other implementations instead. |
@bobauditore Thanks for your advice. Except for the different "depthwise convolution"in that repository(https://github.com/shicai/MobileNet-Caffe), I found another problem during conversion. The first conv layer output values Besides, I use np.swapaxes to swap tf variables and feed into caffe variables: Where's the mistake of my conversion ? |
@cjerry1243 Do you solve the problem? |
@KeyKy I have solved it ! |
@cjerry1243 could you share your code with me? It is hard to understand. update: I see! Thanks! |
Does anyone have any update about new tools to convert tf models to caffemodel? It's been a long time since the question was posted. |
How to convert a tensorflow .ckpt to caffe model? Is that possible without .prototxt?
Any help is appreciated.
The text was updated successfully, but these errors were encountered: