NervanaSystems / neon

Intel® Nervana™ reference deep learning framework committed to best performance on all hardware
http://neon.nervanasys.com/docs/latest
Apache License 2.0
3.87k stars 811 forks source link

Model loading error #451

Open zhiltsov-max opened 6 years ago

zhiltsov-max commented 6 years ago

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:

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 commented 6 years ago

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