Commit a9d0e6e8 authored by Neal Wu's avatar Neal Wu
Browse files

Converted slim models to TF 1.0 and fixed a few issues

parent f21c4278
...@@ -232,11 +232,9 @@ def _gather_clone_loss(clone, num_clones, regularization_losses): ...@@ -232,11 +232,9 @@ def _gather_clone_loss(clone, num_clones, regularization_losses):
sum_loss = tf.add_n(all_losses) sum_loss = tf.add_n(all_losses)
# Add the summaries out of the clone device block. # Add the summaries out of the clone device block.
if clone_loss is not None: if clone_loss is not None:
tf.scalar_summary(clone.scope + '/clone_loss', clone_loss, tf.summary.scalar('clone_loss', clone_loss)
name='clone_loss')
if regularization_loss is not None: if regularization_loss is not None:
tf.scalar_summary('regularization_loss', regularization_loss, tf.summary.scalar('regularization_loss', regularization_loss)
name='regularization_loss')
return sum_loss return sum_loss
...@@ -404,12 +402,11 @@ def deploy(config, ...@@ -404,12 +402,11 @@ def deploy(config,
if total_loss is not None: if total_loss is not None:
# Add total_loss to summary. # Add total_loss to summary.
summaries.add(tf.scalar_summary('total_loss', total_loss, summaries.add(tf.summary.scalar('total_loss', total_loss))
name='total_loss'))
if summaries: if summaries:
# Merge all summaries together. # Merge all summaries together.
summary_op = tf.merge_summary(list(summaries), name='summary_op') summary_op = tf.summary.merge(list(summaries), name='summary_op')
else: else:
summary_op = None summary_op = None
...@@ -467,9 +464,9 @@ def _add_gradients_summaries(grads_and_vars): ...@@ -467,9 +464,9 @@ def _add_gradients_summaries(grads_and_vars):
grad_values = grad.values grad_values = grad.values
else: else:
grad_values = grad grad_values = grad
summaries.append(tf.histogram_summary(var.op.name + ':gradient', summaries.append(tf.summary.histogram(var.op.name + ':gradient',
grad_values)) grad_values))
summaries.append(tf.histogram_summary(var.op.name + ':gradient_norm', summaries.append(tf.summary.histogram(var.op.name + ':gradient_norm',
tf.global_norm([grad_values]))) tf.global_norm([grad_values])))
else: else:
tf.logging.info('Var %s has no gradient', var.op.name) tf.logging.info('Var %s has no gradient', var.op.name)
......
...@@ -160,7 +160,7 @@ def main(_): ...@@ -160,7 +160,7 @@ def main(_):
# Print the summaries to screen. # Print the summaries to screen.
for name, value in names_to_values.iteritems(): for name, value in names_to_values.iteritems():
summary_name = 'eval/%s' % name summary_name = 'eval/%s' % name
op = tf.scalar_summary(summary_name, value, collections=[]) op = tf.summary.scalar(summary_name, value, collections=[])
op = tf.Print(op, [value], summary_name) op = tf.Print(op, [value], summary_name)
tf.add_to_collection(tf.GraphKeys.SUMMARIES, op) tf.add_to_collection(tf.GraphKeys.SUMMARIES, op)
......
...@@ -113,7 +113,7 @@ def alexnet_v2(inputs, ...@@ -113,7 +113,7 @@ def alexnet_v2(inputs,
net = slim.conv2d(net, num_classes, [1, 1], net = slim.conv2d(net, num_classes, [1, 1],
activation_fn=None, activation_fn=None,
normalizer_fn=None, normalizer_fn=None,
biases_initializer=tf.zeros_initializer, biases_initializer=tf.zeros_initializer(),
scope='fc8') scope='fc8')
# Convert end_points_collection into a end_point dict. # Convert end_points_collection into a end_point dict.
......
...@@ -77,7 +77,7 @@ def cifarnet(images, num_classes=10, is_training=False, ...@@ -77,7 +77,7 @@ def cifarnet(images, num_classes=10, is_training=False,
net = slim.fully_connected(net, 192, scope='fc4') net = slim.fully_connected(net, 192, scope='fc4')
end_points['fc4'] = net end_points['fc4'] = net
logits = slim.fully_connected(net, num_classes, logits = slim.fully_connected(net, num_classes,
biases_initializer=tf.zeros_initializer, biases_initializer=tf.zeros_initializer(),
weights_initializer=trunc_normal(1/192.0), weights_initializer=trunc_normal(1/192.0),
weights_regularizer=None, weights_regularizer=None,
activation_fn=None, activation_fn=None,
......
...@@ -93,7 +93,7 @@ def inception_v1_base(inputs, ...@@ -93,7 +93,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 32, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 32, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -110,7 +110,7 @@ def inception_v1_base(inputs, ...@@ -110,7 +110,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -132,7 +132,7 @@ def inception_v1_base(inputs, ...@@ -132,7 +132,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -149,7 +149,7 @@ def inception_v1_base(inputs, ...@@ -149,7 +149,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -166,7 +166,7 @@ def inception_v1_base(inputs, ...@@ -166,7 +166,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -183,7 +183,7 @@ def inception_v1_base(inputs, ...@@ -183,7 +183,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 64, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -200,7 +200,7 @@ def inception_v1_base(inputs, ...@@ -200,7 +200,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -222,7 +222,7 @@ def inception_v1_base(inputs, ...@@ -222,7 +222,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
...@@ -239,7 +239,7 @@ def inception_v1_base(inputs, ...@@ -239,7 +239,7 @@ def inception_v1_base(inputs,
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3') branch_3 = slim.max_pool2d(net, [3, 3], scope='MaxPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if final_endpoint == end_point: return net, end_points if final_endpoint == end_point: return net, end_points
raise ValueError('Unknown final endpoint %s' % final_endpoint) raise ValueError('Unknown final endpoint %s' % final_endpoint)
......
...@@ -145,7 +145,7 @@ def inception_v2_base(inputs, ...@@ -145,7 +145,7 @@ def inception_v2_base(inputs,
branch_3, depth(32), [1, 1], branch_3, depth(32), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 28 x 28 x 256 # 28 x 28 x 256
...@@ -175,7 +175,7 @@ def inception_v2_base(inputs, ...@@ -175,7 +175,7 @@ def inception_v2_base(inputs,
branch_3, depth(64), [1, 1], branch_3, depth(64), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 28 x 28 x 320 # 28 x 28 x 320
...@@ -200,7 +200,7 @@ def inception_v2_base(inputs, ...@@ -200,7 +200,7 @@ def inception_v2_base(inputs,
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d( branch_2 = slim.max_pool2d(
net, [3, 3], stride=2, scope='MaxPool_1a_3x3') net, [3, 3], stride=2, scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1, branch_2]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 14 x 14 x 576 # 14 x 14 x 576
...@@ -230,7 +230,7 @@ def inception_v2_base(inputs, ...@@ -230,7 +230,7 @@ def inception_v2_base(inputs,
branch_3, depth(128), [1, 1], branch_3, depth(128), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 14 x 14 x 576 # 14 x 14 x 576
...@@ -260,7 +260,7 @@ def inception_v2_base(inputs, ...@@ -260,7 +260,7 @@ def inception_v2_base(inputs,
branch_3, depth(128), [1, 1], branch_3, depth(128), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 14 x 14 x 576 # 14 x 14 x 576
...@@ -290,7 +290,7 @@ def inception_v2_base(inputs, ...@@ -290,7 +290,7 @@ def inception_v2_base(inputs,
branch_3, depth(96), [1, 1], branch_3, depth(96), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -321,7 +321,7 @@ def inception_v2_base(inputs, ...@@ -321,7 +321,7 @@ def inception_v2_base(inputs,
branch_3, depth(96), [1, 1], branch_3, depth(96), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 14 x 14 x 576 # 14 x 14 x 576
...@@ -346,7 +346,7 @@ def inception_v2_base(inputs, ...@@ -346,7 +346,7 @@ def inception_v2_base(inputs,
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, branch_2 = slim.max_pool2d(net, [3, 3], stride=2,
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1, branch_2]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# 7 x 7 x 1024 # 7 x 7 x 1024
...@@ -376,7 +376,7 @@ def inception_v2_base(inputs, ...@@ -376,7 +376,7 @@ def inception_v2_base(inputs,
branch_3, depth(128), [1, 1], branch_3, depth(128), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -407,7 +407,7 @@ def inception_v2_base(inputs, ...@@ -407,7 +407,7 @@ def inception_v2_base(inputs,
branch_3, depth(128), [1, 1], branch_3, depth(128), [1, 1],
weights_initializer=trunc_normal(0.1), weights_initializer=trunc_normal(0.1),
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
raise ValueError('Unknown final endpoint %s' % final_endpoint) raise ValueError('Unknown final endpoint %s' % final_endpoint)
......
...@@ -158,7 +158,7 @@ def inception_v3_base(inputs, ...@@ -158,7 +158,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(32), [1, 1], branch_3 = slim.conv2d(branch_3, depth(32), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -182,7 +182,7 @@ def inception_v3_base(inputs, ...@@ -182,7 +182,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(64), [1, 1], branch_3 = slim.conv2d(branch_3, depth(64), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -205,7 +205,7 @@ def inception_v3_base(inputs, ...@@ -205,7 +205,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(64), [1, 1], branch_3 = slim.conv2d(branch_3, depth(64), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -224,7 +224,7 @@ def inception_v3_base(inputs, ...@@ -224,7 +224,7 @@ def inception_v3_base(inputs,
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1, branch_2]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -253,7 +253,7 @@ def inception_v3_base(inputs, ...@@ -253,7 +253,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1], branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -282,7 +282,7 @@ def inception_v3_base(inputs, ...@@ -282,7 +282,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1], branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# mixed_6: 17 x 17 x 768. # mixed_6: 17 x 17 x 768.
...@@ -310,7 +310,7 @@ def inception_v3_base(inputs, ...@@ -310,7 +310,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1], branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -339,7 +339,7 @@ def inception_v3_base(inputs, ...@@ -339,7 +339,7 @@ def inception_v3_base(inputs,
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, depth(192), [1, 1], branch_3 = slim.conv2d(branch_3, depth(192), [1, 1],
scope='Conv2d_0b_1x1') scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -361,7 +361,7 @@ def inception_v3_base(inputs, ...@@ -361,7 +361,7 @@ def inception_v3_base(inputs,
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', branch_2 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1, branch_2]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
# mixed_9: 8 x 8 x 2048. # mixed_9: 8 x 8 x 2048.
...@@ -371,21 +371,21 @@ def inception_v3_base(inputs, ...@@ -371,21 +371,21 @@ def inception_v3_base(inputs,
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1') branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
with tf.variable_scope('Branch_1'): with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1') branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
branch_1 = tf.concat(3, [ branch_1 = tf.concat(axis=3, values=[
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'), slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')]) slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0b_3x1')])
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1') branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d( branch_2 = slim.conv2d(
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3') branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
branch_2 = tf.concat(3, [ branch_2 = tf.concat(axis=3, values=[
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'), slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')]) slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d( branch_3 = slim.conv2d(
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1') branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
...@@ -396,21 +396,21 @@ def inception_v3_base(inputs, ...@@ -396,21 +396,21 @@ def inception_v3_base(inputs,
branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1') branch_0 = slim.conv2d(net, depth(320), [1, 1], scope='Conv2d_0a_1x1')
with tf.variable_scope('Branch_1'): with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1') branch_1 = slim.conv2d(net, depth(384), [1, 1], scope='Conv2d_0a_1x1')
branch_1 = tf.concat(3, [ branch_1 = tf.concat(axis=3, values=[
slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'), slim.conv2d(branch_1, depth(384), [1, 3], scope='Conv2d_0b_1x3'),
slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')]) slim.conv2d(branch_1, depth(384), [3, 1], scope='Conv2d_0c_3x1')])
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1') branch_2 = slim.conv2d(net, depth(448), [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d( branch_2 = slim.conv2d(
branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3') branch_2, depth(384), [3, 3], scope='Conv2d_0b_3x3')
branch_2 = tf.concat(3, [ branch_2 = tf.concat(axis=3, values=[
slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'), slim.conv2d(branch_2, depth(384), [1, 3], scope='Conv2d_0c_1x3'),
slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')]) slim.conv2d(branch_2, depth(384), [3, 1], scope='Conv2d_0d_3x1')])
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(net, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d( branch_3 = slim.conv2d(
branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1') branch_3, depth(192), [1, 1], scope='Conv2d_0b_1x1')
net = tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) net = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
end_points[end_point] = net end_points[end_point] = net
if end_point == final_endpoint: return net, end_points if end_point == final_endpoint: return net, end_points
raise ValueError('Unknown final endpoint %s' % final_endpoint) raise ValueError('Unknown final endpoint %s' % final_endpoint)
......
...@@ -49,7 +49,7 @@ def block_inception_a(inputs, scope=None, reuse=None): ...@@ -49,7 +49,7 @@ def block_inception_a(inputs, scope=None, reuse=None):
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 96, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 96, [1, 1], scope='Conv2d_0b_1x1')
return tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
def block_reduction_a(inputs, scope=None, reuse=None): def block_reduction_a(inputs, scope=None, reuse=None):
...@@ -69,7 +69,7 @@ def block_reduction_a(inputs, scope=None, reuse=None): ...@@ -69,7 +69,7 @@ def block_reduction_a(inputs, scope=None, reuse=None):
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID', branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
return tf.concat(3, [branch_0, branch_1, branch_2]) return tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
def block_inception_b(inputs, scope=None, reuse=None): def block_inception_b(inputs, scope=None, reuse=None):
...@@ -93,7 +93,7 @@ def block_inception_b(inputs, scope=None, reuse=None): ...@@ -93,7 +93,7 @@ def block_inception_b(inputs, scope=None, reuse=None):
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')
return tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
def block_reduction_b(inputs, scope=None, reuse=None): def block_reduction_b(inputs, scope=None, reuse=None):
...@@ -115,7 +115,7 @@ def block_reduction_b(inputs, scope=None, reuse=None): ...@@ -115,7 +115,7 @@ def block_reduction_b(inputs, scope=None, reuse=None):
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID', branch_2 = slim.max_pool2d(inputs, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
return tf.concat(3, [branch_0, branch_1, branch_2]) return tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
def block_inception_c(inputs, scope=None, reuse=None): def block_inception_c(inputs, scope=None, reuse=None):
...@@ -128,20 +128,20 @@ def block_inception_c(inputs, scope=None, reuse=None): ...@@ -128,20 +128,20 @@ def block_inception_c(inputs, scope=None, reuse=None):
branch_0 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1') branch_0 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1')
with tf.variable_scope('Branch_1'): with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_1 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')
branch_1 = tf.concat(3, [ branch_1 = tf.concat(axis=3, values=[
slim.conv2d(branch_1, 256, [1, 3], scope='Conv2d_0b_1x3'), slim.conv2d(branch_1, 256, [1, 3], scope='Conv2d_0b_1x3'),
slim.conv2d(branch_1, 256, [3, 1], scope='Conv2d_0c_3x1')]) slim.conv2d(branch_1, 256, [3, 1], scope='Conv2d_0c_3x1')])
with tf.variable_scope('Branch_2'): with tf.variable_scope('Branch_2'):
branch_2 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_2 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d(branch_2, 448, [3, 1], scope='Conv2d_0b_3x1') branch_2 = slim.conv2d(branch_2, 448, [3, 1], scope='Conv2d_0b_3x1')
branch_2 = slim.conv2d(branch_2, 512, [1, 3], scope='Conv2d_0c_1x3') branch_2 = slim.conv2d(branch_2, 512, [1, 3], scope='Conv2d_0c_1x3')
branch_2 = tf.concat(3, [ branch_2 = tf.concat(axis=3, values=[
slim.conv2d(branch_2, 256, [1, 3], scope='Conv2d_0d_1x3'), slim.conv2d(branch_2, 256, [1, 3], scope='Conv2d_0d_1x3'),
slim.conv2d(branch_2, 256, [3, 1], scope='Conv2d_0e_3x1')]) slim.conv2d(branch_2, 256, [3, 1], scope='Conv2d_0e_3x1')])
with tf.variable_scope('Branch_3'): with tf.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3') branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 256, [1, 1], scope='Conv2d_0b_1x1') branch_3 = slim.conv2d(branch_3, 256, [1, 1], scope='Conv2d_0b_1x1')
return tf.concat(3, [branch_0, branch_1, branch_2, branch_3]) return tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3])
def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
...@@ -192,7 +192,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -192,7 +192,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
with tf.variable_scope('Branch_1'): with tf.variable_scope('Branch_1'):
branch_1 = slim.conv2d(net, 96, [3, 3], stride=2, padding='VALID', branch_1 = slim.conv2d(net, 96, [3, 3], stride=2, padding='VALID',
scope='Conv2d_0a_3x3') scope='Conv2d_0a_3x3')
net = tf.concat(3, [branch_0, branch_1]) net = tf.concat(axis=3, values=[branch_0, branch_1])
if add_and_check_final('Mixed_3a', net): return net, end_points if add_and_check_final('Mixed_3a', net): return net, end_points
# 73 x 73 x 160 # 73 x 73 x 160
...@@ -207,7 +207,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -207,7 +207,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
branch_1 = slim.conv2d(branch_1, 64, [7, 1], scope='Conv2d_0c_7x1') branch_1 = slim.conv2d(branch_1, 64, [7, 1], scope='Conv2d_0c_7x1')
branch_1 = slim.conv2d(branch_1, 96, [3, 3], padding='VALID', branch_1 = slim.conv2d(branch_1, 96, [3, 3], padding='VALID',
scope='Conv2d_1a_3x3') scope='Conv2d_1a_3x3')
net = tf.concat(3, [branch_0, branch_1]) net = tf.concat(axis=3, values=[branch_0, branch_1])
if add_and_check_final('Mixed_4a', net): return net, end_points if add_and_check_final('Mixed_4a', net): return net, end_points
# 71 x 71 x 192 # 71 x 71 x 192
...@@ -218,7 +218,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -218,7 +218,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
with tf.variable_scope('Branch_1'): with tf.variable_scope('Branch_1'):
branch_1 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID', branch_1 = slim.max_pool2d(net, [3, 3], stride=2, padding='VALID',
scope='MaxPool_1a_3x3') scope='MaxPool_1a_3x3')
net = tf.concat(3, [branch_0, branch_1]) net = tf.concat(axis=3, values=[branch_0, branch_1])
if add_and_check_final('Mixed_5a', net): return net, end_points if add_and_check_final('Mixed_5a', net): return net, end_points
# 35 x 35 x 384 # 35 x 35 x 384
......
...@@ -41,7 +41,7 @@ def overfeat_arg_scope(weight_decay=0.0005): ...@@ -41,7 +41,7 @@ def overfeat_arg_scope(weight_decay=0.0005):
with slim.arg_scope([slim.conv2d, slim.fully_connected], with slim.arg_scope([slim.conv2d, slim.fully_connected],
activation_fn=tf.nn.relu, activation_fn=tf.nn.relu,
weights_regularizer=slim.l2_regularizer(weight_decay), weights_regularizer=slim.l2_regularizer(weight_decay),
biases_initializer=tf.zeros_initializer): biases_initializer=tf.zeros_initializer()):
with slim.arg_scope([slim.conv2d], padding='SAME'): with slim.arg_scope([slim.conv2d], padding='SAME'):
with slim.arg_scope([slim.max_pool2d], padding='VALID') as arg_sc: with slim.arg_scope([slim.max_pool2d], padding='VALID') as arg_sc:
return arg_sc return arg_sc
...@@ -107,7 +107,7 @@ def overfeat(inputs, ...@@ -107,7 +107,7 @@ def overfeat(inputs,
net = slim.conv2d(net, num_classes, [1, 1], net = slim.conv2d(net, num_classes, [1, 1],
activation_fn=None, activation_fn=None,
normalizer_fn=None, normalizer_fn=None,
biases_initializer=tf.zeros_initializer, biases_initializer=tf.zeros_initializer(),
scope='fc8') scope='fc8')
# Convert end_points_collection into a end_point dict. # Convert end_points_collection into a end_point dict.
end_points = slim.utils.convert_collection_to_dict(end_points_collection) end_points = slim.utils.convert_collection_to_dict(end_points_collection)
......
...@@ -234,7 +234,7 @@ def resnet_v2_50(inputs, ...@@ -234,7 +234,7 @@ def resnet_v2_50(inputs,
return resnet_v2(inputs, blocks, num_classes, is_training=is_training, return resnet_v2(inputs, blocks, num_classes, is_training=is_training,
global_pool=global_pool, output_stride=output_stride, global_pool=global_pool, output_stride=output_stride,
include_root_block=True, reuse=reuse, scope=scope) include_root_block=True, reuse=reuse, scope=scope)
resnet_v2_50.default_image_size = 224
def resnet_v2_101(inputs, def resnet_v2_101(inputs,
num_classes=None, num_classes=None,
...@@ -256,6 +256,7 @@ def resnet_v2_101(inputs, ...@@ -256,6 +256,7 @@ def resnet_v2_101(inputs,
return resnet_v2(inputs, blocks, num_classes, is_training=is_training, return resnet_v2(inputs, blocks, num_classes, is_training=is_training,
global_pool=global_pool, output_stride=output_stride, global_pool=global_pool, output_stride=output_stride,
include_root_block=True, reuse=reuse, scope=scope) include_root_block=True, reuse=reuse, scope=scope)
resnet_v2_101.default_image_size = 224
def resnet_v2_152(inputs, def resnet_v2_152(inputs,
...@@ -278,6 +279,7 @@ def resnet_v2_152(inputs, ...@@ -278,6 +279,7 @@ def resnet_v2_152(inputs,
return resnet_v2(inputs, blocks, num_classes, is_training=is_training, return resnet_v2(inputs, blocks, num_classes, is_training=is_training,
global_pool=global_pool, output_stride=output_stride, global_pool=global_pool, output_stride=output_stride,
include_root_block=True, reuse=reuse, scope=scope) include_root_block=True, reuse=reuse, scope=scope)
resnet_v2_152.default_image_size = 224
def resnet_v2_200(inputs, def resnet_v2_200(inputs,
...@@ -300,3 +302,4 @@ def resnet_v2_200(inputs, ...@@ -300,3 +302,4 @@ def resnet_v2_200(inputs,
return resnet_v2(inputs, blocks, num_classes, is_training=is_training, return resnet_v2(inputs, blocks, num_classes, is_training=is_training,
global_pool=global_pool, output_stride=output_stride, global_pool=global_pool, output_stride=output_stride,
include_root_block=True, reuse=reuse, scope=scope) include_root_block=True, reuse=reuse, scope=scope)
resnet_v2_200.default_image_size = 224
...@@ -58,7 +58,7 @@ def vgg_arg_scope(weight_decay=0.0005): ...@@ -58,7 +58,7 @@ def vgg_arg_scope(weight_decay=0.0005):
with slim.arg_scope([slim.conv2d, slim.fully_connected], with slim.arg_scope([slim.conv2d, slim.fully_connected],
activation_fn=tf.nn.relu, activation_fn=tf.nn.relu,
weights_regularizer=slim.l2_regularizer(weight_decay), weights_regularizer=slim.l2_regularizer(weight_decay),
biases_initializer=tf.zeros_initializer): biases_initializer=tf.zeros_initializer()):
with slim.arg_scope([slim.conv2d], padding='SAME') as arg_sc: with slim.arg_scope([slim.conv2d], padding='SAME') as arg_sc:
return arg_sc return arg_sc
......
...@@ -45,7 +45,7 @@ def preprocess_for_train(image, ...@@ -45,7 +45,7 @@ def preprocess_for_train(image,
Returns: Returns:
A preprocessed image. A preprocessed image.
""" """
tf.image_summary('image', tf.expand_dims(image, 0)) tf.summary.image('image', tf.expand_dims(image, 0))
# Transform the image to floats. # Transform the image to floats.
image = tf.to_float(image) image = tf.to_float(image)
...@@ -58,7 +58,7 @@ def preprocess_for_train(image, ...@@ -58,7 +58,7 @@ def preprocess_for_train(image,
# Randomly flip the image horizontally. # Randomly flip the image horizontally.
distorted_image = tf.image.random_flip_left_right(distorted_image) distorted_image = tf.image.random_flip_left_right(distorted_image)
tf.image_summary('distorted_image', tf.expand_dims(distorted_image, 0)) tf.summary.image('distorted_image', tf.expand_dims(distorted_image, 0))
# Because these operations are not commutative, consider randomizing # Because these operations are not commutative, consider randomizing
# the order their operation. # the order their operation.
...@@ -67,7 +67,7 @@ def preprocess_for_train(image, ...@@ -67,7 +67,7 @@ def preprocess_for_train(image,
distorted_image = tf.image.random_contrast(distorted_image, distorted_image = tf.image.random_contrast(distorted_image,
lower=0.2, upper=1.8) lower=0.2, upper=1.8)
# Subtract off the mean and divide by the variance of the pixels. # Subtract off the mean and divide by the variance of the pixels.
return tf.image.per_image_whitening(distorted_image) return tf.image.per_image_standardization(distorted_image)
def preprocess_for_eval(image, output_height, output_width): def preprocess_for_eval(image, output_height, output_width):
...@@ -81,7 +81,7 @@ def preprocess_for_eval(image, output_height, output_width): ...@@ -81,7 +81,7 @@ def preprocess_for_eval(image, output_height, output_width):
Returns: Returns:
A preprocessed image. A preprocessed image.
""" """
tf.image_summary('image', tf.expand_dims(image, 0)) tf.summary.image('image', tf.expand_dims(image, 0))
# Transform the image to floats. # Transform the image to floats.
image = tf.to_float(image) image = tf.to_float(image)
...@@ -89,10 +89,10 @@ def preprocess_for_eval(image, output_height, output_width): ...@@ -89,10 +89,10 @@ def preprocess_for_eval(image, output_height, output_width):
resized_image = tf.image.resize_image_with_crop_or_pad(image, resized_image = tf.image.resize_image_with_crop_or_pad(image,
output_width, output_width,
output_height) output_height)
tf.image_summary('resized_image', tf.expand_dims(resized_image, 0)) tf.summary.image('resized_image', tf.expand_dims(resized_image, 0))
# Subtract off the mean and divide by the variance of the pixels. # Subtract off the mean and divide by the variance of the pixels.
return tf.image.per_image_whitening(resized_image) return tf.image.per_image_standardization(resized_image)
def preprocess_image(image, output_height, output_width, is_training=False): def preprocess_image(image, output_height, output_width, is_training=False):
......
...@@ -192,7 +192,7 @@ def preprocess_for_train(image, height, width, bbox, ...@@ -192,7 +192,7 @@ def preprocess_for_train(image, height, width, bbox,
# the coordinates are ordered [ymin, xmin, ymax, xmax]. # the coordinates are ordered [ymin, xmin, ymax, xmax].
image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0), image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0),
bbox) bbox)
tf.image_summary('image_with_bounding_boxes', image_with_box) tf.summary.image('image_with_bounding_boxes', image_with_box)
distorted_image, distorted_bbox = distorted_bounding_box_crop(image, bbox) distorted_image, distorted_bbox = distorted_bounding_box_crop(image, bbox)
# Restore the shape since the dynamic slice based upon the bbox_size loses # Restore the shape since the dynamic slice based upon the bbox_size loses
...@@ -200,7 +200,7 @@ def preprocess_for_train(image, height, width, bbox, ...@@ -200,7 +200,7 @@ def preprocess_for_train(image, height, width, bbox,
distorted_image.set_shape([None, None, 3]) distorted_image.set_shape([None, None, 3])
image_with_distorted_box = tf.image.draw_bounding_boxes( image_with_distorted_box = tf.image.draw_bounding_boxes(
tf.expand_dims(image, 0), distorted_bbox) tf.expand_dims(image, 0), distorted_bbox)
tf.image_summary('images_with_distorted_bounding_box', tf.summary.image('images_with_distorted_bounding_box',
image_with_distorted_box) image_with_distorted_box)
# This resizing operation may distort the images because the aspect # This resizing operation may distort the images because the aspect
...@@ -215,7 +215,7 @@ def preprocess_for_train(image, height, width, bbox, ...@@ -215,7 +215,7 @@ def preprocess_for_train(image, height, width, bbox,
lambda x, method: tf.image.resize_images(x, [height, width], method=method), lambda x, method: tf.image.resize_images(x, [height, width], method=method),
num_cases=num_resize_cases) num_cases=num_resize_cases)
tf.image_summary('cropped_resized_image', tf.summary.image('cropped_resized_image',
tf.expand_dims(distorted_image, 0)) tf.expand_dims(distorted_image, 0))
# Randomly flip the image horizontally. # Randomly flip the image horizontally.
...@@ -227,10 +227,10 @@ def preprocess_for_train(image, height, width, bbox, ...@@ -227,10 +227,10 @@ def preprocess_for_train(image, height, width, bbox,
lambda x, ordering: distort_color(x, ordering, fast_mode), lambda x, ordering: distort_color(x, ordering, fast_mode),
num_cases=4) num_cases=4)
tf.image_summary('final_distorted_image', tf.summary.image('final_distorted_image',
tf.expand_dims(distorted_image, 0)) tf.expand_dims(distorted_image, 0))
distorted_image = tf.sub(distorted_image, 0.5) distorted_image = tf.subtract(distorted_image, 0.5)
distorted_image = tf.mul(distorted_image, 2.0) distorted_image = tf.multiply(distorted_image, 2.0)
return distorted_image return distorted_image
...@@ -270,8 +270,8 @@ def preprocess_for_eval(image, height, width, ...@@ -270,8 +270,8 @@ def preprocess_for_eval(image, height, width,
image = tf.image.resize_bilinear(image, [height, width], image = tf.image.resize_bilinear(image, [height, width],
align_corners=False) align_corners=False)
image = tf.squeeze(image, [0]) image = tf.squeeze(image, [0])
image = tf.sub(image, 0.5) image = tf.subtract(image, 0.5)
image = tf.mul(image, 2.0) image = tf.multiply(image, 2.0)
return image return image
......
...@@ -39,6 +39,6 @@ def preprocess_image(image, output_height, output_width, is_training): ...@@ -39,6 +39,6 @@ def preprocess_image(image, output_height, output_width, is_training):
image = tf.to_float(image) image = tf.to_float(image)
image = tf.image.resize_image_with_crop_or_pad( image = tf.image.resize_image_with_crop_or_pad(
image, output_width, output_height) image, output_width, output_height)
image = tf.sub(image, 128.0) image = tf.subtract(image, 128.0)
image = tf.div(image, 128.0) image = tf.div(image, 128.0)
return image return image
...@@ -56,6 +56,9 @@ def get_preprocessing(name, is_training=False): ...@@ -56,6 +56,9 @@ def get_preprocessing(name, is_training=False):
'resnet_v1_50': vgg_preprocessing, 'resnet_v1_50': vgg_preprocessing,
'resnet_v1_101': vgg_preprocessing, 'resnet_v1_101': vgg_preprocessing,
'resnet_v1_152': vgg_preprocessing, 'resnet_v1_152': vgg_preprocessing,
'resnet_v2_50': vgg_preprocessing,
'resnet_v2_101': vgg_preprocessing,
'resnet_v2_152': vgg_preprocessing,
'vgg': vgg_preprocessing, 'vgg': vgg_preprocessing,
'vgg_a': vgg_preprocessing, 'vgg_a': vgg_preprocessing,
'vgg_16': vgg_preprocessing, 'vgg_16': vgg_preprocessing,
......
...@@ -73,7 +73,7 @@ def _crop(image, offset_height, offset_width, crop_height, crop_width): ...@@ -73,7 +73,7 @@ def _crop(image, offset_height, offset_width, crop_height, crop_width):
['Rank of image must be equal to 3.']) ['Rank of image must be equal to 3.'])
cropped_shape = control_flow_ops.with_dependencies( cropped_shape = control_flow_ops.with_dependencies(
[rank_assertion], [rank_assertion],
tf.pack([crop_height, crop_width, original_shape[2]])) tf.stack([crop_height, crop_width, original_shape[2]]))
size_assertion = tf.Assert( size_assertion = tf.Assert(
tf.logical_and( tf.logical_and(
...@@ -81,7 +81,7 @@ def _crop(image, offset_height, offset_width, crop_height, crop_width): ...@@ -81,7 +81,7 @@ def _crop(image, offset_height, offset_width, crop_height, crop_width):
tf.greater_equal(original_shape[1], crop_width)), tf.greater_equal(original_shape[1], crop_width)),
['Crop size greater than the image size.']) ['Crop size greater than the image size.'])
offsets = tf.to_int32(tf.pack([offset_height, offset_width, 0])) offsets = tf.to_int32(tf.stack([offset_height, offset_width, 0]))
# Use tf.slice instead of crop_to_bounding box as it accepts tensors to # Use tf.slice instead of crop_to_bounding box as it accepts tensors to
# define the crop size. # define the crop size.
...@@ -227,10 +227,10 @@ def _mean_image_subtraction(image, means): ...@@ -227,10 +227,10 @@ def _mean_image_subtraction(image, means):
if len(means) != num_channels: if len(means) != num_channels:
raise ValueError('len(means) must match the number of channels') raise ValueError('len(means) must match the number of channels')
channels = tf.split(2, num_channels, image) channels = tf.split(axis=2, num_or_size_splits=num_channels, value=image)
for i in range(num_channels): for i in range(num_channels):
channels[i] -= means[i] channels[i] -= means[i]
return tf.concat(2, channels) return tf.concat(axis=2, values=channels)
def _smallest_size_at_least(height, width, smallest_side): def _smallest_size_at_least(height, width, smallest_side):
......
...@@ -676,7 +676,7 @@ ...@@ -676,7 +676,7 @@
" total_loss = slim.losses.get_total_loss()\n", " total_loss = slim.losses.get_total_loss()\n",
"\n", "\n",
" # Create some summaries to visualize the training process:\n", " # Create some summaries to visualize the training process:\n",
" tf.scalar_summary('losses/Total Loss', total_loss)\n", " tf.summary.scalar('losses/Total Loss', total_loss)\n",
" \n", " \n",
" # Specify the optimizer and create the train op:\n", " # Specify the optimizer and create the train op:\n",
" optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n", " optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n",
...@@ -1015,7 +1015,7 @@ ...@@ -1015,7 +1015,7 @@
" total_loss = slim.losses.get_total_loss()\n", " total_loss = slim.losses.get_total_loss()\n",
"\n", "\n",
" # Create some summaries to visualize the training process:\n", " # Create some summaries to visualize the training process:\n",
" tf.scalar_summary('losses/Total Loss', total_loss)\n", " tf.summary.scalar('losses/Total Loss', total_loss)\n",
" \n", " \n",
" # Specify the optimizer and create the train op:\n", " # Specify the optimizer and create the train op:\n",
" optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n", " optimizer = tf.train.AdamOptimizer(learning_rate=0.01)\n",
......
...@@ -316,8 +316,8 @@ def _configure_optimizer(learning_rate): ...@@ -316,8 +316,8 @@ def _configure_optimizer(learning_rate):
def _add_variables_summaries(learning_rate): def _add_variables_summaries(learning_rate):
summaries = [] summaries = []
for variable in slim.get_model_variables(): for variable in slim.get_model_variables():
summaries.append(tf.histogram_summary(variable.op.name, variable)) summaries.append(tf.summary.histogram(variable.op.name, variable))
summaries.append(tf.scalar_summary('training/Learning Rate', learning_rate)) summaries.append(tf.summary.scalar('training/Learning Rate', learning_rate))
return summaries return summaries
...@@ -469,11 +469,11 @@ def main(_): ...@@ -469,11 +469,11 @@ def main(_):
# Specify the loss function # # Specify the loss function #
############################# #############################
if 'AuxLogits' in end_points: if 'AuxLogits' in end_points:
slim.losses.softmax_cross_entropy( tf.losses.softmax_cross_entropy(
end_points['AuxLogits'], labels, end_points['AuxLogits'], labels,
label_smoothing=FLAGS.label_smoothing, weight=0.4, scope='aux_loss') label_smoothing=FLAGS.label_smoothing, weights=0.4, scope='aux_loss')
slim.losses.softmax_cross_entropy( tf.losses.softmax_cross_entropy(
logits, labels, label_smoothing=FLAGS.label_smoothing, weight=1.0) tf.squeeze(logits), labels, label_smoothing=FLAGS.label_smoothing, weights=1.0)
return end_points return end_points
# Gather initial summaries. # Gather initial summaries.
...@@ -489,17 +489,17 @@ def main(_): ...@@ -489,17 +489,17 @@ def main(_):
end_points = clones[0].outputs end_points = clones[0].outputs
for end_point in end_points: for end_point in end_points:
x = end_points[end_point] x = end_points[end_point]
summaries.add(tf.histogram_summary('activations/' + end_point, x)) summaries.add(tf.summary.histogram('activations/' + end_point, x))
summaries.add(tf.scalar_summary('sparsity/' + end_point, summaries.add(tf.summary.scalar('sparsity/' + end_point,
tf.nn.zero_fraction(x))) tf.nn.zero_fraction(x)))
# Add summaries for losses. # Add summaries for losses.
for loss in tf.get_collection(tf.GraphKeys.LOSSES, first_clone_scope): for loss in tf.get_collection(tf.GraphKeys.LOSSES, first_clone_scope):
summaries.add(tf.scalar_summary('losses/%s' % loss.op.name, loss)) summaries.add(tf.summary.scalar('losses/%s' % loss.op.name, loss))
# Add summaries for variables. # Add summaries for variables.
for variable in slim.get_model_variables(): for variable in slim.get_model_variables():
summaries.add(tf.histogram_summary(variable.op.name, variable)) summaries.add(tf.summary.histogram(variable.op.name, variable))
################################# #################################
# Configure the moving averages # # Configure the moving averages #
...@@ -517,8 +517,7 @@ def main(_): ...@@ -517,8 +517,7 @@ def main(_):
with tf.device(deploy_config.optimizer_device()): with tf.device(deploy_config.optimizer_device()):
learning_rate = _configure_learning_rate(dataset.num_samples, global_step) learning_rate = _configure_learning_rate(dataset.num_samples, global_step)
optimizer = _configure_optimizer(learning_rate) optimizer = _configure_optimizer(learning_rate)
summaries.add(tf.scalar_summary('learning_rate', learning_rate, summaries.add(tf.summary.scalar('learning_rate', learning_rate))
name='learning_rate'))
if FLAGS.sync_replicas: if FLAGS.sync_replicas:
# If sync_replicas is enabled, the averaging will be done in the chief # If sync_replicas is enabled, the averaging will be done in the chief
...@@ -543,8 +542,7 @@ def main(_): ...@@ -543,8 +542,7 @@ def main(_):
optimizer, optimizer,
var_list=variables_to_train) var_list=variables_to_train)
# Add total_loss to summary. # Add total_loss to summary.
summaries.add(tf.scalar_summary('total_loss', total_loss, summaries.add(tf.summary.scalar('total_loss', total_loss))
name='total_loss'))
# Create gradient updates. # Create gradient updates.
grad_updates = optimizer.apply_gradients(clones_gradients, grad_updates = optimizer.apply_gradients(clones_gradients,
...@@ -561,7 +559,7 @@ def main(_): ...@@ -561,7 +559,7 @@ def main(_):
first_clone_scope)) first_clone_scope))
# Merge all summaries together. # Merge all summaries together.
summary_op = tf.merge_summary(list(summaries), name='summary_op') summary_op = tf.summary.merge(list(summaries), name='summary_op')
########################### ###########################
......
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