Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model2.load_parameters(fp.name)
assert numpy.allclose(asnumpy(model1(x)), asnumpy(model2(x)))
# testing with symbolic (NB with fixed dimensions!)
input = mxnet.sym.Variable('data', shape=x.shape)
json = model1(input).tojson()
model3 = mxnet.gluon.SymbolBlock(outputs=mxnet.sym.load_json(json), inputs=input)
model4 = mxnet.gluon.SymbolBlock(outputs=mxnet.sym.load_json(json), inputs=input)
model3.initialize(ctx=mxnet.cpu())
model3(x)
with tempfile.NamedTemporaryFile(mode='r+b') as fp:
model3.save_parameters(fp.name)
model4.load_parameters(fp.name)
assert numpy.allclose(asnumpy(model3(x)), asnumpy(model4(x)))
try:
# hybridization doesn't work
model1.hybridize(static_alloc=True, static_shape=True)
model1(x)
except:
pass
]
for layer in layers:
model.add(layer)
model.initialize(mxnet.init.Xavier(), ctx=mxnet.cpu())
return model
model1 = create_model()
model2 = create_model()
x = mxnet.ndarray.random_normal(shape=[10, 3, 32, 32])
assert not numpy.allclose(asnumpy(model1(x)), asnumpy(model2(x)))
with tempfile.NamedTemporaryFile(mode='r+b') as fp:
model1.save_parameters(fp.name)
model2.load_parameters(fp.name)
assert numpy.allclose(asnumpy(model1(x)), asnumpy(model2(x)))
# testing with symbolic (NB with fixed dimensions!)
input = mxnet.sym.Variable('data', shape=x.shape)
json = model1(input).tojson()
model3 = mxnet.gluon.SymbolBlock(outputs=mxnet.sym.load_json(json), inputs=input)
model4 = mxnet.gluon.SymbolBlock(outputs=mxnet.sym.load_json(json), inputs=input)
model3.initialize(ctx=mxnet.cpu())
model3(x)
with tempfile.NamedTemporaryFile(mode='r+b') as fp:
model3.save_parameters(fp.name)
model4.load_parameters(fp.name)
assert numpy.allclose(asnumpy(model3(x)), asnumpy(model4(x)))
try:
# hybridization doesn't work