Andrew Andrew - 1 year ago 62
Python Question

Nervana Neon AttributeError: 'NoneType' object has no attribute 'sizeI'

I'm a trying to do fprop with Nervana Neon, however, when I go to run model fprop I get the following error:

AttributeError: 'NoneType' object has no attribute 'sizeI'

I am following their example for fprop very close. I've trained the model using their
and now I want to utilize the results in a system. I've tried using
but still issues. Any thoughts?

xdev = np.zeros((3 * 224 * 224, batch_size), dtype=np.float32)
xbuf = np.zeros((3 * 224 * 224, batch_size), dtype=np.float32)
img = to_neon(new_img) # function to flatten image to (3 * 224 * 224, )
xbuf[:,0] = img[:, 0]
model = model.load_params("/path/to/params.p")
out = model.fprop(xdev)
AttributeError Traceback (most recent call last)
<ipython-input-35-fc650f5dcbc4> in <module>()
----> 1 out = model.fprop(xdev)

/root/neon/neon/models/model.pyc in fprop(self, x, inference)
213 Tensor: the output of the final layer in the model
214 """
--> 215 return self.layers.fprop(x, inference)
217 def bprop(self, delta):

/root/neon/neon/layers/container.pyc in fprop(self, inputs, inference, beta)
248 x = l.fprop(x, inference, beta=beta)
249 else:
--> 250 x = l.fprop(x, inference)
252 if inference:

/root/neon/neon/layers/layer.pyc in fprop(self, inputs, inference, beta)
787 self.inputs = inputs
788, inputs, self.W, self.outputs, beta=beta,
--> 789 bsum=self.batch_sum)
790 return self.outputs

/root/neon/neon/backends/nervanagpu.pyc in fprop_conv(self, layer, I, F, O, X, bias, bsum, alpha, beta, relu, brelu, slope, repeat)
1936 repeat: used in benchmarking
1937 """
-> 1938 assert layer.sizeI == I.size
1939 assert layer.sizeF == F.size
1940 assert layer.sizeO == O.size

AttributeError: 'NoneType' object has no attribute 'sizeI'

Answer Source

Working backwards on your stacktrace...

The problem comes from an attempt to dereference the sizeI attribute of a layer object when layer is None:

-> 1938 assert layer.sizeI == I.size

I'd call that a bug in the neon library (backends/ it should have above that 1938 line something like:

    assert isinstance(layer, TheExpectedLayerClass)

A similar check could have been added even earlier, in layers/, before line 788:

    assert isinstance(self.nglayer, TheExpectedLayerClass)

But often hitting such bugs in 3rd party libs are simply indications that the library is not used in the way it was intended to. The bugs simply obscure the real cause by not making the proper checks earlier, where maybe it's clear what's missing.

So check the docs/tutorials, maybe you're missing some init/setup step, some additional argument somewhere, etc. Or, if you're more familiar with neon, keep going backwards on the stacktrace until you find what's missing.