Created
January 30, 2018 22:58
-
-
Save aaronmarkham/1017664fe683596c614961112a867145 to your computer and use it in GitHub Desktop.
shows a problem with exporting then importing a model in gluon
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
import mxnet as mx | |
from mxnet.test_utils import download | |
from mxnet.gluon.model_zoo import vision as models | |
gpus = 0 | |
contexts = [mx.gpu(i) for i in range(gpus)] if gpus > 0 else [mx.cpu()] | |
deep_dog_net = models.squeezenet1_1(prefix='deep_dog_', classes=2) | |
deep_dog_net.collect_params().initialize(ctx=contexts) | |
download('https://apache-mxnet.s3-accelerate.amazonaws.com/gluon/models/deep-dog-5a342a6f.params', | |
overwrite=True) | |
F = mx.nd.random.uniform(shape=(1,3,224,224), ctx=contexts[0]) | |
deep_dog_net.hybridize() | |
deep_dog_net(F) | |
deep_dog_net.load_params('deep-dog-5a342a6f.params', contexts) | |
# this generates nothotdog-0000.params and nothotdog-symbol.json | |
deep_dog_net.export('nothotdog') | |
# then loading the exported params file will fail with | |
# Parameter conv0_weight is missing in file nothotdog-0000.params | |
deep_dog_net.load_params('nothotdog-0000.params', contexts) | |
# try to allow missing, but fails with | |
# Parameter squeezenet1_conv0_weight loaded from file nothotdog-0000.params is not present in ParameterDict | |
deep_dog_net.load_params('nothotdog-0000.params', ctx=contexts, allow_missing=True) | |
# add ignore_extra=True and it "works" but I image the network is not really loaded properly | |
deep_dog_net.load_params('nothotdog-0000.params', ctx=contexts, allow_missing=True, ignore_extra=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When originally fetching the model from the zoo, if you don't set a prefix, you'll get the default "squeezenet1_", and this will fail too when you try to load the exported params file.
It seems that the
load_params
isn't using the prefix and isn't expecting the network definition to have the prefix.If you set
prefix
to be blank, things seem to start working.The exported params and symbols file now have the prefix now, and now the
load_params
call will work.