frarch.utils.data package#

frarch.utils.data.build_experiment_structure(hparams_file: Union[str, pathlib.Path], experiment_folder: Union[str, pathlib.Path], overrides: Optional[Mapping] = None, debug: bool = False)[source]#

Construct experiment folder hierarchy on experiment_folder.

Parameters
  • hparams_file (Union[str, Path]) – hparams configuration file path.

  • experiment_folder (Union[str, Path]) – Folder where to store experiment files. Defaults to “results/debug/”.

  • overrides (Mapping, optional) – Parameters to override on hparams file. Defaults to None.

  • debug (bool, optional) – debug flag. Defaults to False.

frarch.utils.data.create_dataloader(dataset: torch.utils.data.dataset.Dataset, **dataloader_kwargs) torch.utils.data.dataloader.DataLoader[source]#

Create dataloader from dataset.

Parameters

dataset (torch.utils.data.Dataset) – dataset object to feed onto DataLoader.

Raises

ValueError – dataset is not a Dataset or does not inherit from it.

Returns

dataloader with the dataset object.

Return type

torch.utils.data.DataLoader

frarch.utils.data.download_url(url: str, destination: Optional[str] = None, progress_bar: bool = True) str[source]#

Download a URL to a local file.

Parameters
  • url (str) – The URL to download.

  • destination (Optional[str], optional) – The destination of the file. If None is given the file is saved to a temporary directory. Defaults to None.

  • progress_bar (bool, optional) – The destination of the file. If None is given the file is saved to a temporary directory. Defaults to True.

Returns

filename of downloaded file.

Return type

str

frarch.utils.data.read_file(filepath: Union[str, pathlib.Path]) str[source]#

Read contents of file.

Parameters

filepath (Union[str, Path]) – path to file.

Returns

contents of the file

Return type

str

frarch.utils.data.tensor_in_device(data: Any, device: str = 'cpu', **kwargs) torch.Tensor[source]#

Create tensor in device.

Parameters
  • data (Any) – data on the tensor.

  • device (str, optional) – string of the device to be created in. Defaults to “cpu”.

Returns

tensor in device.

Return type

torch.Tensor