You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/09/30 08:50:03 UTC
[GitHub] [incubator-mxnet] haojin2 opened a new issue #19257: Error when loading back saved model weights
haojin2 opened a new issue #19257:
URL: https://github.com/apache/incubator-mxnet/issues/19257
## Desciption
Gluon will throw exception when trying to load back model weights that were just saved seconds ago
## Version
cu102mkl 1.6.0.post0
## Minimal Reproduction
```python
from mxnet.gluon import HybridBlock
from mxnet.gluon.nn import Dense
from mxnet import nd
class MLP(HybridBlock):
def __init__(self, units, prefix=None):
super(MLP, self).__init__(prefix=prefix)
with self.name_scope():
self.layer = Dense(units, activation='sigmoid')
def hybrid_forward(self, F, x):
return self.layer(x)
model = MLP(100, prefix=None)
model.initialize()
test = nd.random.uniform(shape=(1, 100))
model.hybridize()
model.forward(test)
nd.waitall()
print(model.collect_params().keys())
model.export("mlp")
model.load_parameters('mlp-0000.params')
```
## Exception & Stack Trace
```
odict_keys(['mlp0_dense0_weight', 'mlp0_dense0_bias'])
Traceback (most recent call last):
File "test.py", line 29, in <module>
model.load_parameters('mlp-0000.params')
File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/mxnet/gluon/block.py", line 530, in load_parameters
cast_dtype=cast_dtype, dtype_source=dtype_source)
File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/mxnet/gluon/parameter.py", line 1012, in load
ignore_extra, restore_prefix, filename, cast_dtype, dtype_source)
File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/mxnet/gluon/parameter.py", line 1047, in load_dict
name[lprefix:], error_str, _brief_print_list(arg_dict.keys()))
AssertionError: Parameter 'dense0_weight' is missing in file: mlp-0000.params, which contains parameters: 'mlp0_mlp0_dense0_weight', 'mlp0_mlp0_dense0_bias'. Please make sure source and target networks have the same prefix.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org
[GitHub] [incubator-mxnet] szha closed issue #19257: HybridBlock.export parameter naming scheme is incompatible with Block.load_parameters
Posted by GitBox <gi...@apache.org>.
szha closed issue #19257:
URL: https://github.com/apache/incubator-mxnet/issues/19257
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org
[GitHub] [incubator-mxnet] leezu commented on issue #19257: Error when loading back saved model weights
Posted by GitBox <gi...@apache.org>.
leezu commented on issue #19257:
URL: https://github.com/apache/incubator-mxnet/issues/19257#issuecomment-701522799
If you use `export`, you want to use `SymbolBlock.imports` to load the model back. If you're just interested in the parameters, you can use `save_parameters` / `load_parameters`. In summary, it's expected that your example doesn't work as it mixes the two APIs. It's unfortunate that the two APIs use different naming schemes, but may not change for backwards compat reason.
https://github.com/apache/incubator-mxnet/blob/c76593162c2a5e421243dd09a8c3cde044efaa3f/python/mxnet/gluon/block.py#L1077-L1079
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org