torchnet.utils¶
MultiTaskDataLoader¶
-
class
torchnet.utils.MultiTaskDataLoader(datasets, batch_size=1, use_all=False, **loading_kwargs)[source]¶ Bases:
objectLoads batches simultaneously from multiple datasets.
The MultiTaskDataLoader is designed to make multi-task learning simpler. It is ideal for jointly training a model for multiple tasks or multiple datasets. MultiTaskDataLoader is initialzes with an iterable of
Datasetobjects, and provides an iterator which will return one batch that contains an equal number of samples from each of theDatasets.Specifically, it returns batches of
[(B_0, 0), (B_1, 1), ..., (B_k, k)]from datasets(D_0, ..., D_k), where each B_i hasbatch_sizesamplesParameters: - datasets – A list of
Datasetobjects to serve batches from - batch_size – Each batch from each
Datasetwill have this many samples - use_all (bool) – If True, then the iterator will return batches until all datasets are exhausted. If False, then iteration stops as soon as one dataset runs out
- loading_kwargs – These are passed to the children dataloaders
Example
>>> train_loader = MultiTaskDataLoader([dataset1, dataset2], batch_size=3) >>> for ((datas1, labels1), task1), (datas2, labels2), task2) in train_loader: >>> print(task1, task2) 0 1 0 1 ... 0 1
- datasets – A list of
ResultsWriter¶
-
class
torchnet.utils.ResultsWriter(filepath, overwrite=False)[source]¶ Bases:
objectLogs results to a file.
The ResultsWriter provides a convenient interface for periodically writing results to a file. It is designed to capture all information for a given experiment, which may have a sequence of distinct tasks. Therefore, it writes results in the format:
{ 'tasks': [...] 'results': [...] }
The ResultsWriter class chooses to use a top-level list instead of a dictionary to preserve temporal order of tasks (by default).
Parameters: Example
>>> result_writer = ResultWriter(path) >>> for task in ['CIFAR-10', 'SVHN']: >>> train_results = train_model() >>> test_results = test_model() >>> result_writer.update(task, {'Train': train_results, 'Test': test_results})
-
update(task_name, result)[source]¶ Update the results file with new information.
Parameters: - task_name (str) – Name of the currently running task. A previously unseen
task_namewill create a new entry in bothtasksandresults. - result – This will be appended to the list in
resultswhich corresponds to thetask_nameintask_nametasks.
- task_name (str) – Name of the currently running task. A previously unseen
-