question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model can't find encoding_available variable [BUG]

See original GitHub issue

Describe the bug After fitting TCN model, when attempting to backtest program spits out error regarding self.encoders.encoding_available

Error

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_1955/95313221.py in <module>
      7     retrain=False,
      8     num_samples=1,
----> 9     verbose=True,
     10 )

/lib/python3.7/site-packages/darts/utils/utils.py in sanitized_method(self, *args, **kwargs)
    170 
    171                 getattr(self, sanity_check_method)(*only_args.values(), **only_kwargs)
--> 172             return method_to_sanitize(self, *only_args.values(), **only_kwargs)
    173 
    174         return sanitized_method

/lib/python3.7/site-packages/darts/models/forecasting/forecasting_model.py in historical_forecasts(self, series, past_covariates, future_covariates, num_samples, start, forecast_horizon, stride, retrain, overlap_end, last_points_only, verbose)
    421                 past_covariates=past_covariates,
    422                 future_covariates=future_covariates,
--> 423                 num_samples=num_samples,
    424             )
    425 

/lib/python3.7/site-packages/darts/models/forecasting/forecasting_model.py in _predict_wrapper(self, n, series, past_covariates, future_covariates, num_samples)
   1008             past_covariates=past_covariates,
   1009             future_covariates=future_covariates,
-> 1010             num_samples=num_samples,
   1011         )
   1012 

/lib/python3.7/site-packages/darts/utils/torch.py in decorator(self, *args, **kwargs)
     68         with fork_rng():
     69             manual_seed(self._random_instance.randint(0, high=MAX_TORCH_SEED_VALUE))
---> 70             return decorated(self, *args, **kwargs)
     71 
     72     return decorator

/lib/python3.7/site-packages/darts/models/forecasting/torch_forecasting_model.py in predict(self, n, series, past_covariates, future_covariates, trainer, batch_size, verbose, n_jobs, roll_size, num_samples, num_loader_workers)
   1076         )
   1077 
-> 1078         if self.encoders.encoding_available:
   1079             past_covariates, future_covariates = self.encoders.encode_inference(
   1080                 n=n,

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

To Reproduce

backtest_series = model.historical_forecasts(
    series_transformed,
    start=series_transformed.get_timestamp_at_point(0.6),
    forecast_horizon=7,
    stride=5,
    retrain=False,
    num_samples=1, 
    verbose=True,
)

Expected behavior I expect to backtest on fitted model

System

  • Python version: 3.7.11
  • darts version 0.17.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisbadercommented, Feb 23, 2022

Can you try model = TCNModel.load_model('dt-model.pth.tar') and see if this resolves the issue? load_model() is a class method and returns the loaded model as a new TCNModel object.

1reaction
dennisbadercommented, Feb 23, 2022

Hey @Joe-TheBro, I tried your code snippet and it runs without issues…

This seems strange to me. The encoders should be initialized when model.fit() is called.

Here are some questions:

  • Can you verify your darts version by printing print(darts.__version__)
  • As I can see, you used a jupyter notebook to run the code (is that correct?).
  • Is it possible that your model.fit() failed and that your model is still in its initial state?
  • Can you print print(model.epochs_trained) and check if this is > 0?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Detect encoding and make everything UTF-8 - php
You first have to detect what encoding has been used. As you're parsing RSS feeds (probably via HTTP), you should read the encoding...
Read more >
3 steps to fix encoding problems in Ruby - Justin Weiss
Most encodings are small, and can't handle every possible character. You'll see that error when a character in one encoding doesn't exist in...
Read more >
Filename encoding errors · Issue #1368 · aws/aws-cli - GitHub
I'm using aws s3 sync to upload to a bucket, but I'm getting errors on many files: Please check your locale settings. The...
Read more >
Charset issues - Apache FreeMarker Manual
You can use the encoding setting to specify the charset. This setting takes effect only when FreeMarker loads a template (parsed or unparsed)...
Read more >
You should re-encode high cardinality categorical variables
Nina Zumel and I have been doing a lot of writing on the (important) details of re-encoding high cardinality categorical variables for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found