Skip to content

Commit e39f7ab

Browse files
Add an example
1 parent 9c44685 commit e39f7ab

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,72 @@ and in many cases, you will **NOT need to write Python code at all**.
4141
Take a look at some configurations available in [configs/](https://github.com/yoshitomo-matsubara/torchdistill/tree/main/configs/).
4242
You'll see what modules are abstracted and how they are defined in a declarative PyYAML config file to design an experiment.
4343

44+
E.g., instantiate CIFAR-10 datasets with a declarative PyYAML config file
45+
```python
46+
from torchdistill.common import yaml_util
47+
config = yaml_util.load_yaml_file('./test.yaml')
48+
train_dataset = config['datasets']['cifar10/train']
49+
test_dataset = config['datasets']['cifar10/test']
50+
```
51+
52+
`test.yaml`
53+
```yaml
54+
datasets:
55+
cifar10/train: !import_call
56+
_name: &dataset_name 'cifar10'
57+
_root: &root_dir !join ['~/datasets/', *dataset_name]
58+
key: 'torchvision.datasets.CIFAR10'
59+
init:
60+
kwargs:
61+
root: *root_dir
62+
train: True
63+
download: True
64+
transform: !import_call
65+
key: 'torchvision.transforms.Compose'
66+
init:
67+
kwargs:
68+
transforms:
69+
- !import_call
70+
key: 'torchvision.transforms.RandomCrop'
71+
init:
72+
kwargs:
73+
size: 32
74+
padding: 4
75+
- !import_call
76+
key: 'torchvision.transforms.RandomHorizontalFlip'
77+
init:
78+
kwargs:
79+
p: 0.5
80+
- !import_call
81+
key: 'torchvision.transforms.ToTensor'
82+
init:
83+
- !import_call
84+
key: 'torchvision.transforms.Normalize'
85+
init:
86+
kwargs: &normalize_kwargs
87+
mean: [0.49139968, 0.48215841, 0.44653091]
88+
std: [0.24703223, 0.24348513, 0.26158784]
89+
cifar10/test: !import_call
90+
key: 'torchvision.datasets.CIFAR10'
91+
init:
92+
kwargs:
93+
root: *root_dir
94+
train: False
95+
download: True
96+
transform: !import_call
97+
key: 'torchvision.transforms.Compose'
98+
init:
99+
kwargs:
100+
transforms:
101+
- !import_call
102+
key: 'torchvision.transforms.ToTensor'
103+
init:
104+
- !import_call
105+
key: 'torchvision.transforms.Normalize'
106+
init:
107+
kwargs: *normalize_kwargs
108+
```
109+
44110
If you want to use your own modules (models, loss functions, datasets, etc) with this framework,
45111
you can do so without editing code in the local package `torchdistill/`.
46112
See [the official documentation](https://yoshitomo-matsubara.net/torchdistill/usage.html) and [Discussions](https://github.com/yoshitomo-matsubara/torchdistill/discussions) for more details.

0 commit comments

Comments
 (0)