Commit 22569cc1 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Organized the transfer learning variables for the estimators

parent 77838cb4
Pipeline #13778 failed with stages
in 20 minutes and 20 seconds
......@@ -127,6 +127,7 @@ class Triplet(estimator.Estimator):
if self.extra_checkpoint is not None:
tf.contrib.framework.init_from_checkpoint(self.extra_checkpoint["checkpoint_path"],
self.extra_checkpoint["scopes"])
# Compute Loss (for both TRAIN and EVAL modes)
self.loss = self.loss_op(prelogits_anchor, prelogits_positive, prelogits_negative)
......
......@@ -48,7 +48,7 @@ def block35(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, tr
return net
# Inception-Renset-B
def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None):
def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, trainable_variables=True):
"""Builds the 17x17 resnet block."""
with tf.variable_scope(scope, 'Block17', [net], reuse=reuse):
with tf.variable_scope('Branch_0'):
......@@ -69,7 +69,7 @@ def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None):
# Inception-Resnet-C
def block8(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None):
def block8(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, trainable_variables=True):
"""Builds the 8x8 resnet block."""
with tf.variable_scope(scope, 'Block8', [net], reuse=reuse):
with tf.variable_scope('Branch_0'):
......@@ -88,7 +88,7 @@ def block8(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None):
net = activation_fn(net)
return net
def reduction_a(net, k, l, m, n, trainable_variables=True, reuse=True):
def reduction_a(net, k, l, m, n, trainable_variables=True, reuse=None):
with tf.variable_scope('Branch_0', reuse=reuse):
tower_conv = slim.conv2d(net, n, 3, stride=2, padding='VALID',
scope='Conv2d_1a_3x3', trainable=trainable_variables)
......@@ -105,7 +105,7 @@ def reduction_a(net, k, l, m, n, trainable_variables=True, reuse=True):
net = tf.concat([tower_conv, tower_conv1_2, tower_pool], 3)
return net
def reduction_b(net, reuse=True, trainable_variables=True):
def reduction_b(net, reuse=None, trainable_variables=True):
with tf.variable_scope('Branch_0', reuse=reuse):
tower_conv = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv_1 = slim.conv2d(tower_conv, 384, 3, stride=2,
......@@ -211,28 +211,28 @@ def inception_resnet_v1(inputs, is_training=True,
end_points['Conv2d_4b_3x3'] = net
# 5 x Inception-resnet-A
net = slim.repeat(net, 5, block35, scale=0.17, trainable_variables=trainable_variables)
net = slim.repeat(net, 5, block35, scale=0.17, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_5a'] = net
# Reduction-A
with tf.variable_scope('Mixed_6a'):
net = reduction_a(net, 192, 192, 256, 384, trainable_variables=trainable_variables)
net = reduction_a(net, 192, 192, 256, 384, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_6a'] = net
# 10 x Inception-Resnet-B
net = slim.repeat(net, 10, block17, scale=0.10, trainable_variables=trainable_variables)
net = slim.repeat(net, 10, block17, scale=0.10, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_6b'] = net
# Reduction-B
with tf.variable_scope('Mixed_7a'):
net = reduction_b(net, trainable_variables=trainable_variables)
net = reduction_b(net, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_7a'] = net
# 5 x Inception-Resnet-C
net = slim.repeat(net, 5, block8, scale=0.20, trainable_variables=trainable_variables)
net = slim.repeat(net, 5, block8, scale=0.20, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_8a'] = net
net = block8(net, activation_fn=None, trainable_variables=trainable_variables)
net = block8(net, activation_fn=None, trainable_variables=trainable_variables, reuse=reuse)
end_points['Mixed_8b'] = net
with tf.variable_scope('Logits'):
......@@ -248,6 +248,6 @@ def inception_resnet_v1(inputs, is_training=True,
end_points['PreLogitsFlatten'] = net
net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None,
scope='Bottleneck', reuse=False, trainable=trainable_variables)
scope='Bottleneck', reuse=reuse, trainable=trainable_variables)
return net, end_points
......@@ -29,19 +29,19 @@ import tensorflow.contrib.slim as slim
# Inception-Renset-A
def block35(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, trainable_variables=True):
"""Builds the 35x35 resnet block."""
with tf.variable_scope(scope, 'Block35', [net], reuse=reuse):
with tf.variable_scope(scope, 'Block35', [net]):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 32, 1, scope='Conv2d_1x1', trainable=trainable_variables)
tower_conv = slim.conv2d(net, 32, 1, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 32, 3, scope='Conv2d_0b_3x3', trainable=trainable_variables)
tower_conv1_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 32, 3, scope='Conv2d_0b_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_2'):
tower_conv2_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv2_1 = slim.conv2d(tower_conv2_0, 48, 3, scope='Conv2d_0b_3x3', trainable=trainable_variables)
tower_conv2_2 = slim.conv2d(tower_conv2_1, 64, 3, scope='Conv2d_0c_3x3', trainable=trainable_variables)
tower_conv2_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv2_1 = slim.conv2d(tower_conv2_0, 48, 3, scope='Conv2d_0b_3x3', trainable=trainable_variables, reuse=reuse)
tower_conv2_2 = slim.conv2d(tower_conv2_1, 64, 3, scope='Conv2d_0c_3x3', trainable=trainable_variables, reuse=reuse)
mixed = tf.concat([tower_conv, tower_conv1_1, tower_conv2_2], 3)
up = slim.conv2d(mixed, net.get_shape()[3], 1, normalizer_fn=None,
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables)
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
net += scale * up
if activation_fn:
net = activation_fn(net)
......@@ -50,18 +50,18 @@ def block35(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, tr
# Inception-Renset-B
def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, trainable_variables=True):
"""Builds the 17x17 resnet block."""
with tf.variable_scope(scope, 'Block17', [net], reuse=reuse):
with tf.variable_scope(scope, 'Block17', [net]):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 192, 1, scope='Conv2d_1x1', trainable=trainable_variables)
tower_conv = slim.conv2d(net, 192, 1, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 128, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1_0 = slim.conv2d(net, 128, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 160, [1, 7],
scope='Conv2d_0b_1x7', trainable=trainable_variables)
scope='Conv2d_0b_1x7', trainable=trainable_variables, reuse=reuse)
tower_conv1_2 = slim.conv2d(tower_conv1_1, 192, [7, 1],
scope='Conv2d_0c_7x1', trainable=trainable_variables)
scope='Conv2d_0c_7x1', trainable=trainable_variables, reuse=reuse)
mixed = tf.concat([tower_conv, tower_conv1_2], 3)
up = slim.conv2d(mixed, net.get_shape()[3], 1, normalizer_fn=None,
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables)
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
net += scale * up
if activation_fn:
net = activation_fn(net)
......@@ -71,18 +71,18 @@ def block17(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, tr
# Inception-Resnet-C
def block8(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None, trainable_variables=True):
"""Builds the 8x8 resnet block."""
with tf.variable_scope(scope, 'Block8', [net], reuse=reuse):
with tf.variable_scope(scope, 'Block8', [net]):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 192, 1, scope='Conv2d_1x1', trainable=trainable_variables)
tower_conv = slim.conv2d(net, 192, 1, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 192, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1_0 = slim.conv2d(net, 192, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 224, [1, 3],
scope='Conv2d_0b_1x3', trainable=trainable_variables)
scope='Conv2d_0b_1x3', trainable=trainable_variables, reuse=reuse)
tower_conv1_2 = slim.conv2d(tower_conv1_1, 256, [3, 1],
scope='Conv2d_0c_3x1', trainable=trainable_variables)
scope='Conv2d_0c_3x1', trainable=trainable_variables, reuse=reuse)
mixed = tf.concat([tower_conv, tower_conv1_2], 3)
up = slim.conv2d(mixed, net.get_shape()[3], 1, normalizer_fn=None,
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables)
activation_fn=None, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
net += scale * up
if activation_fn:
net = activation_fn(net)
......@@ -147,14 +147,14 @@ def inception_resnet_v2(inputs,
# 149 x 149 x 32
net = slim.conv2d(inputs, 32, 3, stride=2, padding='VALID',
scope='Conv2d_1a_3x3', trainable=trainable_variables)
scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_1a_3x3'] = net
# 147 x 147 x 32
net = slim.conv2d(net, 32, 3, padding='VALID',
scope='Conv2d_2a_3x3', trainable=trainable_variables)
scope='Conv2d_2a_3x3', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_2a_3x3'] = net
# 147 x 147 x 64
net = slim.conv2d(net, 64, 3, scope='Conv2d_2b_3x3', trainable=trainable_variables)
net = slim.conv2d(net, 64, 3, scope='Conv2d_2b_3x3', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_2b_3x3'] = net
# 73 x 73 x 64
net = slim.max_pool2d(net, 3, stride=2, padding='VALID',
......@@ -162,11 +162,11 @@ def inception_resnet_v2(inputs,
end_points['MaxPool_3a_3x3'] = net
# 73 x 73 x 80
net = slim.conv2d(net, 80, 1, padding='VALID',
scope='Conv2d_3b_1x1', trainable=trainable_variables)
scope='Conv2d_3b_1x1', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_3b_1x1'] = net
# 71 x 71 x 192
net = slim.conv2d(net, 192, 3, padding='VALID',
scope='Conv2d_4a_3x3', trainable=trainable_variables)
scope='Conv2d_4a_3x3', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_4a_3x3'] = net
# 35 x 35 x 192
net = slim.max_pool2d(net, 3, stride=2, padding='VALID',
......@@ -176,63 +176,63 @@ def inception_resnet_v2(inputs,
# 35 x 35 x 320
with tf.variable_scope('Mixed_5b'):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 96, 1, scope='Conv2d_1x1', trainable=trainable_variables)
tower_conv = slim.conv2d(net, 96, 1, scope='Conv2d_1x1', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 48, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1_0 = slim.conv2d(net, 48, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 64, 5,
scope='Conv2d_0b_5x5', trainable=trainable_variables)
scope='Conv2d_0b_5x5', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_2'):
tower_conv2_0 = slim.conv2d(net, 64, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv2_0 = slim.conv2d(net, 64, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv2_1 = slim.conv2d(tower_conv2_0, 96, 3,
scope='Conv2d_0b_3x3', trainable=trainable_variables)
scope='Conv2d_0b_3x3', trainable=trainable_variables, reuse=reuse)
tower_conv2_2 = slim.conv2d(tower_conv2_1, 96, 3,
scope='Conv2d_0c_3x3', trainable=trainable_variables)
scope='Conv2d_0c_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_3'):
tower_pool = slim.avg_pool2d(net, 3, stride=1, padding='SAME',
scope='AvgPool_0a_3x3')
tower_pool_1 = slim.conv2d(tower_pool, 64, 1,
scope='Conv2d_0b_1x1', trainable=trainable_variables)
scope='Conv2d_0b_1x1', trainable=trainable_variables, reuse=reuse)
net = tf.concat([tower_conv, tower_conv1_1,
tower_conv2_2, tower_pool_1], 3)
end_points['Mixed_5b'] = net
net = slim.repeat(net, 10, block35, scale=0.17, trainable_variables=trainable_variables)
net = slim.repeat(net, 10, block35, scale=0.17, trainable_variables=trainable_variables, reuse=reuse)
# 17 x 17 x 1024
with tf.variable_scope('Mixed_6a'):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 384, 3, stride=2, padding='VALID',
scope='Conv2d_1a_3x3', trainable=trainable_variables)
scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1_0 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1_0, 256, 3,
scope='Conv2d_0b_3x3', trainable=trainable_variables)
scope='Conv2d_0b_3x3', trainable=trainable_variables, reuse=reuse)
tower_conv1_2 = slim.conv2d(tower_conv1_1, 384, 3,
stride=2, padding='VALID',
scope='Conv2d_1a_3x3', trainable=trainable_variables)
scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_2'):
tower_pool = slim.max_pool2d(net, 3, stride=2, padding='VALID',
scope='MaxPool_1a_3x3')
net = tf.concat([tower_conv, tower_conv1_2, tower_pool], 3)
end_points['Mixed_6a'] = net
net = slim.repeat(net, 20, block17, scale=0.10,trainable_variables=trainable_variables)
net = slim.repeat(net, 20, block17, scale=0.10,trainable_variables=trainable_variables, reuse=reuse)
with tf.variable_scope('Mixed_7a'):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv_1 = slim.conv2d(tower_conv, 384, 3, stride=2,
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables)
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_1'):
tower_conv1 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv1 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv1_1 = slim.conv2d(tower_conv1, 288, 3, stride=2,
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables)
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_2'):
tower_conv2 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables)
tower_conv2 = slim.conv2d(net, 256, 1, scope='Conv2d_0a_1x1', trainable=trainable_variables, reuse=reuse)
tower_conv2_1 = slim.conv2d(tower_conv2, 288, 3,
scope='Conv2d_0b_3x3', trainable=trainable_variables)
scope='Conv2d_0b_3x3', trainable=trainable_variables, reuse=reuse)
tower_conv2_2 = slim.conv2d(tower_conv2_1, 320, 3, stride=2,
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables)
padding='VALID', scope='Conv2d_1a_3x3', trainable=trainable_variables, reuse=reuse)
with tf.variable_scope('Branch_3'):
tower_pool = slim.max_pool2d(net, 3, stride=2, padding='VALID',
scope='MaxPool_1a_3x3')
......@@ -241,10 +241,10 @@ def inception_resnet_v2(inputs,
end_points['Mixed_7a'] = net
net = slim.repeat(net, 9, block8, scale=0.20,trainable_variables=trainable_variables)
net = block8(net, activation_fn=None,trainable_variables=trainable_variables)
net = slim.repeat(net, 9, block8, scale=0.20,trainable_variables=trainable_variables, reuse=reuse)
net = block8(net, activation_fn=None,trainable_variables=trainable_variables, reuse=reuse)
net = slim.conv2d(net, 1536, 1, scope='Conv2d_7b_1x1', trainable=trainable_variables)
net = slim.conv2d(net, 1536, 1, scope='Conv2d_7b_1x1', trainable=trainable_variables, reuse=reuse)
end_points['Conv2d_7b_1x1'] = net
with tf.variable_scope('Logits'):
......@@ -260,7 +260,7 @@ def inception_resnet_v2(inputs,
end_points['PreLogitsFlatten'] = net
net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None,
scope='Bottleneck', reuse=False, trainable=trainable_variables)
scope='Bottleneck', reuse=reuse, trainable=trainable_variables)
end_points['Bottleneck'] = net
return net, end_points
......
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