Skip to content

Commit 3875609

Browse files
committed
add evaluate
1 parent 00cfc40 commit 3875609

File tree

8 files changed

+406
-66
lines changed

8 files changed

+406
-66
lines changed

.DS_Store

6 KB
Binary file not shown.

data/get_data.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import nvidia.dali.ops as ops
99
import nvidia.dali.types as types
1010
except ImportError:
11-
raise ImportError("Please install DALI from https://www.github.com/NVIDIA/DALI to run this example.")
11+
raise ImportError(
12+
"Please install DALI from https://www.github.com/NVIDIA/DALI to run this example.")
1213

1314

1415
def get_data(dataset, data_path, cutout_length, auto_augmentation):
@@ -29,11 +30,14 @@ def get_data(dataset, data_path, cutout_length, auto_augmentation):
2930
n_classes = 1000
3031
else:
3132
raise ValueError(dataset)
32-
trn_transform, val_transform = preproc.data_transforms(dataset, cutout_length, auto_augmentation)
33+
trn_transform, val_transform = preproc.data_transforms(
34+
dataset, cutout_length, auto_augmentation)
3335
if 'imagenet' in dataset:
34-
trn_data = dset_cls(root=os.path.join(data_path, 'train'), transform=trn_transform)
36+
trn_data = dset_cls(root=os.path.join(
37+
data_path, 'train'), transform=trn_transform)
3538
else:
36-
trn_data = dset_cls(root=data_path, train=True, download=True, transform=trn_transform)
39+
trn_data = dset_cls(root=data_path, train=True,
40+
download=True, transform=trn_transform)
3741

3842
# assuming shape is NHW or NHWC
3943
if 'imagenet' in dataset:
@@ -56,9 +60,11 @@ def get_data(dataset, data_path, cutout_length, auto_augmentation):
5660
input_size = shape[1]
5761
ret = [input_size, input_channels, n_classes, trn_data]
5862
if 'imagenet' in dataset:
59-
ret.append(dset_cls(root=os.path.join(data_path, 'val'), transform=val_transform))
63+
ret.append(dset_cls(root=os.path.join(
64+
data_path, 'val'), transform=val_transform))
6065
else:
61-
ret.append(dset_cls(root=data_path, train=False, download=True, transform=val_transform))
66+
ret.append(dset_cls(root=data_path, train=False,
67+
download=True, transform=val_transform))
6268
return ret
6369

6470

@@ -71,7 +77,7 @@ def get_data_dali(dataset, data_path, batch_size=256, num_threads=4):
7177
train_loader = cifar10.get_cifar_iter_dali(type='train', image_dir=data_path,
7278
batch_size=batch_size, num_threads=num_threads)
7379
val_loader = cifar10.get_cifar_iter_dali(type='val', image_dir=data_path,
74-
batch_size=batch_size, num_threads=num_threads)
80+
batch_size=batch_size, num_threads=num_threads)
7581
elif dataset == 'imagenet':
7682
input_size = 224
7783
input_channels = 3
@@ -80,8 +86,8 @@ def get_data_dali(dataset, data_path, batch_size=256, num_threads=4):
8086
batch_size=batch_size, num_threads=num_threads,
8187
crop=224, val_size=256)
8288
val_loader = imagenet.get_imagenet_iter_dali(type='val', image_dir=data_path,
83-
batch_size=batch_size, num_threads=num_threads,
84-
crop=224, val_size=256)
89+
batch_size=batch_size, num_threads=num_threads,
90+
crop=224, val_size=256)
8591
elif dataset == 'imagenet112':
8692
input_size = 112
8793
input_channels = 3
@@ -119,13 +125,16 @@ def get_data_dali(dataset, data_path, batch_size=256, num_threads=4):
119125

