Skip to content
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

feature map mismatch #2

Open
wenhe-jia opened this issue May 14, 2017 · 1 comment
Open

feature map mismatch #2

wenhe-jia opened this issue May 14, 2017 · 1 comment

Comments

@wenhe-jia
Copy link

I am tring to convert a mxnet model into a caffe model. The feature maps of 'conv1a' layer in mxnet and caffe are the same, but the feature maps of 'bn' layer in mxnet differs from the ones in caffe. The parameters 'moving_men', 'moving_var', 'gamma', 'beta' of mxnet model are suitable put into the caffe model.
And, when i tried to test the caffe model on ilsvrc2012 val, predicted classes of all images are 0. There must be some mistakes when i converted the model.
This bothers me for quite a while,can u give me some suggestions? thx a lot~

@cypw
Copy link
Owner

cypw commented May 14, 2017

I guess the mismatched feature map size is caused by the Pooling layer, because Caffe and MXNet use different default rounding strategy for the Pooling layer. So, you may need to add an option "ceil_mode: false" in Caffe's prototxt for the pooling layer(s).

If the solution above does not help you fix the problem, you may need to check if all parameters are copied from the MXNet Model.
( if everything else fails, checking the output consistency layer by layer can help you find the problem. )

-------------
Take the resnet-18 for example:

You will encounter all zero output for this particular case, because:

The first BatchNorm layer uses "fixed gamma", which causes some problem when copying the "bn_data_gamma" from MXNet model to Caffe model.

The json2prototxt.py is still NOT fully automatic and cannot deal with this case. To solve the problem, you have to either change the code or manually delete the scaling layer below:

layer {
  bottom: "data"
  top: "bn_data"
  name: "bn_data"
  type: "BatchNorm"
  batch_norm_param {
    use_global_stats: true
    moving_average_fraction: 0.9
    eps: 0.00001  # you may also need to manually set eps base the .json file
  }
}
# ---- delete lines below
layer {
  bottom: "bn_data"
  top: "bn_data"
  name: "bn_data_scale"
  type: "Scale"
  scale_param { bias_term: true }
}
# ---- delete lines above

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

No branches or pull requests

2 participants