1616from torch .utils .data import DataLoader , BatchSampler , SequentialSampler , Dataset , RandomSampler
1717import torch
1818
19+ import cesnet_tszoo .version as version
1920from cesnet_tszoo .files .utils import get_annotations_path_and_whether_it_is_built_in , get_config_path_and_whether_it_is_built_in , exists_built_in_annotations , exists_built_in_benchmark , exists_built_in_config
2021from cesnet_tszoo .configs .base_config import DatasetConfig
2122from cesnet_tszoo .annotation import Annotations
@@ -260,8 +261,8 @@ def get_train_dataloader(self, ts_id: int | None = None, workers: int | Literal[
260261
261262 assert self .train_dataset is not None , "The train_dataset must be initialized before accessing data from training set."
262263
263- defaultKwargs = {'take_all' : False , "cache_loader" : True }
264- kwargs = {** defaultKwargs , ** kwargs }
264+ default_kwargs = {'take_all' : False , "cache_loader" : True }
265+ kwargs = {** default_kwargs , ** kwargs }
265266
266267 if ts_id is not None :
267268
@@ -364,8 +365,8 @@ def get_val_dataloader(self, ts_id: int | None = None, workers: int | Literal["c
364365
365366 assert self .val_dataset is not None , "The val_dataset must be initialized before accessing data from validation set."
366367
367- defaultKwargs = {'take_all' : False , "cache_loader" : True }
368- kwargs = {** defaultKwargs , ** kwargs }
368+ default_kwargs = {'take_all' : False , "cache_loader" : True }
369+ kwargs = {** default_kwargs , ** kwargs }
369370
370371 if ts_id is not None :
371372
@@ -463,13 +464,13 @@ def get_test_dataloader(self, ts_id: int | None = None, workers: int | Literal["
463464 if self .dataset_config is None or not self .dataset_config .is_initialized :
464465 raise ValueError ("Dataset is not initialized. Please call set_dataset_config_and_initialize() before attempting to access test_dataloader." )
465466
466- if not self .dataset_config .has_all :
467+ if not self .dataset_config .has_test :
467468 raise ValueError ("Dataloader for test set is not available in the dataset configuration." )
468469
469470 assert self .test_dataset is not None , "The test_dataset must be initialized before accessing data from test set."
470471
471- defaultKwargs = {'take_all' : False , "cache_loader" : True }
472- kwargs = {** defaultKwargs , ** kwargs }
472+ default_kwargs = {'take_all' : False , "cache_loader" : True }
473+ kwargs = {** default_kwargs , ** kwargs }
473474
474475 if ts_id is not None :
475476
@@ -572,8 +573,8 @@ def get_all_dataloader(self, ts_id: int | None = None, workers: int | Literal["c
572573
573574 assert self .all_dataset is not None , "The all_dataset must be initialized before accessing data from all set."
574575
575- defaultKwargs = {'take_all' : False , "cache_loader" : True }
576- kwargs = {** defaultKwargs , ** kwargs }
576+ default_kwargs = {'take_all' : False , "cache_loader" : True }
577+ kwargs = {** default_kwargs , ** kwargs }
577578
578579 if ts_id is not None :
579580
@@ -705,7 +706,7 @@ def get_test_df(self, workers: int | Literal["config"] = "config", as_single_dat
705706 if self .dataset_config is None or not self .dataset_config .is_initialized :
706707 raise ValueError ("Dataset is not initialized. Please call set_dataset_config_and_initialize() before attempting to access test_dataloader." )
707708
708- if not self .dataset_config .has_all :
709+ if not self .dataset_config .has_test :
709710 raise ValueError ("Dataloader for test set is not available in the dataset configuration." )
710711
711712 assert self .test_dataset is not None , "The test_dataset must be initialized before accessing data from test set."
@@ -823,7 +824,7 @@ def get_test_numpy(self, workers: int | Literal["config"] = "config") -> np.ndar
823824 if self .dataset_config is None or not self .dataset_config .is_initialized :
824825 raise ValueError ("Dataset is not initialized. Please call set_dataset_config_and_initialize() before attempting to access test_dataloader." )
825826
826- if not self .dataset_config .has_all :
827+ if not self .dataset_config .has_test :
827828 raise ValueError ("Dataloader for test set is not available in the dataset configuration." )
828829
829830 assert self .test_dataset is not None , "The test_dataset must be initialized before accessing data from test set."
@@ -1544,6 +1545,8 @@ def import_config(self, identifier: str, display_config_details: bool = True, wo
15441545 self .logger .info ("Custom config found: %s. Loading it." , identifier )
15451546 config = pickle_load (config_file_path )
15461547
1548+ config ._try_update_version ()
1549+
15471550 self .logger .info ("Initializing dataset configuration with the imported config." )
15481551 self .set_dataset_config_and_initialize (config , display_config_details , workers )
15491552
@@ -1638,6 +1641,7 @@ def save_config(self, identifier: str, create_with_details_file: bool = True, fo
16381641 self .logger .info ("Config details saved to %s" , path_details )
16391642
16401643 self ._update_config_imported_status (identifier )
1644+ self .dataset_config .export_update_needed = False
16411645 self .logger .info ("Config successfully saved" )
16421646
16431647 def save_benchmark (self , identifier : str , force_write : bool = False ) -> None :
@@ -1677,8 +1681,8 @@ def save_benchmark(self, identifier: str, force_write: bool = False) -> None:
16771681 else :
16781682 annotations_both_name = None
16791683
1680- # Use the imported identifier if available, otherwise default to the current identifier
1681- config_name = self .dataset_config .import_identifier if self .dataset_config .import_identifier is not None else identifier
1684+ # Use the imported identifier if available and update is not necessary , otherwise default to the current identifier
1685+ config_name = self .dataset_config .import_identifier if ( self .dataset_config .import_identifier is not None and not self . dataset_config . export_update_needed ) else identifier
16821686
16831687 export_benchmark = ExportBenchmark (self .database_name ,
16841688 self .is_series_based ,
@@ -1687,10 +1691,11 @@ def save_benchmark(self, identifier: str, force_write: bool = False) -> None:
16871691 config_name ,
16881692 annotations_ts_name ,
16891693 annotations_time_name ,
1690- annotations_both_name )
1694+ annotations_both_name ,
1695+ version = version .current_version )
16911696
16921697 # If the config was not imported, save it
1693- if self .dataset_config .import_identifier is None :
1698+ if self .dataset_config .import_identifier is None or self . dataset_config . export_update_needed :
16941699 self .save_config (export_benchmark .config_identifier , force_write = force_write )
16951700 else :
16961701 self .logger .info ("Using already existing config with identifier: %s" , self .dataset_config .import_identifier )
0 commit comments