philipperemy / n-beats

Keras/Pytorch implementation of N-BEATS: Neural basis expansion analysis for interpretable time series forecasting.
MIT License
864 stars 166 forks source link

NBeatsNet initialisation error. #28

Closed Priyatham10 closed 3 years ago

Priyatham10 commented 4 years ago

When trying to implement notebook "NBeats-GPU.ipynb" from examples, at the code cell where the net initialisation is done using,

net = NBeatsNet(device=device,
                stack_types=(NBeatsNet.GENERIC_BLOCK, NBeatsNet.GENERIC_BLOCK),
                forecast_length=forecast_length,
                backcast_length=backcast_length,
                hidden_layer_units=128,
                share_weights_in_stack=True,
                )

I got the following error;

| N-Beats
| --  Stack Generic (#0) (share_weights_in_stack=True)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-41-dfdb76bc5848> in <module>()
      4                 backcast_length=backcast_length,
      5                 hidden_layer_units=128,
----> 6                 share_weights_in_stack=True,
      7                 )
      8 optimiser = optim.Adam(net.parameters())

1 frames
/usr/local/lib/python3.6/dist-packages/nbeats_pytorch/model.py in create_stack(self, stack_id)
     48             else:
     49                 block = block_init(self.hidden_layer_units, self.thetas_dim[stack_id],
---> 50                                    self.device, self.backcast_length, self.forecast_length, self.nb_harmonics)
     51                 self.parameters.extend(block.parameters())
     52             print(f'     | -- {block}')

TypeError: __init__() takes from 4 to 6 positional arguments but 7 were given

When I looked into the model.py code, in the block_init, we have; block_init = NBeatsNet.select_block(stack_type). The error says, that we have 7 positional arguments which is true in bock_init initialisation. Please look after the error and throw some light.

Thank you, stay home, stay safe..

lk1983823 commented 4 years ago

I also have this problem and I installed the torch version of 1.3.1.

yuemind commented 4 years ago

Hi, have you got the problem solved? I also met the same problem with torch 1.5. Thanks!

lk1983823 commented 4 years ago

I updated the torch to 1.5 and make install from source. Then it worked.

yuemind commented 4 years ago

I updated the torch to 1.5 and make install from source. Then it worked.

Thanks! Problem solved.

TYtianyang commented 4 years ago

In model.py, the class GenericBlock(Block) module, argument nb_harmonics is not initiated. Try change the code to:

class GenericBlock(Block):

    def __init__(self, units, thetas_dim, device, backcast_length=10, forecast_length=5, nb_harmonics=None):
        super(GenericBlock, self).__init__(units, thetas_dim, device, backcast_length, forecast_length)

        self.backcast_fc = nn.Linear(thetas_dim, backcast_length)
        self.forecast_fc = nn.Linear(thetas_dim, forecast_length)

    def forward(self, x):
        # no constraint for generic arch.
        x = super(GenericBlock, self).forward(x)

        theta_b = F.relu(self.theta_b_fc(x))
        theta_f = F.relu(self.theta_f_fc(x))

        backcast = self.backcast_fc(theta_b)  # generic. 3.3.
        forecast = self.forecast_fc(theta_f)  # generic. 3.3.

        return backcast, forecast

It should work.

philipperemy commented 3 years ago

Yep, I updated the PyPI repository. Update the n-beats with pip and it should work! (version 1.3.3)