Skip to content
Advertisement

How to solve “NotImplementedError”

I defined a three layer convolution layer(self.convs) ,the input tensor has the shape([100,10,24])

JavaScript

When I excuate x_convs = self.convs(Variable(torch.from_numpy(X).type(torch.FloatTensor))), it gives me the error

JavaScript

The ConvBlock is defined as below

JavaScript

The “forward” function has correct indent, so I cannot figure it out what is going on.

Advertisement

Answer

You are trying to call a ModuleList, which is a list (i.e. a list object in Python), slightly modified for being used with PyTorch.

A quick fix would be to call the self.convs as:

JavaScript

That is, although self.convs is a list, each member of it is a Module. You can directly call each member of the self.convs, using its index, e.g. “self.convsan_index`.

Or, you can do it with the help of functools module:

JavaScript

P.S. Though, the Variable keyword is not used anymore.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement