Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Model loading error #451

Open
zhiltsov-max opened this issue Apr 21, 2018 · 1 comment
Open

Model loading error #451

zhiltsov-max opened this issue Apr 21, 2018 · 1 comment

Comments

@zhiltsov-max
Copy link

Hello, I have faced an issue in model loading while trying to load ResNet-like model. The simplest steps to reproduce I found is to use the following model:

# input = (3, 128, 128), 2 classes
layers = [ Conv(fshape=(1, 1, 2), padding=0, strides=128, dilation=1, init=Xavier()) ]
model = Model(layers)

This produces the following error during loading from saved weights:

  File "<...>/neon/models/model.py", line 177, in fit
    callbacks.on_train_begin(num_epochs)
  File "<...>/neon/callbacks/callbacks.py", line 267, in on_train_begin
    self.model().load_params(self.model_file)
  File "<...>/neon/models/model.py", line 418, in load_params
    self.deserialize(load_obj(param_path), load_states=load_states)
  File "<...>/neon/models/model.py", line 479, in deserialize
    self.layers.load_weights(model_dict['model'], load_states)
  File "<...>/neon/layers/container.py", line 199, in load_weights
    pdict['config']['layers'] = self.fusion_pass(pdict['config']['layers'])
  File "<...>/neon/layers/container.py", line 178, in fusion_pass
    if any([pattern(l1, l2) for pattern in patterns]): #if (l1 is not None and l2 is not None)
  File "<...>/neon/layers/container.py", line 178, in <listcomp>
    if any([pattern(l1, l2) for pattern in patterns]): #if (l1 is not None and l2 is not None)
  File "<...>/neon/layers/container.py", line 172, in <lambda>
    y['type'] == 'neon.layers.layer.Bias']
TypeError: 'NoneType' object is not subscriptable

The key components of this problem is:

  • pairwise function, which adds a None element to the list;
  • This line, which calls pattern function on the None value of l2;
  • The single layer in saved model layers list. This is not rare in ResNet-like models because of projection residual connections, which are saved by MergeSum (used for branches concatenation) as a separate layer list.

The solution I found is to skip pairs with None values:

if any([pattern(l1, l2) for pattern in patterns if (l1 is not None and l2 is not None)]):

Environment: python 3.5.2, neon 2.6.0 (f9d771b).

@baojun-nervana
Copy link
Contributor

@zhiltsov-max Thanks for the finding and improving neon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants