Created
December 23, 2016 17:26
-
-
Save Hiroshiba/549052c175356949cba5162151916307 to your computer and use it in GitHub Desktop.
copy chainer's layer weights to Keras' layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy_weights_deconvolution(chainer_model, keras_model, layer_name): | |
deconv_chainer = chainer_model[layer_name] | |
W, b = (deconv_chainer.W.data, deconv_chainer.b.data) | |
keras_model.get_layer(layer_name).set_weights([numpy.transpose(W, (2, 3, 0, 1)), b]) | |
def copy_weights_convolution(chainer_model, keras_model, layer_name): | |
conv_chainer = chainer_model[layer_name] | |
W, b = (conv_chainer.W.data, conv_chainer.b.data) | |
keras_model.get_layer(layer_name).set_weights([numpy.transpose(W, (2, 3, 1, 0)), b]) | |
def copy_weights_bn(chainer_model, keras_model, layer_name): | |
bn_chainer = chainer_model[layer_name] | |
w = [bn_chainer.gamma.data, bn_chainer.beta.data, bn_chainer.avg_mean, bn_chainer.avg_var] | |
keras_model.get_layer(layer_name).set_weights(w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great!
However, have you tested this on any pretrained model?