提交 a5aac614 编写于 作者: T tensor-tang

skip cost when inference

上级 849bf9d0
...@@ -6,8 +6,15 @@ width = 224 ...@@ -6,8 +6,15 @@ width = 224
num_class = 1000 num_class = 1000
batch_size = get_config_arg('batch_size', int, 128) batch_size = get_config_arg('batch_size', int, 128)
use_gpu = get_config_arg('use_gpu', bool, True) use_gpu = get_config_arg('use_gpu', bool, True)
is_infer = get_config_arg("is_infer", bool, False)
args = {'height': height, 'width': width, 'color': True, 'num_class': num_class}
args = {
'height': height,
'width': width,
'color': True,
'num_class': num_class,
'is_infer': is_infer
}
define_py_data_sources2( define_py_data_sources2(
"train.list", "test.list", module="provider", obj="process", args=args) "train.list", "test.list", module="provider", obj="process", args=args)
...@@ -146,7 +153,6 @@ def inception(name, input, channels, \ ...@@ -146,7 +153,6 @@ def inception(name, input, channels, \
return cat return cat
lab = data_layer(name="label", size=1000)
data = data_layer(name="input", size=3 * height * width) data = data_layer(name="input", size=3 * height * width)
# stage 1 # stage 1
...@@ -224,6 +230,10 @@ pool5 = img_pool_layer( ...@@ -224,6 +230,10 @@ pool5 = img_pool_layer(
dropout = dropout_layer(name="dropout", input=pool5, dropout_rate=0.4) dropout = dropout_layer(name="dropout", input=pool5, dropout_rate=0.4)
out3 = fc_layer( out3 = fc_layer(
name="output3", input=dropout, size=1000, act=SoftmaxActivation()) name="output3", input=dropout, size=1000, act=SoftmaxActivation())
loss3 = cross_entropy(name='loss3', input=out3, label=lab)
outputs(loss3) if is_infer:
outputs(out3)
else:
lab = data_layer(name="label", size=num_class)
loss3 = cross_entropy(name='loss3', input=out3, label=lab)
outputs(loss3)
...@@ -13,8 +13,11 @@ def initHook(settings, height, width, color, num_class, **kwargs): ...@@ -13,8 +13,11 @@ def initHook(settings, height, width, color, num_class, **kwargs):
settings.data_size = settings.height * settings.width * 3 settings.data_size = settings.height * settings.width * 3
else: else:
settings.data_size = settings.height * settings.width settings.data_size = settings.height * settings.width
settings.is_infer = kwargs.get('is_infer', False)
settings.slots = [dense_vector(settings.data_size), integer_value(1)] if settings.is_infer:
settings.slots = [dense_vector(settings.data_size)]
else:
settings.slots = [dense_vector(settings.data_size), integer_value(1)]
@provider( @provider(
...@@ -22,5 +25,8 @@ def initHook(settings, height, width, color, num_class, **kwargs): ...@@ -22,5 +25,8 @@ def initHook(settings, height, width, color, num_class, **kwargs):
def process(settings, file_list): def process(settings, file_list):
for i in xrange(1024): for i in xrange(1024):
img = np.random.rand(1, settings.data_size).reshape(-1, 1).flatten() img = np.random.rand(1, settings.data_size).reshape(-1, 1).flatten()
lab = random.randint(0, settings.num_class - 1) if settings.is_infer:
yield img.astype('float32'), int(lab) yield img.astype('float32')
else:
lab = random.randint(0, settings.num_class - 1)
yield img.astype('float32'), int(lab)
...@@ -6,9 +6,15 @@ width = 224 ...@@ -6,9 +6,15 @@ width = 224
num_class = 1000 num_class = 1000
batch_size = get_config_arg('batch_size', int, 64) batch_size = get_config_arg('batch_size', int, 64)
layer_num = get_config_arg("layer_num", int, 50) layer_num = get_config_arg("layer_num", int, 50)
is_test = get_config_arg("is_test", bool, False) is_infer = get_config_arg("is_infer", bool, False)
args = {'height': height, 'width': width, 'color': True, 'num_class': num_class} args = {
'height': height,
'width': width,
'color': True,
'num_class': num_class,
'is_infer': is_infer
}
define_py_data_sources2( define_py_data_sources2(
"train.list", "test.list", module="provider", obj="process", args=args) "train.list", "test.list", module="provider", obj="process", args=args)
...@@ -45,7 +51,10 @@ def conv_bn_layer(name, ...@@ -45,7 +51,10 @@ def conv_bn_layer(name,
act=LinearActivation(), act=LinearActivation(),
bias_attr=False) bias_attr=False)
return batch_norm_layer( return batch_norm_layer(
name=name + "_bn", input=tmp, act=active_type, use_global_stats=is_test) name=name + "_bn",
input=tmp,
act=active_type,
use_global_stats=is_infer)
def bottleneck_block(name, input, num_filters1, num_filters2): def bottleneck_block(name, input, num_filters1, num_filters2):
...@@ -207,7 +216,9 @@ elif layer_num == 152: ...@@ -207,7 +216,9 @@ elif layer_num == 152:
else: else:
print("Wrong layer number.") print("Wrong layer number.")
lbl = data_layer(name="label", size=num_class) if is_infer:
loss = cross_entropy(name='loss', input=resnet, label=lbl) outputs(resnet)
inputs(img, lbl) else:
outputs(loss) lbl = data_layer(name="label", size=num_class)
loss = cross_entropy(name='loss', input=resnet, label=lbl)
outputs(loss)
...@@ -6,8 +6,15 @@ width = 224 ...@@ -6,8 +6,15 @@ width = 224
num_class = 1000 num_class = 1000
batch_size = get_config_arg('batch_size', int, 64) batch_size = get_config_arg('batch_size', int, 64)
layer_num = get_config_arg('layer_num', int, 19) layer_num = get_config_arg('layer_num', int, 19)
is_infer = get_config_arg("is_infer", bool, False)
args = {'height': height, 'width': width, 'color': True, 'num_class': num_class} args = {
'height': height,
'width': width,
'color': True,
'num_class': num_class,
'is_infer': is_infer
}
define_py_data_sources2( define_py_data_sources2(
"train.list", "test.list", module="provider", obj="process", args=args) "train.list", "test.list", module="provider", obj="process", args=args)
...@@ -98,6 +105,9 @@ elif layer_num == 19: ...@@ -98,6 +105,9 @@ elif layer_num == 19:
else: else:
print("Wrong layer number.") print("Wrong layer number.")
lab = data_layer('label', num_class) if is_infer:
loss = cross_entropy(input=vgg, label=lab) outputs(vgg)
outputs(loss) else:
lab = data_layer('label', num_class)
loss = cross_entropy(input=vgg, label=lab)
outputs(loss)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册