Commit 68a18b70 authored by Toby Boyd's avatar Toby Boyd Committed by GitHub
Browse files

Merge pull request #1 from tensorflow/master

update to tensorflow/model master
parents bc70271a 2c4fea8d
...@@ -125,7 +125,7 @@ def _add_to_tfrecord(data_filename, labels_filename, num_images, ...@@ -125,7 +125,7 @@ def _add_to_tfrecord(data_filename, labels_filename, num_images,
png_string = sess.run(encoded_png, feed_dict={image: images[j]}) png_string = sess.run(encoded_png, feed_dict={image: images[j]})
example = dataset_utils.image_to_tfexample( example = dataset_utils.image_to_tfexample(
png_string, 'png', _IMAGE_SIZE, _IMAGE_SIZE, labels[j]) png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
tfrecord_writer.write(example.SerializeToString()) tfrecord_writer.write(example.SerializeToString())
...@@ -165,7 +165,7 @@ def _download_dataset(dataset_dir): ...@@ -165,7 +165,7 @@ def _download_dataset(dataset_dir):
_progress) _progress)
print() print()
with tf.gfile.GFile(filepath) as f: with tf.gfile.GFile(filepath) as f:
size = f.Size() size = f.size()
print('Successfully downloaded', filename, size, 'bytes.') print('Successfully downloaded', filename, size, 'bytes.')
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
"""Provides data for the MNIST dataset. """Provides data for the MNIST dataset.
The dataset scripts used to create the dataset can be found at: The dataset scripts used to create the dataset can be found at:
tensorflow/models/slim/data/create_mnist_dataset.py tensorflow/models/slim/datasets/download_and_convert_mnist.py
""" """
from __future__ import absolute_import from __future__ import absolute_import
......
...@@ -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.scope + '/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
...@@ -306,7 +304,7 @@ def optimize_clones(clones, optimizer, ...@@ -306,7 +304,7 @@ def optimize_clones(clones, optimizer,
regularization_losses = None regularization_losses = None
# Compute the total_loss summing all the clones_losses. # Compute the total_loss summing all the clones_losses.
total_loss = tf.add_n(clones_losses, name='total_loss') total_loss = tf.add_n(clones_losses, name='total_loss')
# Sum the gradients accross clones. # Sum the gradients across clones.
grads_and_vars = _sum_clones_gradients(grads_and_vars) grads_and_vars = _sum_clones_gradients(grads_and_vars)
return total_loss, grads_and_vars return total_loss, grads_and_vars
...@@ -380,8 +378,8 @@ def deploy(config, ...@@ -380,8 +378,8 @@ def deploy(config,
update_ops.append(grad_updates) update_ops.append(grad_updates)
update_op = tf.group(*update_ops) update_op = tf.group(*update_ops)
train_op = control_flow_ops.with_dependencies([update_op], total_loss, with tf.control_dependencies([update_op]):
name='train_op') train_op = tf.identity(total_loss, name='train_op')
else: else:
clones_losses = [] clones_losses = []
regularization_losses = tf.get_collection( regularization_losses = tf.get_collection(
...@@ -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)
...@@ -666,7 +663,7 @@ class DeploymentConfig(object): ...@@ -666,7 +663,7 @@ class DeploymentConfig(object):
if op.device: if op.device:
return op.device return op.device
node_def = op if isinstance(op, tf.NodeDef) else op.node_def node_def = op if isinstance(op, tf.NodeDef) else op.node_def
if node_def.op == 'Variable': if node_def.op.startswith('Variable'):
t = self._task t = self._task
self._task = (self._task + 1) % self._tasks self._task = (self._task + 1) % self._tasks
d = '%s/task:%d' % (self._device, t) d = '%s/task:%d' % (self._device, t)
......
...@@ -153,14 +153,14 @@ def main(_): ...@@ -153,14 +153,14 @@ def main(_):
# Define the metrics: # Define the metrics:
names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({ names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
'Accuracy': slim.metrics.streaming_accuracy(predictions, labels), 'Accuracy': slim.metrics.streaming_accuracy(predictions, labels),
'Recall@5': slim.metrics.streaming_recall_at_k( 'Recall_5': slim.metrics.streaming_recall_at_k(
logits, labels, 5), logits, labels, 5),
}) })
# 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.items():
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)
...@@ -183,7 +183,7 @@ def main(_): ...@@ -183,7 +183,7 @@ def main(_):
checkpoint_path=checkpoint_path, checkpoint_path=checkpoint_path,
logdir=FLAGS.eval_dir, logdir=FLAGS.eval_dir,
num_evals=num_batches, num_evals=num_batches,
eval_op=names_to_updates.values(), eval_op=list(names_to_updates.values()),
variables_to_restore=variables_to_restore) variables_to_restore=variables_to_restore)
......
...@@ -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,
......
...@@ -171,7 +171,7 @@ def inception_resnet_v2(inputs, num_classes=1001, is_training=True, ...@@ -171,7 +171,7 @@ def inception_resnet_v2(inputs, num_classes=1001, is_training=True,
end_points['Mixed_5b'] = net end_points['Mixed_5b'] = net
net = slim.repeat(net, 10, block35, scale=0.17) net = slim.repeat(net, 10, block35, scale=0.17)
# 17 x 17 x 1024 # 17 x 17 x 1088
with tf.variable_scope('Mixed_6a'): with tf.variable_scope('Mixed_6a'):
with tf.variable_scope('Branch_0'): with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 384, 3, stride=2, padding='VALID', tower_conv = slim.conv2d(net, 384, 3, stride=2, padding='VALID',
...@@ -191,7 +191,7 @@ def inception_resnet_v2(inputs, num_classes=1001, is_training=True, ...@@ -191,7 +191,7 @@ def inception_resnet_v2(inputs, num_classes=1001, is_training=True,
end_points['Mixed_6a'] = net end_points['Mixed_6a'] = net
net = slim.repeat(net, 20, block17, scale=0.10) net = slim.repeat(net, 20, block17, scale=0.10)
# Auxillary tower # Auxiliary tower
with tf.variable_scope('AuxLogits'): with tf.variable_scope('AuxLogits'):
aux = slim.avg_pool2d(net, 5, stride=3, padding='VALID', aux = slim.avg_pool2d(net, 5, stride=3, padding='VALID',
scope='Conv2d_1a_3x3') scope='Conv2d_1a_3x3')
......
...@@ -65,9 +65,9 @@ class InceptionTest(tf.test.TestCase): ...@@ -65,9 +65,9 @@ class InceptionTest(tf.test.TestCase):
inception.inception_resnet_v2(inputs, num_classes) inception.inception_resnet_v2(inputs, num_classes)
with tf.variable_scope('on_gpu'), tf.device('/gpu:0'): with tf.variable_scope('on_gpu'), tf.device('/gpu:0'):
inception.inception_resnet_v2(inputs, num_classes) inception.inception_resnet_v2(inputs, num_classes)
for v in tf.get_collection(tf.GraphKeys.VARIABLES, scope='on_cpu'): for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='on_cpu'):
self.assertDeviceEqual(v.device, '/cpu:0') self.assertDeviceEqual(v.device, '/cpu:0')
for v in tf.get_collection(tf.GraphKeys.VARIABLES, scope='on_gpu'): for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='on_gpu'):
self.assertDeviceEqual(v.device, '/gpu:0') self.assertDeviceEqual(v.device, '/gpu:0')
def testHalfSizeImages(self): def testHalfSizeImages(self):
......
...@@ -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)
...@@ -270,7 +270,7 @@ def inception_v1(inputs, ...@@ -270,7 +270,7 @@ def inception_v1(inputs,
is_training: whether is training or not. is_training: whether is training or not.
dropout_keep_prob: the percentage of activation values that are retained. dropout_keep_prob: the percentage of activation values that are retained.
prediction_fn: a function to get predictions out of logits. prediction_fn: a function to get predictions out of logits.
spatial_squeeze: if True, logits is of shape is [B, C], if false logits is spatial_squeeze: if True, logits is of shape [B, C], if false logits is
of shape [B, 1, 1, C], where B is batch_size and C is number of classes. of shape [B, 1, 1, C], where B is batch_size and C is number of classes.
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
...@@ -289,7 +289,7 @@ def inception_v1(inputs, ...@@ -289,7 +289,7 @@ def inception_v1(inputs,
is_training=is_training): is_training=is_training):
net, end_points = inception_v1_base(inputs, scope=scope) net, end_points = inception_v1_base(inputs, scope=scope)
with tf.variable_scope('Logits'): with tf.variable_scope('Logits'):
net = slim.avg_pool2d(net, [7, 7], stride=1, scope='MaxPool_0a_7x7') net = slim.avg_pool2d(net, [7, 7], stride=1, scope='AvgPool_0a_7x7')
net = slim.dropout(net, net = slim.dropout(net,
dropout_keep_prob, scope='Dropout_0b') dropout_keep_prob, scope='Dropout_0b')
logits = slim.conv2d(net, num_classes, [1, 1], activation_fn=None, logits = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,
......
...@@ -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)
...@@ -443,7 +443,7 @@ def inception_v2(inputs, ...@@ -443,7 +443,7 @@ def inception_v2(inputs,
usage will be to set this value in (0, 1) to reduce the number of usage will be to set this value in (0, 1) to reduce the number of
parameters or computation cost of the model. parameters or computation cost of the model.
prediction_fn: a function to get predictions out of logits. prediction_fn: a function to get predictions out of logits.
spatial_squeeze: if True, logits is of shape is [B, C], if false logits is spatial_squeeze: if True, logits is of shape [B, C], if false logits is
of shape [B, 1, 1, C], where B is batch_size and C is number of classes. of shape [B, 1, 1, C], where B is batch_size and C is number of classes.
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
......
...@@ -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)
...@@ -453,7 +453,7 @@ def inception_v3(inputs, ...@@ -453,7 +453,7 @@ def inception_v3(inputs,
usage will be to set this value in (0, 1) to reduce the number of usage will be to set this value in (0, 1) to reduce the number of
parameters or computation cost of the model. parameters or computation cost of the model.
prediction_fn: a function to get predictions out of logits. prediction_fn: a function to get predictions out of logits.
spatial_squeeze: if True, logits is of shape is [B, C], if false logits is spatial_squeeze: if True, logits is of shape [B, C], if false logits is
of shape [B, 1, 1, C], where B is batch_size and C is number of classes. of shape [B, 1, 1, C], where B is batch_size and C is number of classes.
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
......
...@@ -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,12 +218,12 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -218,12 +218,12 @@ 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
# 4 x Inception-A blocks # 4 x Inception-A blocks
for idx in xrange(4): for idx in range(4):
block_scope = 'Mixed_5' + chr(ord('b') + idx) block_scope = 'Mixed_5' + chr(ord('b') + idx)
net = block_inception_a(net, block_scope) net = block_inception_a(net, block_scope)
if add_and_check_final(block_scope, net): return net, end_points if add_and_check_final(block_scope, net): return net, end_points
...@@ -235,7 +235,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -235,7 +235,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
# 17 x 17 x 1024 # 17 x 17 x 1024
# 7 x Inception-B blocks # 7 x Inception-B blocks
for idx in xrange(7): for idx in range(7):
block_scope = 'Mixed_6' + chr(ord('b') + idx) block_scope = 'Mixed_6' + chr(ord('b') + idx)
net = block_inception_b(net, block_scope) net = block_inception_b(net, block_scope)
if add_and_check_final(block_scope, net): return net, end_points if add_and_check_final(block_scope, net): return net, end_points
...@@ -247,7 +247,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None): ...@@ -247,7 +247,7 @@ def inception_v4_base(inputs, final_endpoint='Mixed_7d', scope=None):
# 8 x 8 x 1536 # 8 x 8 x 1536
# 3 x Inception-C blocks # 3 x Inception-C blocks
for idx in xrange(3): for idx in range(3):
block_scope = 'Mixed_7' + chr(ord('b') + idx) block_scope = 'Mixed_7' + chr(ord('b') + idx)
net = block_inception_c(net, block_scope) net = block_inception_c(net, block_scope)
if add_and_check_final(block_scope, net): return net, end_points if add_and_check_final(block_scope, net): return net, end_points
...@@ -269,7 +269,7 @@ def inception_v4(inputs, num_classes=1001, is_training=True, ...@@ -269,7 +269,7 @@ def inception_v4(inputs, num_classes=1001, is_training=True,
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
scope: Optional variable_scope. scope: Optional variable_scope.
create_aux_logits: Whether to include the auxilliary logits. create_aux_logits: Whether to include the auxiliary logits.
Returns: Returns:
logits: the logits outputs of the model. logits: the logits outputs of the model.
......
...@@ -146,9 +146,9 @@ class InceptionTest(tf.test.TestCase): ...@@ -146,9 +146,9 @@ class InceptionTest(tf.test.TestCase):
inception.inception_v4(inputs, num_classes) inception.inception_v4(inputs, num_classes)
with tf.variable_scope('on_gpu'), tf.device('/gpu:0'): with tf.variable_scope('on_gpu'), tf.device('/gpu:0'):
inception.inception_v4(inputs, num_classes) inception.inception_v4(inputs, num_classes)
for v in tf.get_collection(tf.GraphKeys.VARIABLES, scope='on_cpu'): for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='on_cpu'):
self.assertDeviceEqual(v.device, '/cpu:0') self.assertDeviceEqual(v.device, '/cpu:0')
for v in tf.get_collection(tf.GraphKeys.VARIABLES, scope='on_gpu'): for v in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='on_gpu'):
self.assertDeviceEqual(v.device, '/gpu:0') self.assertDeviceEqual(v.device, '/gpu:0')
def testHalfSizeImages(self): def testHalfSizeImages(self):
......
...@@ -97,10 +97,10 @@ def get_network_fn(name, num_classes, weight_decay=0.0, is_training=False): ...@@ -97,10 +97,10 @@ def get_network_fn(name, num_classes, weight_decay=0.0, is_training=False):
""" """
if name not in networks_map: if name not in networks_map:
raise ValueError('Name of network unknown %s' % name) raise ValueError('Name of network unknown %s' % name)
arg_scope = arg_scopes_map[name](weight_decay=weight_decay)
func = networks_map[name] func = networks_map[name]
@functools.wraps(func) @functools.wraps(func)
def network_fn(images): def network_fn(images):
arg_scope = arg_scopes_map[name](weight_decay=weight_decay)
with slim.arg_scope(arg_scope): with slim.arg_scope(arg_scope):
return func(images, num_classes, is_training=is_training) return func(images, num_classes, is_training=is_training)
if hasattr(func, 'default_image_size'): if hasattr(func, 'default_image_size'):
......
...@@ -19,11 +19,12 @@ from __future__ import absolute_import ...@@ -19,11 +19,12 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import tensorflow as tf import tensorflow as tf
from nets import nets_factory from nets import nets_factory
slim = tf.contrib.slim
class NetworksTest(tf.test.TestCase): class NetworksTest(tf.test.TestCase):
...@@ -42,5 +43,19 @@ class NetworksTest(tf.test.TestCase): ...@@ -42,5 +43,19 @@ class NetworksTest(tf.test.TestCase):
self.assertEqual(logits.get_shape().as_list()[0], batch_size) self.assertEqual(logits.get_shape().as_list()[0], batch_size)
self.assertEqual(logits.get_shape().as_list()[-1], num_classes) self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
def testGetNetworkFnArgScope(self):
batch_size = 5
num_classes = 10
net = 'cifarnet'
with self.test_session(use_gpu=True):
net_fn = nets_factory.get_network_fn(net, num_classes)
image_size = getattr(net_fn, 'default_image_size', 224)
with slim.arg_scope([slim.model_variable, slim.variable],
device='/CPU:0'):
inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
net_fn(inputs)
weights = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, 'CifarNet/conv1')[0]
self.assertDeviceEqual('/CPU:0', weights.device)
if __name__ == '__main__': if __name__ == '__main__':
tf.test.main() tf.test.main()
...@@ -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)
......
...@@ -119,6 +119,7 @@ def resnet_v1(inputs, ...@@ -119,6 +119,7 @@ def resnet_v1(inputs,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
include_root_block=True, include_root_block=True,
spatial_squeeze=True,
reuse=None, reuse=None,
scope=None): scope=None):
"""Generator for v1 ResNet models. """Generator for v1 ResNet models.
...@@ -158,6 +159,8 @@ def resnet_v1(inputs, ...@@ -158,6 +159,8 @@ def resnet_v1(inputs,
ratio of input to output spatial resolution. ratio of input to output spatial resolution.
include_root_block: If True, include the initial convolution followed by include_root_block: If True, include the initial convolution followed by
max-pooling, if False excludes it. max-pooling, if False excludes it.
spatial_squeeze: if True, logits is of shape [B, C], if false logits is
of shape [B, 1, 1, C], where B is batch_size and C is number of classes.
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
scope: Optional variable_scope. scope: Optional variable_scope.
...@@ -197,11 +200,15 @@ def resnet_v1(inputs, ...@@ -197,11 +200,15 @@ def resnet_v1(inputs,
if num_classes is not None: if num_classes is not None:
net = slim.conv2d(net, num_classes, [1, 1], activation_fn=None, net = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,
normalizer_fn=None, scope='logits') normalizer_fn=None, scope='logits')
if spatial_squeeze:
logits = tf.squeeze(net, [1, 2], name='SpatialSqueeze')
else:
logits = net
# Convert end_points_collection into a dictionary of end_points. # Convert end_points_collection into a dictionary of end_points.
end_points = slim.utils.convert_collection_to_dict(end_points_collection) end_points = slim.utils.convert_collection_to_dict(end_points_collection)
if num_classes is not None: if num_classes is not None:
end_points['predictions'] = slim.softmax(net, scope='predictions') end_points['predictions'] = slim.softmax(logits, scope='predictions')
return net, end_points return logits, end_points
resnet_v1.default_image_size = 224 resnet_v1.default_image_size = 224
...@@ -210,6 +217,7 @@ def resnet_v1_50(inputs, ...@@ -210,6 +217,7 @@ def resnet_v1_50(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v1_50'): scope='resnet_v1_50'):
"""ResNet-50 model of [1]. See resnet_v1() for arg and return description.""" """ResNet-50 model of [1]. See resnet_v1() for arg and return description."""
...@@ -225,7 +233,9 @@ def resnet_v1_50(inputs, ...@@ -225,7 +233,9 @@ def resnet_v1_50(inputs,
] ]
return resnet_v1(inputs, blocks, num_classes, is_training, return resnet_v1(inputs, blocks, num_classes, 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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v1_50.default_image_size = resnet_v1.default_image_size
def resnet_v1_101(inputs, def resnet_v1_101(inputs,
...@@ -233,6 +243,7 @@ def resnet_v1_101(inputs, ...@@ -233,6 +243,7 @@ def resnet_v1_101(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v1_101'): scope='resnet_v1_101'):
"""ResNet-101 model of [1]. See resnet_v1() for arg and return description.""" """ResNet-101 model of [1]. See resnet_v1() for arg and return description."""
...@@ -248,7 +259,9 @@ def resnet_v1_101(inputs, ...@@ -248,7 +259,9 @@ def resnet_v1_101(inputs,
] ]
return resnet_v1(inputs, blocks, num_classes, is_training, return resnet_v1(inputs, blocks, num_classes, 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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v1_101.default_image_size = resnet_v1.default_image_size
def resnet_v1_152(inputs, def resnet_v1_152(inputs,
...@@ -256,6 +269,7 @@ def resnet_v1_152(inputs, ...@@ -256,6 +269,7 @@ def resnet_v1_152(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v1_152'): scope='resnet_v1_152'):
"""ResNet-152 model of [1]. See resnet_v1() for arg and return description.""" """ResNet-152 model of [1]. See resnet_v1() for arg and return description."""
...@@ -270,7 +284,9 @@ def resnet_v1_152(inputs, ...@@ -270,7 +284,9 @@ def resnet_v1_152(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
return resnet_v1(inputs, blocks, num_classes, is_training, return resnet_v1(inputs, blocks, num_classes, 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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v1_152.default_image_size = resnet_v1.default_image_size
def resnet_v1_200(inputs, def resnet_v1_200(inputs,
...@@ -278,6 +294,7 @@ def resnet_v1_200(inputs, ...@@ -278,6 +294,7 @@ def resnet_v1_200(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v1_200'): scope='resnet_v1_200'):
"""ResNet-200 model of [2]. See resnet_v1() for arg and return description.""" """ResNet-200 model of [2]. See resnet_v1() for arg and return description."""
...@@ -292,4 +309,6 @@ def resnet_v1_200(inputs, ...@@ -292,4 +309,6 @@ def resnet_v1_200(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
return resnet_v1(inputs, blocks, num_classes, is_training, return resnet_v1(inputs, blocks, num_classes, 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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v1_200.default_image_size = resnet_v1.default_image_size
...@@ -25,8 +25,6 @@ introduced by: ...@@ -25,8 +25,6 @@ introduced by:
The key difference of the full preactivation 'v2' variant compared to the The key difference of the full preactivation 'v2' variant compared to the
'v1' variant in [1] is the use of batch normalization before every weight layer. 'v1' variant in [1] is the use of batch normalization before every weight layer.
Another difference is that 'v2' ResNets do not include an activation function in
the main pathway. Also see [2; Fig. 4e].
Typical use: Typical use:
...@@ -117,6 +115,7 @@ def resnet_v2(inputs, ...@@ -117,6 +115,7 @@ def resnet_v2(inputs,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
include_root_block=True, include_root_block=True,
spatial_squeeze=True,
reuse=None, reuse=None,
scope=None): scope=None):
"""Generator for v2 (preactivation) ResNet models. """Generator for v2 (preactivation) ResNet models.
...@@ -157,6 +156,8 @@ def resnet_v2(inputs, ...@@ -157,6 +156,8 @@ def resnet_v2(inputs,
include_root_block: If True, include the initial convolution followed by include_root_block: If True, include the initial convolution followed by
max-pooling, if False excludes it. If excluded, `inputs` should be the max-pooling, if False excludes it. If excluded, `inputs` should be the
results of an activation-less convolution. results of an activation-less convolution.
spatial_squeeze: if True, logits is of shape [B, C], if false logits is
of shape [B, 1, 1, C], where B is batch_size and C is number of classes.
reuse: whether or not the network and its variables should be reused. To be reuse: whether or not the network and its variables should be reused. To be
able to reuse 'scope' must be given. able to reuse 'scope' must be given.
scope: Optional variable_scope. scope: Optional variable_scope.
...@@ -206,11 +207,15 @@ def resnet_v2(inputs, ...@@ -206,11 +207,15 @@ def resnet_v2(inputs,
if num_classes is not None: if num_classes is not None:
net = slim.conv2d(net, num_classes, [1, 1], activation_fn=None, net = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,
normalizer_fn=None, scope='logits') normalizer_fn=None, scope='logits')
if spatial_squeeze:
logits = tf.squeeze(net, [1, 2], name='SpatialSqueeze')
else:
logits = net
# Convert end_points_collection into a dictionary of end_points. # Convert end_points_collection into a dictionary of end_points.
end_points = slim.utils.convert_collection_to_dict(end_points_collection) end_points = slim.utils.convert_collection_to_dict(end_points_collection)
if num_classes is not None: if num_classes is not None:
end_points['predictions'] = slim.softmax(net, scope='predictions') end_points['predictions'] = slim.softmax(logits, scope='predictions')
return net, end_points return logits, end_points
resnet_v2.default_image_size = 224 resnet_v2.default_image_size = 224
...@@ -219,6 +224,7 @@ def resnet_v2_50(inputs, ...@@ -219,6 +224,7 @@ def resnet_v2_50(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v2_50'): scope='resnet_v2_50'):
"""ResNet-50 model of [1]. See resnet_v2() for arg and return description.""" """ResNet-50 model of [1]. See resnet_v2() for arg and return description."""
...@@ -233,7 +239,9 @@ def resnet_v2_50(inputs, ...@@ -233,7 +239,9 @@ def resnet_v2_50(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v2_50.default_image_size = resnet_v2.default_image_size
def resnet_v2_101(inputs, def resnet_v2_101(inputs,
...@@ -241,6 +249,7 @@ def resnet_v2_101(inputs, ...@@ -241,6 +249,7 @@ def resnet_v2_101(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v2_101'): scope='resnet_v2_101'):
"""ResNet-101 model of [1]. See resnet_v2() for arg and return description.""" """ResNet-101 model of [1]. See resnet_v2() for arg and return description."""
...@@ -255,7 +264,9 @@ def resnet_v2_101(inputs, ...@@ -255,7 +264,9 @@ def resnet_v2_101(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v2_101.default_image_size = resnet_v2.default_image_size
def resnet_v2_152(inputs, def resnet_v2_152(inputs,
...@@ -263,6 +274,7 @@ def resnet_v2_152(inputs, ...@@ -263,6 +274,7 @@ def resnet_v2_152(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v2_152'): scope='resnet_v2_152'):
"""ResNet-152 model of [1]. See resnet_v2() for arg and return description.""" """ResNet-152 model of [1]. See resnet_v2() for arg and return description."""
...@@ -277,7 +289,9 @@ def resnet_v2_152(inputs, ...@@ -277,7 +289,9 @@ def resnet_v2_152(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v2_152.default_image_size = resnet_v2.default_image_size
def resnet_v2_200(inputs, def resnet_v2_200(inputs,
...@@ -285,6 +299,7 @@ def resnet_v2_200(inputs, ...@@ -285,6 +299,7 @@ def resnet_v2_200(inputs,
is_training=True, is_training=True,
global_pool=True, global_pool=True,
output_stride=None, output_stride=None,
spatial_squeeze=True,
reuse=None, reuse=None,
scope='resnet_v2_200'): scope='resnet_v2_200'):
"""ResNet-200 model of [2]. See resnet_v2() for arg and return description.""" """ResNet-200 model of [2]. See resnet_v2() for arg and return description."""
...@@ -299,4 +314,6 @@ def resnet_v2_200(inputs, ...@@ -299,4 +314,6 @@ def resnet_v2_200(inputs,
'block4', bottleneck, [(2048, 512, 1)] * 3)] 'block4', bottleneck, [(2048, 512, 1)] * 3)]
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, spatial_squeeze=spatial_squeeze,
reuse=reuse, scope=scope)
resnet_v2_200.default_image_size = resnet_v2.default_image_size
...@@ -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
...@@ -68,7 +68,8 @@ def vgg_a(inputs, ...@@ -68,7 +68,8 @@ def vgg_a(inputs,
is_training=True, is_training=True,
dropout_keep_prob=0.5, dropout_keep_prob=0.5,
spatial_squeeze=True, spatial_squeeze=True,
scope='vgg_a'): scope='vgg_a',
fc_conv_padding='VALID'):
"""Oxford Net VGG 11-Layers version A Example. """Oxford Net VGG 11-Layers version A Example.
Note: All the fully_connected layers have been transformed to conv2d layers. Note: All the fully_connected layers have been transformed to conv2d layers.
...@@ -83,6 +84,11 @@ def vgg_a(inputs, ...@@ -83,6 +84,11 @@ def vgg_a(inputs,
spatial_squeeze: whether or not should squeeze the spatial dimensions of the spatial_squeeze: whether or not should squeeze the spatial dimensions of the
outputs. Useful to remove unnecessary dimensions for classification. outputs. Useful to remove unnecessary dimensions for classification.
scope: Optional scope for the variables. scope: Optional scope for the variables.
fc_conv_padding: the type of padding to use for the fully connected layer
that is implemented as a convolutional layer. Use 'SAME' padding if you
are applying the network in a fully convolutional manner and want to
get a prediction map downsampled by a factor of 32 as an output. Otherwise,
the output prediction map will be (input / 32) - 6 in case of 'VALID' padding.
Returns: Returns:
the last op containing the log predictions and end_points dict. the last op containing the log predictions and end_points dict.
...@@ -103,7 +109,7 @@ def vgg_a(inputs, ...@@ -103,7 +109,7 @@ def vgg_a(inputs,
net = slim.repeat(net, 2, slim.conv2d, 512, [3, 3], scope='conv5') net = slim.repeat(net, 2, slim.conv2d, 512, [3, 3], scope='conv5')
net = slim.max_pool2d(net, [2, 2], scope='pool5') net = slim.max_pool2d(net, [2, 2], scope='pool5')
# Use conv2d instead of fully_connected layers. # Use conv2d instead of fully_connected layers.
net = slim.conv2d(net, 4096, [7, 7], padding='VALID', scope='fc6') net = slim.conv2d(net, 4096, [7, 7], padding=fc_conv_padding, scope='fc6')
net = slim.dropout(net, dropout_keep_prob, is_training=is_training, net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
scope='dropout6') scope='dropout6')
net = slim.conv2d(net, 4096, [1, 1], scope='fc7') net = slim.conv2d(net, 4096, [1, 1], scope='fc7')
...@@ -127,7 +133,8 @@ def vgg_16(inputs, ...@@ -127,7 +133,8 @@ def vgg_16(inputs,
is_training=True, is_training=True,
dropout_keep_prob=0.5, dropout_keep_prob=0.5,
spatial_squeeze=True, spatial_squeeze=True,
scope='vgg_16'): scope='vgg_16',
fc_conv_padding='VALID'):
"""Oxford Net VGG 16-Layers version D Example. """Oxford Net VGG 16-Layers version D Example.
Note: All the fully_connected layers have been transformed to conv2d layers. Note: All the fully_connected layers have been transformed to conv2d layers.
...@@ -142,6 +149,11 @@ def vgg_16(inputs, ...@@ -142,6 +149,11 @@ def vgg_16(inputs,
spatial_squeeze: whether or not should squeeze the spatial dimensions of the spatial_squeeze: whether or not should squeeze the spatial dimensions of the
outputs. Useful to remove unnecessary dimensions for classification. outputs. Useful to remove unnecessary dimensions for classification.
scope: Optional scope for the variables. scope: Optional scope for the variables.
fc_conv_padding: the type of padding to use for the fully connected layer
that is implemented as a convolutional layer. Use 'SAME' padding if you
are applying the network in a fully convolutional manner and want to
get a prediction map downsampled by a factor of 32 as an output. Otherwise,
the output prediction map will be (input / 32) - 6 in case of 'VALID' padding.
Returns: Returns:
the last op containing the log predictions and end_points dict. the last op containing the log predictions and end_points dict.
...@@ -162,7 +174,7 @@ def vgg_16(inputs, ...@@ -162,7 +174,7 @@ def vgg_16(inputs,
net = slim.repeat(net, 3, slim.conv2d, 512, [3, 3], scope='conv5') net = slim.repeat(net, 3, slim.conv2d, 512, [3, 3], scope='conv5')
net = slim.max_pool2d(net, [2, 2], scope='pool5') net = slim.max_pool2d(net, [2, 2], scope='pool5')
# Use conv2d instead of fully_connected layers. # Use conv2d instead of fully_connected layers.
net = slim.conv2d(net, 4096, [7, 7], padding='VALID', scope='fc6') net = slim.conv2d(net, 4096, [7, 7], padding=fc_conv_padding, scope='fc6')
net = slim.dropout(net, dropout_keep_prob, is_training=is_training, net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
scope='dropout6') scope='dropout6')
net = slim.conv2d(net, 4096, [1, 1], scope='fc7') net = slim.conv2d(net, 4096, [1, 1], scope='fc7')
...@@ -186,7 +198,8 @@ def vgg_19(inputs, ...@@ -186,7 +198,8 @@ def vgg_19(inputs,
is_training=True, is_training=True,
dropout_keep_prob=0.5, dropout_keep_prob=0.5,
spatial_squeeze=True, spatial_squeeze=True,
scope='vgg_19'): scope='vgg_19',
fc_conv_padding='VALID'):
"""Oxford Net VGG 19-Layers version E Example. """Oxford Net VGG 19-Layers version E Example.
Note: All the fully_connected layers have been transformed to conv2d layers. Note: All the fully_connected layers have been transformed to conv2d layers.
...@@ -201,6 +214,11 @@ def vgg_19(inputs, ...@@ -201,6 +214,11 @@ def vgg_19(inputs,
spatial_squeeze: whether or not should squeeze the spatial dimensions of the spatial_squeeze: whether or not should squeeze the spatial dimensions of the
outputs. Useful to remove unnecessary dimensions for classification. outputs. Useful to remove unnecessary dimensions for classification.
scope: Optional scope for the variables. scope: Optional scope for the variables.
fc_conv_padding: the type of padding to use for the fully connected layer
that is implemented as a convolutional layer. Use 'SAME' padding if you
are applying the network in a fully convolutional manner and want to
get a prediction map downsampled by a factor of 32 as an output. Otherwise,
the output prediction map will be (input / 32) - 6 in case of 'VALID' padding.
Returns: Returns:
the last op containing the log predictions and end_points dict. the last op containing the log predictions and end_points dict.
...@@ -221,7 +239,7 @@ def vgg_19(inputs, ...@@ -221,7 +239,7 @@ def vgg_19(inputs,
net = slim.repeat(net, 4, slim.conv2d, 512, [3, 3], scope='conv5') net = slim.repeat(net, 4, slim.conv2d, 512, [3, 3], scope='conv5')
net = slim.max_pool2d(net, [2, 2], scope='pool5') net = slim.max_pool2d(net, [2, 2], scope='pool5')
# Use conv2d instead of fully_connected layers. # Use conv2d instead of fully_connected layers.
net = slim.conv2d(net, 4096, [7, 7], padding='VALID', scope='fc6') net = slim.conv2d(net, 4096, [7, 7], padding=fc_conv_padding, scope='fc6')
net = slim.dropout(net, dropout_keep_prob, is_training=is_training, net = slim.dropout(net, dropout_keep_prob, is_training=is_training,
scope='dropout6') scope='dropout6')
net = slim.conv2d(net, 4096, [1, 1], scope='fc7') net = slim.conv2d(net, 4096, [1, 1], scope='fc7')
......
...@@ -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):
......
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