120126
class HybridTrainPipe(Pipeline):
121127
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, dali_cpu=False):
122-
super(HybridTrainPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
123-
self.input = ops.FileReader(file_root=data_dir, shard_id=0, num_shards=1, random_shuffle=True)
124-
#let user decide which pipeline works him bets for RN version he runs
128+
super(HybridTrainPipe, self).__init__(batch_size,
129+
num_threads, device_id, seed=12 + device_id)
130+
self.input = ops.FileReader(
131+
file_root=data_dir, shard_id=0, num_shards=1, random_shuffle=True)
132+
# let user decide which pipeline works him bets for RN version he runs
125133
if dali_cpu:
126134
dali_device = "cpu"
127135
self.decode = ops.HostDecoderRandomCrop(device=dali_device, output_type=types.RGB,
128-
random_aspect_ratio=[0.8, 1.25],
136+
random_aspect_ratio=[
137+
0.8, 1.25],
129138
random_area=[0.1, 1.0],
130139
num_attempts=100)
131140
else:
@@ -135,17 +144,20 @@ def __init__(self, batch_size, num_threads, device_id, data_dir, crop, dali_cpu=
135144
self.decode = ops.nvJPEGDecoderRandomCrop(device="mixed", output_type=types.RGB,
136145
device_memory_padding=211025920,
137146
host_memory_padding=140544512,
138-
random_aspect_ratio=[0.8, 1.25],
147+
random_aspect_ratio=[
148+
0.8, 1.25],
139149
random_area=[0.1, 1.0],
140150
num_attempts=100)
141-
self.res = ops.Resize(device=dali_device, resize_x=crop, resize_y=crop, interp_type=types.INTERP_TRIANGULAR)
151+
self.res = ops.Resize(device=dali_device, resize_x=crop,
152+
resize_y=crop, interp_type=types.INTERP_TRIANGULAR)
142153
self.cmnp = ops.CropMirrorNormalize(device="gpu",
143154
output_dtype=types.FLOAT,
144155
output_layout=types.NCHW,
145156
crop=(crop, crop),
146157
image_type=types.RGB,
147-
mean=[0.485 * 255,0.456 * 255,0.406 * 255],
148-
std=[0.229 * 255,0.224 * 255,0.225 * 255])
158+
mean=[0.485 * 255, 0.456 *
159+
255, 0.406 * 255],
160+
std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
149161
self.coin = ops.CoinFlip(probability=0.5)
150162
# self.color_jitter = [ops.Brightness(device="gpu", brightness=0.4),
151163
# ops.Contrast(device="gpu", contrast=0.4),
@@ -166,16 +178,20 @@ def define_graph(self):
166178

167179
class HybridValPipe(Pipeline):
168180
def __init__(self, batch_size, num_threads, device_id, data_dir, crop, size):
169-
super(HybridValPipe, self).__init__(batch_size, num_threads, device_id, seed=12 + device_id)
170-
self.input = ops.FileReader(file_root=data_dir, shard_id=0, num_shards=1, random_shuffle=False)
181+
super(HybridValPipe, self).__init__(batch_size,
182+
num_threads, device_id, seed=12 + device_id)
183+
self.input = ops.FileReader(
184+
file_root=data_dir, shard_id=0, num_shards=1, random_shuffle=False)
171185
self.decode = ops.nvJPEGDecoder(device="mixed", output_type=types.RGB)
172-
self.res = ops.Resize(device="gpu", resize_shorter=size, interp_type=types.INTERP_TRIANGULAR)
186+
self.res = ops.Resize(device="gpu", resize_shorter=size,
187+
interp_type=types.INTERP_TRIANGULAR)
173188
self.cmnp = ops.CropMirrorNormalize(device="gpu",
174189
output_dtype=types.FLOAT,
175190
output_layout=types.NCHW,
176191
crop=(crop, crop),
177192
image_type=types.RGB,
178-
mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
193+
mean=[0.485 * 255, 0.456 *
194+
255, 0.406 * 255],
179195
std=[0.229 * 255, 0.224 * 255, 0.225 * 255])
180196

181197
def define_graph(self):
@@ -189,13 +205,12 @@ def define_graph(self):
189205
def get_dali_imagenet_pipeline(batch_size, num_threads, data_path, train_cpu=False,
190206
crop=224, size=256):
191207
train_pipe = HybridTrainPipe(batch_size=batch_size, num_threads=num_threads, device_id=0,
192-
data_dir=os.path.join(data_path, 'train'),
193-
crop=crop, dali_cpu=train_cpu)
208+
data_dir=os.path.join(data_path, 'train'),
209+
crop=crop, dali_cpu=train_cpu)
194210
train_pipe.build()
195211

196212
val_pipe = HybridValPipe(batch_size=batch_size, num_threads=num_threads, device_id=0,
197-
data_dir=os.path.join(data_path, 'val'),
198-
crop=crop, size=size)
213+
data_dir=os.path.join(data_path, 'val'),
214+
crop=crop, size=size)
199215
val_pipe.build()
200216
return [train_pipe, val_pipe]
201-

flops_counter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def count_linear(m, _, __):
4444
def profile(model, input_size, custom_ops=None):
4545
handler_collection = []
4646
custom_ops = {} if custom_ops is None else custom_ops
47-
47+
4848
def add_hooks(m_):
4949
if len(list(m_.children())) > 0:
5050
return
@@ -86,6 +86,8 @@ def add_hooks(m_):
8686
for m in model.modules():
8787
if len(list(m.children())) > 0: # skip for non-leaf module
8888
continue
89+
print(m)
90+
print(m.total_ops)
8991
total_ops += m.total_ops
9092
total_params += m.total_params
9193

