unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
8.09k stars 881 forks source link

OSError: [WinError 123] when fitting model #386

Closed Mirzoe closed 3 years ago

Mirzoe commented 3 years ago

Hi.

im not able to fit models in darts. Even when i try the example codes.

Read data:

      ts = AirPassengersDataset().load()
      scaler = Scaler()
      ts = scaler.fit_transform(ts)  # scale the whole time series not caring about train/val split...

We'll use the month as a covariate

      month_series = datetime_attribute_timeseries(ts, attribute='month', one_hot=True)
      scaler_month = Scaler()
      month_series = scaler_month.fit_transform(month_series)

Create training and validation sets:

      train, val = ts.split_after(pd.Timestamp('19580801'))
      train_month, val_month = month_series.split_after(pd.Timestamp('19580801'))

Create model:

      model_air = TCNModel(
          input_chunk_length=13,
          output_chunk_length=12,
          n_epochs=500,
          dropout=0.1,
          dilation_base=2,
          weight_norm=True,
          kernel_size=5,
          num_filters=3,
          random_state=0
      )

until her, everything works fine. But when i try to fit the 'model_air' i recieve an error.

fit model:

      model_air.fit(series=train, covariates=train_month, val_series=val, val_covariates=val_month, verbose=True)

Error message:


OSError Traceback (most recent call last)

in ----> 1 model_air.fit(series=train, covariates=train_month, val_series=val, val_covariates=val_month, verbose=True) ~\Anaconda3\envs\darts_env\lib\site-packages\darts\utils\torch.py in decorator(self, *args, **kwargs) 63 with fork_rng(): 64 manual_seed(self._random_instance.randint(0, high=MAX_TORCH_SEED_VALUE)) ---> 65 return decorated(self, *args, **kwargs) 66 return decorator ~\Anaconda3\envs\darts_env\lib\site-packages\darts\models\torch_forecasting_model.py in fit(self, series, covariates, val_series, val_covariates, verbose, epochs) 359 logger.info('Train dataset contains {} samples.'.format(len(train_dataset))) 360 --> 361 self.fit_from_dataset(train_dataset, val_dataset, verbose, epochs) 362 363 @random_method ~\Anaconda3\envs\darts_env\lib\site-packages\darts\utils\torch.py in decorator(self, *args, **kwargs) 63 with fork_rng(): 64 manual_seed(self._random_instance.randint(0, high=MAX_TORCH_SEED_VALUE)) ---> 65 return decorated(self, *args, **kwargs) 66 return decorator ~\Anaconda3\envs\darts_env\lib\site-packages\darts\models\torch_forecasting_model.py in fit_from_dataset(self, train_dataset, val_dataset, verbose, epochs) 385 # Build model, based on the dimensions of the first series in the train set. 386 self.input_dim, self.output_dim = input_dim, output_dim --> 387 self._init_model() 388 else: 389 # Check existing model has input/output dim matching what's provided in the training set. ~\Anaconda3\envs\darts_env\lib\site-packages\darts\models\torch_forecasting_model.py in _init_model(self) 281 self.lr_scheduler = None # We won't use a LR scheduler 282 --> 283 self._save_untrained_model(_get_untrained_models_folder(self.work_dir, self.model_name)) 284 285 @abstractmethod ~\Anaconda3\envs\darts_env\lib\site-packages\darts\models\torch_forecasting_model.py in _save_untrained_model(self, folder) 855 856 def _save_untrained_model(self, folder): --> 857 os.makedirs(folder, exist_ok=True) 858 filename = os.path.join(folder, 'model.pth.tar') 859 ~\Anaconda3\envs\darts_env\lib\os.py in makedirs(name, mode, exist_ok) 221 return 222 try: --> 223 mkdir(name, mode) 224 except OSError: 225 # Cannot rely on checking for EEXIST, since the operating system OSError: [WinError 123] Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch: 'C:\\Users\\mzoellner\\Desktop\\Masterthesis\\5.Programmierung\\Data_preparation\\.darts\\untrained_models\\2021-07-14_12:09:22.608414_torch_model_run_20788' translatet to english: The syntax for the file name, directory name or volume label is incorrect: 'C:\\Users\\mzoellner\\Desktop\\Masterthesis\\5.Programmierung\\Data_preparation\\.darts\\untrained_models\\2021-07-14_12:09:22.608414_torch_model_run_20788' ### Do anyone can help me with this problem ?
rmenzie commented 3 years ago

it could potentially be the file path you are using, try in your model doing this: model_air = TCNModel( input_chunk_length=13, output_chunk_length=12, n_epochs=500, dropout=0.1, dilation_base=2, weight_norm=True, kernel_size=5, num_filters=3, random_state=0, work_dir: 'C:\Users\mzoellner\Desktop\Masterthesis\' )

Mirzoe commented 3 years ago

Thanks for your reply! I still get the same error with your suggestion.
Its really confusing, because the untrained_models folder is generated in the working directory...

piaz97 commented 3 years ago

Hi @Mirzoe,

Thanks for reporting this issue!

Probably, the issue is that Windows FS is not supporting the ":" as part of the file/folder names.

In the latest release, we added the current timestamp as part of the models' folders (for parallelization), and those contain some ":". Unfortunately, we haven't tested this new feature in Windows (macOS and Linux don't complain about that). Sorry for that!

I'll test this on Windows and open a PR for fixing this problem asap.

In the meanwhile, you should still be able to train models by downgrading Darts to version 0.8.

Mirzoe commented 3 years ago

Hi @Mirzoe,

Thanks for reporting this issue!

Probably, the issue is that Windows FS is not supporting the ":" as part of the file/folder names.

In the latest release, we added the current timestamp as part of the models' folders (for parallelization), and those contain some ":". Unfortunately, we haven't tested this new feature in Windows (macOS and Linux don't complain about that). Sorry for that!

I'll test this on Windows and open a PR for fixing this problem asap.

In the meanwhile, you should still be able to train models by downgrading Darts to version 0.8.

Mirzoe commented 3 years ago

Thanks for the reply!

With the downgraded version i'm able to train the models :)

And i have another question. Im trying to train my model with multible, multivariate time series. I have 26 features which i transfer over covariates inside the fit function. While putting the features togeter into one TimeSeries class i face the problem that im only can stack 6 features together. Is this right (i mean that im limited with the num of feature)? or im doing something wrong ?

hrzn commented 3 years ago

The issue with training on Windows has been solved in v0.9.1 => closing the issue.

@Mirzoe Concerning your other problem with stacking several components into a multivariate TimeSeries: there's no such limitation to the number of components. You should be able to have 26 components in a series without issues, so there's another problem somewhere. If you still have this problem I invite you to open another Issue and post some code snippets there so we can try and reproduce.