-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
51 lines (38 loc) · 1.15 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from datasets import Array3D, Features, load_dataset
from dawgz import after, job, schedule
# isort: split
from utils import *
@job(cpus=4, ram='64GB', time='06:00:00')
def download():
load_dataset('cifar10', cache_dir=PATH / 'hf')
@after(download)
@job(cpus=4, ram='64GB', time='06:00:00')
def corrupt():
corruption = 75
def transform(row):
x = from_pil(row['img'])
A = np.random.uniform(size=(32, 32, 1)) > corruption / 100
y = np.random.normal(loc=A * x, scale=1e-3)
return {'A': A, 'y': y}
types = {
'A': Array3D(shape=(32, 32, 1), dtype='bool'),
'y': Array3D(shape=(32, 32, 3), dtype='float32'),
}
dataset = load_dataset('cifar10', cache_dir=PATH / 'hf')
dataset = dataset.map(
transform,
features=Features(types),
remove_columns=['img', 'label'],
keep_in_memory=True,
num_proc=4,
)
dataset.save_to_disk(PATH / f'hf/cifar-mask-{corruption}')
if __name__ == '__main__':
schedule(
corrupt,
name='Data corruption',
backend='slurm',
export='ALL',
account='ariacpg',
)