Search code examples
pythonclass-methoddeepargluonts

Why estimator.train() in gluonts.deepar returns TypeError : classmethod cannot be called on an instance?


Helloo, I am trying to use deepar with gluonts (gluonts.torch.model.deepar), here is my code :

estimator = DeepAREstimator(freq='M', prediction_length=18, num_layers=3, trainer_kwargs={'max_epochs':5})
predictor = estimator.train(training_data=df, num_workers=2)
pred = predictor.predict(df)

The second line gives me this error : TypeError: The classmethod DeepARLightningModule.load_from_checkpoint cannot be called on an instance. Please call it on the class type and make sure the return value is used. I don't understand, I can't find a solution on the web. I wonder if there is an issue in the gluonts.torch.model.deepar package because I am not calling directly DeepARLightningModule.load_from_checkpoint.

I successfuly used gluonts.deepar with this code below for the predictor part :

transformation = estimator.create_transformation()
module = estimator.create_lightning_module()
predictor = estimator.create_predictor(transformation, module)

But I guess there is no training part with this code because the dataset is given only for prediction and not for training, so I would like to do it with the first method.

Thank you very much and have a nice day :)


Solution

  • I was using torch (gluonts.torch.model.deepar), there is no problem using train() with mx's deepar version (glonts.mx.model.deepar). I just needed to downgrade numpy in my venv. –