@@ -96,4 +98,4 @@ def add_hooks(m_):
9698
for handler in handler_collection:
9799
handler.remove()
98100

99-
return float(total_ops) / 1000. / 1000., float(total_params) / 1024. / 1024.
101+
return float(total_ops), float(total_params)

models/.DS_Store

6 KB
Binary file not shown.

models/get_model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@
139139
reduce_concat=range(2, 6))
140140

141141
DDPNAS_V3_constraint_4 = Genotype(normal=[[('sep_conv_5x5', 0), ('sep_conv_3x3', 1)], [('sep_conv_3x3', 0), ('skip_connect', 1)], [('sep_conv_3x3', 0), ('dil_conv_3x3', 3)], [('sep_conv_5x5', 0), ('avg_pool_3x3', 4)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('skip_connect', 0)], [('sep_conv_5x5', 1), ('dil_conv_3x3', 0)], [('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('sep_conv_5x5', 1), ('avg_pool_3x3', 3)]], reduce_concat=range(2, 6))
142-
142+
# dynamic_SNG_V3 = Genotype(normal=[[('max_pool_3x3', 1), ('avg_pool_3x3', 0)], [('max_pool_3x3', 1), ('sep_conv_5x5', 2)], [('skip_connect', 2), ('max_pool_3x3', 3)], [('max_pool_3x3', 3), ('sep_conv_3x3', 0)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('max_pool_3x3', 0)], [('max_pool_3x3', 1), ('max_pool_3x3', 2)], [('sep_conv_5x5', 1), ('sep_conv_5x5', 2)], [('sep_conv_3x3', 0), ('avg_pool_3x3', 1)]], reduce_concat=range(2, 6))
143143
# BPE models
144+
dynamic_SNG_V3 = Genotype(normal=[[('sep_conv_5x5', 0), ('sep_conv_5x5', 1)], [('max_pool_3x3', 0), ('skip_connect', 1)], [('sep_conv_3x3', 2), ('sep_conv_3x3', 1)], [('skip_connect', 4), ('sep_conv_5x5', 3)]], normal_concat=range(2, 6), reduce=[[('sep_conv_5x5', 1), ('dil_conv_3x3', 0)], [('skip_connect', 2), ('avg_pool_3x3', 0)], [('avg_pool_3x3', 1), ('dil_conv_5x5', 2)], [('sep_conv_3x3', 3), ('dil_conv_5x5', 2)]], reduce_concat=range(2, 6))
145+
144146
BPE_models = {
145147
'EA_BPE1': "Genotype(normal=[[('avg_pool_3x3', 0), ('skip_connect', 1)], [('skip_connect', 0), ('sep_conv_3x3', 1)], [('sep_conv_5x5', 0), ('dil_conv_5x5', 1)], [('sep_conv_3x3', 0), ('sep_conv_5x5', 2)]], normal_concat=range(2, 6), reduce=[[('max_pool_3x3', 0), ('sep_conv_3x3', 1)], [('sep_conv_5x5', 0), ('sep_conv_5x5', 2)], [('sep_conv_3x3', 0), ('skip_connect', 2)], [('max_pool_3x3', 1), ('skip_connect', 2)]], reduce_concat=range(2, 6))",
146148

@@ -159,14 +161,14 @@
159161
'RS_BPE2': "Genotype(normal=[[('skip_connect', 1), ('sep_conv_3x3', 0)], [('avg_pool_3x3', 2), ('skip_connect', 0)], [('sep_conv_3x3', 1), ('avg_pool_3x3', 3)], [('avg_pool_3x3', 0), ('dil_conv_3x3', 2)]], normal_concat=range(2, 6), reduce=[[('skip_connect', 1), ('dil_conv_3x3', 0)], [('max_pool_3x3', 1), ('dil_conv_3x3', 0)], [('dil_conv_5x5', 3), ('max_pool_3x3', 0)], [('skip_connect', 3), ('dil_conv_3x3', 2)]], reduce_concat=range(2, 6))"
160162
}
161163

162-
163164
DARTS_NAS_model_dict = {'MDENAS': MDENAS,
164165
'DDPNAS_V1': DDPNAS_1,
165166
'DDPNAS_V2': DDPNAS_2,
166167
'DDPNAS_V3': DDPNAS_3,
167168
'DDPNAS_V3_constraint_4': DDPNAS_V3_constraint_4,
168169
'DARTS_V1': DARTS_V1,
169170
'DARTS_V2': DARTS_V2,
171+
'dynamic_SNG_V3': dynamic_SNG_V3,
170172
'EA_BPE1': from_str(BPE_models['EA_BPE1']),
171173
'EA_BPE2': from_str(BPE_models['EA_BPE2']),
172174
'RL_BPE1': from_str(BPE_models['RL_BPE1']),

models/ofa/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)