Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Symbolic .json file not compatible with .params file generated since MXNet 1.2 #11091

Description

@ThomasDelteil

Since MXNet 1.2.0 one possible way of serializing Gluon models is not working anymore.

Reproducible here:

import mxnet as mx
from mxnet import gluon
ctx = mx.cpu()

# Create network
net = gluon.nn.HybridSequential(prefix="test_")
with net.name_scope():
    net.add(gluon.nn.Conv2D(10, (3, 3)))
    net.add(gluon.nn.Dense(50))
net.initialize()
net(mx.nd.ones((1,1,50,50)))

# Save network
a = net(mx.sym.var('data'))
a.save('test.json')
net.save_params('test.params')

# Load network
net2 = gluon.nn.HybridSequential(prefix="test_")
with net2.name_scope():
    sym = mx.sym.load_json(open('test.json', 'r').read())
    net2.add(gluon.nn.SymbolBlock(outputs=sym, inputs=mx.sym.var('data')))
net2.load_params('test.params', ctx=ctx)

Gives the following error:

AssertionError: Parameter 'conv0_weight' is missing in file 'test.params', which contains parameters: '0.weight', '0.bias', '1.weight', '1.bias'. Set allow_missing=True to ignore missing parameters.

Whilst it worked in 1.1.0.

This way of exporting symbol is recommended in this tutorial on the straight dope

The current recommended way, as described in the upcoming tutorial here, is to use the hybridized .export() function.

this would look like that, and works in 1.1.0 and 1.2.0:

import mxnet as mx
from mxnet import gluon
ctx = mx.cpu()

# Create network
net = gluon.nn.HybridSequential(prefix="test_")
with net.name_scope():
    net.add(gluon.nn.Conv2D(10, (3, 3)))
    net.add(gluon.nn.Dense(50))
net.initialize()

# Save network    
net.hybridize()
net(mx.nd.ones((1,1,50,50)))
net.export('test', epoch=0)

# Load network
sym = mx.sym.load_json(open('test-symbol.json', 'r').read())
net2 = gluon.nn.SymbolBlock(outputs=sym, inputs=mx.sym.var('data'))
net2.load_params('test-0000.params', ctx=ctx)

This is affecting people who were until now using this method.

@ifeherva reported this issue is affecting his team.

@piiswrong @marcoabreu @szha

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions