-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasets.py
61 lines (53 loc) · 2 KB
/
datasets.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
52
53
54
55
56
57
58
59
60
61
# Copyright (c) 2018, Curious AI Ltd. All rights reserved.
#
# This work is licensed under the Creative Commons Attribution-NonCommercial
# 4.0 International License. To view a copy of this license, visit
# http://creativecommons.org/licenses/by-nc/4.0/ or send a letter to
# Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
import torchvision.transforms as transforms
from . import data
from .utils import export
@export
def imagenet():
channel_stats = dict(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
train_transformation = data.TransformTwice(transforms.Compose([
transforms.RandomRotation(10),
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1),
transforms.ToTensor(),
transforms.Normalize(**channel_stats)
]))
eval_transformation = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(**channel_stats)
])
return {
'train_transformation': train_transformation,
'eval_transformation': eval_transformation,
'datadir': 'data-local/images/ilsvrc2012/',
'num_classes': 1000
}
@export
def cifar10():
channel_stats = dict(mean=[0.4914, 0.4822, 0.4465],
std=[0.2470, 0.2435, 0.2616])
train_transformation = data.TransformTwice(transforms.Compose([
data.RandomTranslateWithReflect(4),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize(**channel_stats)
]))
eval_transformation = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(**channel_stats)
])
return {
'train_transformation': train_transformation,
'eval_transformation': eval_transformation,
'datadir': 'data-local/images/cifar/cifar10/by-image',
'num_classes': 10
}