Commit d156c501 authored by Felix Bragman's avatar Felix Bragman

fixed bugs that existed in initiall vgg16 body

parent 44db7958
...@@ -48,68 +48,40 @@ class MT1_VGG16Net(BaseNet): ...@@ -48,68 +48,40 @@ class MT1_VGG16Net(BaseNet):
{'name': 'layer_4', 'n_features': 512*2, 'kernel_size': 3, 'repeat': 3}, {'name': 'layer_4', 'n_features': 512*2, 'kernel_size': 3, 'repeat': 3},
{'name': 'maxpool_4'}, {'name': 'maxpool_4'},
{'name': 'layer_5', 'n_features': 512*2, 'kernel_size': 3, 'repeat': 3}, {'name': 'layer_5', 'n_features': 512*2, 'kernel_size': 3, 'repeat': 3},
{'name': 'maxpool_5'}] {'name': 'maxpool_5'},
{'name': 'fc_1', 'n_features': 4096*2},
{'name': 'fc_2', 'n_features': 4096*2}]
self.task1_layers = [ self.task1_layers = [
{'name': 'fc_1', 'n_features': 4096*2}, {'name': 'task_1_out', 'n_features': task1_classes}]
{'name': 'fc_2', 'n_features': 4096*2},
{'name': 'fc_3', 'n_features': task1_classes}]
self.task2_layers = [ self.task2_layers = [
{'name': 'fc_1', 'n_features': 4096*2}, {'name': 'task_2_out', 'n_features': task2_classes}]
{'name': 'fc_2', 'n_features': 4096*2},
{'name': 'fc_3', 'n_features': task2_classes}]
def layer_op(self, images, is_training=True, layer_id=-1, **unused_kwargs): def layer_op(self, images, is_training=True, layer_id=-1, **unused_kwargs):
#assert layer_util.check_spatial_dims(
# images, lambda x: x % 224 == 0)
# main network graph # main network graph
flow, layer_instances = self.create_main_network_graph(images, is_training) flow, layer_instances = self.create_main_network_graph(images, is_training)
# add task 1 output # add task 1 output
flow_t1 = flow task1_layer = self.task1_layers
for layer_iter, layer in enumerate(self.task1_layers): fc_layer = FullyConnectedLayer(
n_output_chns=task1_layer['n_features'],
if layer_iter == len(self.layers)-1: w_initializer=self.initializers['w'],
fc_layer = FullyConnectedLayer( w_regularizer=self.regularizers['w'],
n_output_chns=layer['n_features'], )
w_initializer=self.initializers['w'], task1_out = fc_layer(flow)
w_regularizer=self.regularizers['w'], layer_instances.append((fc_layer, task1_out))
)
task1_out = fc_layer(flow_t1) # add task 2 output
layer_instances.append((fc_layer, task1_out)) task2_layer = self.task2_layers
else: fc_layer = FullyConnectedLayer(
fc_layer = FullyConnectedLayer( n_output_chns=task1_layer['n_features'],
n_output_chns=layer['n_features'], w_initializer=self.initializers['w'],
acti_func=self.acti_func, w_regularizer=self.regularizers['w'],
w_initializer=self.initializers['w'], )
w_regularizer=self.regularizers['w'], task2_out = fc_layer(flow)
) layer_instances.append((fc_layer, task2_out))
flow_t1 = fc_layer(flow_t1)
layer_instances.append((fc_layer, flow_t1))
# add task 1 output
flow_t2 = flow
for layer_iter, layer in enumerate(self.task2_layers):
if layer_iter == len(self.layers) - 1:
fc_layer = FullyConnectedLayer(
n_output_chns=layer['n_features'],
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
)
task2_out = fc_layer(flow_t2)
layer_instances.append((fc_layer, task2_out))
else:
fc_layer = FullyConnectedLayer(
n_output_chns=layer['n_features'],
acti_func=self.acti_func,
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
)
flow_t2 = fc_layer(flow_t2)
layer_instances.append((fc_layer, flow_t2))
if is_training: if is_training:
self._print(layer_instances) self._print(layer_instances)
...@@ -141,9 +113,21 @@ class MT1_VGG16Net(BaseNet): ...@@ -141,9 +113,21 @@ class MT1_VGG16Net(BaseNet):
name=layer['name']) name=layer['name'])
flow = conv_layer(images, is_training) flow = conv_layer(images, is_training)
layer_instances.append((conv_layer, flow)) layer_instances.append((conv_layer, flow))
repeat_conv = repeat_conv - 1
# last layer # last layer
elif layer_iter == len(self.layers)-1: if layer_iter == len(self.layers) - 1:
fc_layer = FullyConnectedLayer(
n_output_chns=layer['n_features'],
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
)
flow = fc_layer(flow)
layer_instances.append((fc_layer, flow))
continue
# all other
if layer_type == 'maxpool':
downsample_layer = DownSampleLayer( downsample_layer = DownSampleLayer(
kernel_size=2, kernel_size=2,
func='MAX', func='MAX',
...@@ -151,55 +135,29 @@ class MT1_VGG16Net(BaseNet): ...@@ -151,55 +135,29 @@ class MT1_VGG16Net(BaseNet):
flow = downsample_layer(flow) flow = downsample_layer(flow)
layer_instances.append((downsample_layer, flow)) layer_instances.append((downsample_layer, flow))
# all other elif layer_type == 'layer':
else:
for _ in range(repeat_conv):
conv_layer = ConvolutionalLayer(
n_output_chns=layer['n_features'],
kernel_size=layer['kernel_size'],
acti_func=self.acti_func,
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
name=layer['name'])
flow = conv_layer(flow, is_training)
layer_instances.append((conv_layer, flow))
elif layer_type == 'fc':
# In case we want multiple convs before first maxpool fc_layer = FullyConnectedLayer(
if repeat_conv > 1: n_output_chns=layer['n_features'],
for _ in range(repeat_conv-1): acti_func=self.acti_func,
conv_layer = ConvolutionalLayer( w_initializer=self.initializers['w'],
n_output_chns=layer['n_features'], w_regularizer=self.regularizers['w'],
kernel_size=layer['kernel_size'], )
acti_func=self.acti_func, flow = fc_layer(flow)
w_initializer=self.initializers['w'], layer_instances.append((fc_layer, flow))
w_regularizer=self.regularizers['w'],
name=layer['name'])
flow = conv_layer(flow, is_training)
layer_instances.append((conv_layer, flow))
else:
if layer_type == 'maxpool':
downsample_layer = DownSampleLayer(
kernel_size=2,
func='MAX',
stride=2)
flow = downsample_layer(flow)
layer_instances.append((downsample_layer, flow))
elif layer_type == 'layer':
for _ in range(repeat_conv):
conv_layer = ConvolutionalLayer(
n_output_chns=layer['n_features'],
kernel_size=layer['kernel_size'],
acti_func=self.acti_func,
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
name=layer['name'])
flow = conv_layer(flow, is_training)
layer_instances.append((conv_layer, flow))
elif layer_type == 'fc':
fc_layer = FullyConnectedLayer(
n_output_chns=layer['n_features'],
acti_func=self.acti_func,
w_initializer=self.initializers['w'],
w_regularizer=self.regularizers['w'],
)
flow = fc_layer(flow)
layer_instances.append((fc_layer, flow))
return flow, layer_instances return flow, layer_instances
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment