"docs/source/en/installation.mdx" did not exist on "e98233dde138270f4cc511ded5136e41a2677644"
Commit f906646c authored by Duc Nguyen's avatar Duc Nguyen Committed by GitHub
Browse files

Merge branch 'master' into patch-2

parents 2f3666ed a6df5573
# Faster R-CNN with Resnet-152 (v1), configured for Oxford-IIT Pets Dataset. # Faster R-CNN with Resnet-152 (v1), configured for Oxford-IIIT Pets Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as # Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and # well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
......
# Faster R-CNN with Resnet-50 (v1), configured for Oxford-IIT Pets Dataset. # Faster R-CNN with Resnet-50 (v1), configured for Oxford-IIIT Pets Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as # Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and # well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
......
# R-FCN with Resnet-101 (v1), configured for Oxford-IIT Pets Dataset. # R-FCN with Resnet-101 (v1), configured for Oxford-IIIT Pets Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as # Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and # well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
......
# SSD with Inception v2 configured for Oxford-IIT Pets Dataset. # SSD with Inception v2 configured for Oxford-IIIT Pets Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as # Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and # well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
......
# SSD with Mobilenet v1, configured for Oxford-IIT Pets Dataset. # SSD with Mobilenet v1, configured for Oxford-IIIT Pets Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as # Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and # well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that # eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from __future__ import division from __future__ import division
import numpy as np import numpy as np
from six import moves
def compute_precision_recall(scores, labels, num_gt): def compute_precision_recall(scores, labels, num_gt):
...@@ -103,7 +104,7 @@ def compute_average_precision(precision, recall): ...@@ -103,7 +104,7 @@ def compute_average_precision(precision, recall):
raise ValueError("Precision must be in the range of [0, 1].") raise ValueError("Precision must be in the range of [0, 1].")
if np.amin(recall) < 0 or np.amax(recall) > 1: if np.amin(recall) < 0 or np.amax(recall) > 1:
raise ValueError("recall must be in the range of [0, 1].") raise ValueError("recall must be in the range of [0, 1].")
if not all(recall[i] <= recall[i + 1] for i in xrange(len(recall) - 1)): if not all(recall[i] <= recall[i + 1] for i in moves.range(len(recall) - 1)):
raise ValueError("recall must be a non-decreasing array") raise ValueError("recall must be a non-decreasing array")
recall = np.concatenate([[0], recall, [1]]) recall = np.concatenate([[0], recall, [1]])
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"""Numpy BoxList classes and functions.""" """Numpy BoxList classes and functions."""
import numpy as np import numpy as np
from six import moves
class BoxList(object): class BoxList(object):
...@@ -127,7 +128,7 @@ class BoxList(object): ...@@ -127,7 +128,7 @@ class BoxList(object):
ymin, and all xmax of boxes are equal or greater than xmin. ymin, and all xmax of boxes are equal or greater than xmin.
""" """
if data.shape[0] > 0: if data.shape[0] > 0:
for i in xrange(data.shape[0]): for i in moves.range(data.shape[0]):
if data[i, 0] > data[i, 2] or data[i, 1] > data[i, 3]: if data[i, 0] > data[i, 2] or data[i, 1] > data[i, 3]:
return False return False
return True return True
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"""A module for helper tensorflow ops.""" """A module for helper tensorflow ops."""
import math import math
import six
import tensorflow as tf import tensorflow as tf
...@@ -197,9 +198,9 @@ def padded_one_hot_encoding(indices, depth, left_pad): ...@@ -197,9 +198,9 @@ def padded_one_hot_encoding(indices, depth, left_pad):
TODO: add runtime checks for depth and indices. TODO: add runtime checks for depth and indices.
""" """
if depth < 0 or not isinstance(depth, (int, long)): if depth < 0 or not isinstance(depth, (int, long) if six.PY2 else int):
raise ValueError('`depth` must be a non-negative integer.') raise ValueError('`depth` must be a non-negative integer.')
if left_pad < 0 or not isinstance(left_pad, (int, long)): if left_pad < 0 or not isinstance(left_pad, (int, long) if six.PY2 else int):
raise ValueError('`left_pad` must be a non-negative integer.') raise ValueError('`left_pad` must be a non-negative integer.')
if depth == 0: if depth == 0:
return None return None
...@@ -548,7 +549,7 @@ def position_sensitive_crop_regions(image, ...@@ -548,7 +549,7 @@ def position_sensitive_crop_regions(image,
raise ValueError('crop_size should be divisible by num_spatial_bins') raise ValueError('crop_size should be divisible by num_spatial_bins')
total_bins *= num_bins total_bins *= num_bins
bin_crop_size.append(crop_dim / num_bins) bin_crop_size.append(crop_dim // num_bins)
if not global_pool and bin_crop_size[0] != bin_crop_size[1]: if not global_pool and bin_crop_size[0] != bin_crop_size[1]:
raise ValueError('Only support square bin crop size for now.') raise ValueError('Only support square bin crop size for now.')
......
...@@ -122,7 +122,7 @@ def get_variables_available_in_checkpoint(variables, checkpoint_path): ...@@ -122,7 +122,7 @@ def get_variables_available_in_checkpoint(variables, checkpoint_path):
ckpt_reader = tf.train.NewCheckpointReader(checkpoint_path) ckpt_reader = tf.train.NewCheckpointReader(checkpoint_path)
ckpt_vars = ckpt_reader.get_variable_to_shape_map().keys() ckpt_vars = ckpt_reader.get_variable_to_shape_map().keys()
vars_in_ckpt = {} vars_in_ckpt = {}
for variable_name, variable in sorted(variable_names_map.iteritems()): for variable_name, variable in sorted(variable_names_map.items()):
if variable_name in ckpt_vars: if variable_name in ckpt_vars:
vars_in_ckpt[variable_name] = variable vars_in_ckpt[variable_name] = variable
else: else:
......
...@@ -80,7 +80,7 @@ def encode_image_array_as_png_str(image): ...@@ -80,7 +80,7 @@ def encode_image_array_as_png_str(image):
PNG encoded image string. PNG encoded image string.
""" """
image_pil = Image.fromarray(np.uint8(image)) image_pil = Image.fromarray(np.uint8(image))
output = six.StringIO() output = six.BytesIO()
image_pil.save(output, format='PNG') image_pil.save(output, format='PNG')
png_string = output.getvalue() png_string = output.getvalue()
output.close() output.close()
......
...@@ -321,8 +321,8 @@ def masked_conv_aff_coupling(input_, mask_in, dim, name, ...@@ -321,8 +321,8 @@ def masked_conv_aff_coupling(input_, mask_in, dim, name,
input_=res, dim=channels, name="bn_in", scale=False, input_=res, dim=channels, name="bn_in", scale=False,
train=train, epsilon=1e-4, axes=[0, 1, 2]) train=train, epsilon=1e-4, axes=[0, 1, 2])
res *= 2. res *= 2.
res = tf.concat_v2([res, -res], 3) res = tf.concat([res, -res], 3)
res = tf.concat_v2([res, mask], 3) res = tf.concat([res, mask], 3)
dim_in = 2. * channels + 1 dim_in = 2. * channels + 1
res = tf.nn.relu(res) res = tf.nn.relu(res)
res = resnet(input_=res, dim_in=dim_in, dim=dim, res = resnet(input_=res, dim_in=dim_in, dim=dim,
...@@ -411,8 +411,8 @@ def masked_conv_add_coupling(input_, mask_in, dim, name, ...@@ -411,8 +411,8 @@ def masked_conv_add_coupling(input_, mask_in, dim, name,
input_=res, dim=channels, name="bn_in", scale=False, input_=res, dim=channels, name="bn_in", scale=False,
train=train, epsilon=1e-4, axes=[0, 1, 2]) train=train, epsilon=1e-4, axes=[0, 1, 2])
res *= 2. res *= 2.
res = tf.concat_v2([res, -res], 3) res = tf.concat([res, -res], 3)
res = tf.concat_v2([res, mask], 3) res = tf.concat([res, mask], 3)
dim_in = 2. * channels + 1 dim_in = 2. * channels + 1
res = tf.nn.relu(res) res = tf.nn.relu(res)
shift = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=channels, shift = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=channels,
...@@ -501,7 +501,7 @@ def conv_ch_aff_coupling(input_, dim, name, ...@@ -501,7 +501,7 @@ def conv_ch_aff_coupling(input_, dim, name,
res = batch_norm( res = batch_norm(
input_=res, dim=channels, name="bn_in", scale=False, input_=res, dim=channels, name="bn_in", scale=False,
train=train, epsilon=1e-4, axes=[0, 1, 2]) train=train, epsilon=1e-4, axes=[0, 1, 2])
res = tf.concat_v2([res, -res], 3) res = tf.concat([res, -res], 3)
dim_in = 2. * channels dim_in = 2. * channels
res = tf.nn.relu(res) res = tf.nn.relu(res)
res = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=2 * channels, res = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=2 * channels,
...@@ -551,11 +551,11 @@ def conv_ch_aff_coupling(input_, dim, name, ...@@ -551,11 +551,11 @@ def conv_ch_aff_coupling(input_, dim, name,
res *= tf.exp(-.5 * log_var) res *= tf.exp(-.5 * log_var)
log_diff -= .5 * log_var log_diff -= .5 * log_var
if change_bottom: if change_bottom:
res = tf.concat_v2([input_, res], 3) res = tf.concat([input_, res], 3)
log_diff = tf.concat_v2([tf.zeros_like(log_diff), log_diff], 3) log_diff = tf.concat([tf.zeros_like(log_diff), log_diff], 3)
else: else:
res = tf.concat_v2([res, input_], 3) res = tf.concat([res, input_], 3)
log_diff = tf.concat_v2([log_diff, tf.zeros_like(log_diff)], 3) log_diff = tf.concat([log_diff, tf.zeros_like(log_diff)], 3)
return res, log_diff return res, log_diff
...@@ -582,7 +582,7 @@ def conv_ch_add_coupling(input_, dim, name, ...@@ -582,7 +582,7 @@ def conv_ch_add_coupling(input_, dim, name,
res = batch_norm( res = batch_norm(
input_=res, dim=channels, name="bn_in", scale=False, input_=res, dim=channels, name="bn_in", scale=False,
train=train, epsilon=1e-4, axes=[0, 1, 2]) train=train, epsilon=1e-4, axes=[0, 1, 2])
res = tf.concat_v2([res, -res], 3) res = tf.concat([res, -res], 3)
dim_in = 2. * channels dim_in = 2. * channels
res = tf.nn.relu(res) res = tf.nn.relu(res)
shift = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=channels, shift = resnet(input_=res, dim_in=dim_in, dim=dim, dim_out=channels,
...@@ -616,11 +616,11 @@ def conv_ch_add_coupling(input_, dim, name, ...@@ -616,11 +616,11 @@ def conv_ch_add_coupling(input_, dim, name,
res *= tf.exp(-.5 * log_var) res *= tf.exp(-.5 * log_var)
log_diff -= .5 * log_var log_diff -= .5 * log_var
if change_bottom: if change_bottom:
res = tf.concat_v2([input_, res], 3) res = tf.concat([input_, res], 3)
log_diff = tf.concat_v2([tf.zeros_like(log_diff), log_diff], 3) log_diff = tf.concat([tf.zeros_like(log_diff), log_diff], 3)
else: else:
res = tf.concat_v2([res, input_], 3) res = tf.concat([res, input_], 3)
log_diff = tf.concat_v2([log_diff, tf.zeros_like(log_diff)], 3) log_diff = tf.concat([log_diff, tf.zeros_like(log_diff)], 3)
return res, log_diff return res, log_diff
...@@ -742,9 +742,9 @@ def rec_masked_conv_coupling(input_, hps, scale_idx, n_scale, ...@@ -742,9 +742,9 @@ def rec_masked_conv_coupling(input_, hps, scale_idx, n_scale,
input_=res_1, hps=hps, scale_idx=scale_idx + 1, n_scale=n_scale, input_=res_1, hps=hps, scale_idx=scale_idx + 1, n_scale=n_scale,
use_batch_norm=use_batch_norm, weight_norm=weight_norm, use_batch_norm=use_batch_norm, weight_norm=weight_norm,
train=train) train=train)
res = tf.concat_v2([res_1, res_2], 3) res = tf.concat([res_1, res_2], 3)
log_diff_1 += inc_log_diff log_diff_1 += inc_log_diff
log_diff = tf.concat_v2([log_diff_1, log_diff_2], 3) log_diff = tf.concat([log_diff_1, log_diff_2], 3)
res = squeeze_2x2_ordered(res, reverse=True) res = squeeze_2x2_ordered(res, reverse=True)
log_diff = squeeze_2x2_ordered(log_diff, reverse=True) log_diff = squeeze_2x2_ordered(log_diff, reverse=True)
else: else:
...@@ -805,8 +805,8 @@ def rec_masked_deconv_coupling(input_, hps, scale_idx, n_scale, ...@@ -805,8 +805,8 @@ def rec_masked_deconv_coupling(input_, hps, scale_idx, n_scale,
scale_idx=scale_idx + 1, n_scale=n_scale, scale_idx=scale_idx + 1, n_scale=n_scale,
use_batch_norm=use_batch_norm, weight_norm=weight_norm, use_batch_norm=use_batch_norm, weight_norm=weight_norm,
train=train) train=train)
res = tf.concat_v2([res_1, res_2], 3) res = tf.concat([res_1, res_2], 3)
log_diff = tf.concat_v2([log_diff_1, log_diff_2], 3) log_diff = tf.concat([log_diff_1, log_diff_2], 3)
res = squeeze_2x2_ordered(res, reverse=True) res = squeeze_2x2_ordered(res, reverse=True)
log_diff = squeeze_2x2_ordered(log_diff, reverse=True) log_diff = squeeze_2x2_ordered(log_diff, reverse=True)
else: else:
...@@ -1018,7 +1018,7 @@ class RealNVP(object): ...@@ -1018,7 +1018,7 @@ class RealNVP(object):
width = tf.cast(width, tf.int32) width = tf.cast(width, tf.int32)
depth = tf.reshape((features["depth"], tf.int64)[0], [1]) depth = tf.reshape((features["depth"], tf.int64)[0], [1])
depth = tf.cast(depth, tf.int32) depth = tf.cast(depth, tf.int32)
image = tf.reshape(image, tf.concat_v2([height, width, depth], 0)) image = tf.reshape(image, tf.concat([height, width, depth], 0))
image = tf.random_crop(image, [64, 64, 3]) image = tf.random_crop(image, [64, 64, 3])
if FLAGS.mode == "train": if FLAGS.mode == "train":
image = tf.image.random_flip_left_right(image) image = tf.image.random_flip_left_right(image)
...@@ -1309,19 +1309,19 @@ class RealNVP(object): ...@@ -1309,19 +1309,19 @@ class RealNVP(object):
z_compressed = z_lost z_compressed = z_lost
z_noisy = z_lost z_noisy = z_lost
for _ in xrange(scale_idx + 1): for _ in xrange(scale_idx + 1):
z_compressed = tf.concat_v2( z_compressed = tf.concat(
[z_compressed, tf.zeros_like(z_compressed)], 3) [z_compressed, tf.zeros_like(z_compressed)], 3)
z_compressed = squeeze_2x2_ordered( z_compressed = squeeze_2x2_ordered(
z_compressed, reverse=True) z_compressed, reverse=True)
z_noisy = tf.concat_v2( z_noisy = tf.concat(
[z_noisy, tf.random_normal( [z_noisy, tf.random_normal(
z_noisy.get_shape().as_list())], 3) z_noisy.get_shape().as_list())], 3)
z_noisy = squeeze_2x2_ordered(z_noisy, reverse=True) z_noisy = squeeze_2x2_ordered(z_noisy, reverse=True)
z_compressed_list.append(z_compressed) z_compressed_list.append(z_compressed)
z_noisy_list.append(z_noisy) z_noisy_list.append(z_noisy)
self.z_reduced = z_lost self.z_reduced = z_lost
z_compressed = tf.concat_v2(z_compressed_list, 0) z_compressed = tf.concat(z_compressed_list, 0)
z_noisy = tf.concat_v2(z_noisy_list, 0) z_noisy = tf.concat(z_noisy_list, 0)
noisy_images, _ = decoder( noisy_images, _ = decoder(
input_=z_noisy, hps=hps, n_scale=hps.n_scale, input_=z_noisy, hps=hps, n_scale=hps.n_scale,
use_batch_norm=hps.use_batch_norm, weight_norm=True, use_batch_norm=hps.use_batch_norm, weight_norm=True,
......
...@@ -390,3 +390,26 @@ py_binary( ...@@ -390,3 +390,26 @@ py_binary(
":preprocessing_factory", ":preprocessing_factory",
], ],
) )
py_binary(
name = "export_inference_graph",
srcs = ["export_inference_graph.py"],
deps = [
":dataset_factory",
":nets_factory",
],
)
py_test(
name = "export_inference_graph_test",
size = "medium",
srcs = ["export_inference_graph_test.py"],
srcs_version = "PY2AND3",
tags = [
"manual",
],
deps = [
":export_inference_graph",
":nets_factory",
],
)
...@@ -32,6 +32,8 @@ Maintainers of TF-slim: ...@@ -32,6 +32,8 @@ Maintainers of TF-slim:
<a href='#Training'>Training from scratch</a><br> <a href='#Training'>Training from scratch</a><br>
<a href='#Tuning'>Fine tuning to a new task</a><br> <a href='#Tuning'>Fine tuning to a new task</a><br>
<a href='#Eval'>Evaluating performance</a><br> <a href='#Eval'>Evaluating performance</a><br>
<a href='#Export'>Exporting Inference Graph</a><br>
<a href='#Troubleshooting'>Troubleshooting</a><br>
# Installation # Installation
<a id='Install'></a> <a id='Install'></a>
...@@ -195,9 +197,12 @@ Model | TF-Slim File | Checkpoint | Top-1 Accuracy| Top-5 Accuracy | ...@@ -195,9 +197,12 @@ Model | TF-Slim File | Checkpoint | Top-1 Accuracy| Top-5 Accuracy |
[Inception V3](http://arxiv.org/abs/1512.00567)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_v3.py)|[inception_v3_2016_08_28.tar.gz](http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz)|78.0|93.9| [Inception V3](http://arxiv.org/abs/1512.00567)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_v3.py)|[inception_v3_2016_08_28.tar.gz](http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz)|78.0|93.9|
[Inception V4](http://arxiv.org/abs/1602.07261)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_v4.py)|[inception_v4_2016_09_09.tar.gz](http://download.tensorflow.org/models/inception_v4_2016_09_09.tar.gz)|80.2|95.2| [Inception V4](http://arxiv.org/abs/1602.07261)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_v4.py)|[inception_v4_2016_09_09.tar.gz](http://download.tensorflow.org/models/inception_v4_2016_09_09.tar.gz)|80.2|95.2|
[Inception-ResNet-v2](http://arxiv.org/abs/1602.07261)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_resnet_v2.py)|[inception_resnet_v2_2016_08_30.tar.gz](http://download.tensorflow.org/models/inception_resnet_v2_2016_08_30.tar.gz)|80.4|95.3| [Inception-ResNet-v2](http://arxiv.org/abs/1602.07261)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/inception_resnet_v2.py)|[inception_resnet_v2_2016_08_30.tar.gz](http://download.tensorflow.org/models/inception_resnet_v2_2016_08_30.tar.gz)|80.4|95.3|
[ResNet 50](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_50_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_50_2016_08_28.tar.gz)|75.2|92.2| [ResNet V1 50](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_50_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_50_2016_08_28.tar.gz)|75.2|92.2|
[ResNet 101](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_101_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz)|76.4|92.9| [ResNet V1 101](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_101_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz)|76.4|92.9|
[ResNet 152](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_152_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_152_2016_08_28.tar.gz)|76.8|93.2| [ResNet V1 152](https://arxiv.org/abs/1512.03385)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py)|[resnet_v1_152_2016_08_28.tar.gz](http://download.tensorflow.org/models/resnet_v1_152_2016_08_28.tar.gz)|76.8|93.2|
[ResNet V2 50](https://arxiv.org/abs/1603.05027)^|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v2.py)|[resnet_v2_50_2017_04_14.tar.gz](http://download.tensorflow.org/models/resnet_v2_50_2017_04_14.tar.gz)|75.6|92.8|
[ResNet V2 101](https://arxiv.org/abs/1603.05027)^|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v2.py)|[resnet_v2_101_2017_04_14.tar.gz](http://download.tensorflow.org/models/resnet_v2_101_2017_04_14.tar.gz)|77.0|93.7|
[ResNet V2 152](https://arxiv.org/abs/1603.05027)^|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v2.py)|[resnet_v2_152_2017_04_14.tar.gz](http://download.tensorflow.org/models/resnet_v2_152_2017_04_14.tar.gz)|77.8|94.1|
[ResNet V2 200](https://arxiv.org/abs/1603.05027)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v2.py)|[TBA]()|79.9\*|95.2\*| [ResNet V2 200](https://arxiv.org/abs/1603.05027)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v2.py)|[TBA]()|79.9\*|95.2\*|
[VGG 16](http://arxiv.org/abs/1409.1556.pdf)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/vgg.py)|[vgg_16_2016_08_28.tar.gz](http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz)|71.5|89.8| [VGG 16](http://arxiv.org/abs/1409.1556.pdf)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/vgg.py)|[vgg_16_2016_08_28.tar.gz](http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz)|71.5|89.8|
[VGG 19](http://arxiv.org/abs/1409.1556.pdf)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/vgg.py)|[vgg_19_2016_08_28.tar.gz](http://download.tensorflow.org/models/vgg_19_2016_08_28.tar.gz)|71.1|89.8| [VGG 19](http://arxiv.org/abs/1409.1556.pdf)|[Code](https://github.com/tensorflow/models/blob/master/slim/nets/vgg.py)|[vgg_19_2016_08_28.tar.gz](http://download.tensorflow.org/models/vgg_19_2016_08_28.tar.gz)|71.1|89.8|
...@@ -213,6 +218,7 @@ reported on ImageNet valdiation set. ...@@ -213,6 +218,7 @@ reported on ImageNet valdiation set.
All 16 MobileNet Models reported in the [MobileNet Paper](https://arxiv.org/abs/1704.04861) can be found [here](https://github.com/tensorflow/models/tree/master/slim/nets/mobilenet_v1.md). All 16 MobileNet Models reported in the [MobileNet Paper](https://arxiv.org/abs/1704.04861) can be found [here](https://github.com/tensorflow/models/tree/master/slim/nets/mobilenet_v1.md).
(\*): Results quoted from the [paper](https://arxiv.org/abs/1603.05027). (\*): Results quoted from the [paper](https://arxiv.org/abs/1603.05027).
Here is an example of how to download the Inception V3 checkpoint: Here is an example of how to download the Inception V3 checkpoint:
```shell ```shell
...@@ -327,8 +333,72 @@ $ python eval_image_classifier.py \ ...@@ -327,8 +333,72 @@ $ python eval_image_classifier.py \
``` ```
# Exporting the Inference Graph
<a id='Export'></a>
Saves out a GraphDef containing the architecture of the model.
To use it with a model name defined by slim, run:
```shell
$ python export_inference_graph.py \
--alsologtostderr \
--model_name=inception_v3 \
--output_file=/tmp/inception_v3_inf_graph.pb
$ python export_inference_graph.py \
--alsologtostderr \
--model_name=mobilenet_v1 \
--image_size=224 \
--output_file=/tmp/mobilenet_v1_224.pb
```
## Freezing the exported Graph
If you then want to use the resulting model with your own or pretrained
checkpoints as part of a mobile model, you can run freeze_graph to get a graph
def with the variables inlined as constants using:
```shell
bazel build tensorflow/python/tools:freeze_graph
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=/tmp/inception_v3_inf_graph.pb \
--input_checkpoint=/tmp/checkpoints/inception_v3.ckpt \
--input_binary=true --output_graph=/tmp/frozen_inception_v3.pb \
--output_node_names=InceptionV3/Predictions/Reshape_1
```
The output node names will vary depending on the model, but you can inspect and
estimate them using the summarize_graph tool:
```shell
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph \
--in_graph=/tmp/inception_v3_inf_graph.pb
```
## Run label image in C++
To run the resulting graph in C++, you can look at the label_image sample code:
```shell
bazel build tensorflow/examples/label_image:label_image
bazel-bin/tensorflow/examples/label_image/label_image \
--image=${HOME}/Pictures/flowers.jpg \
--input_layer=input \
--output_layer=InceptionV3/Predictions/Reshape_1 \
--graph=/tmp/frozen_inception_v3.pb \
--labels=/tmp/imagenet_slim_labels.txt \
--input_mean=0 \
--input_std=255 \
--logtostderr
```
# Troubleshooting # Troubleshooting
<a id='Troubleshooting'></a>
#### The model runs out of CPU memory. #### The model runs out of CPU memory.
......
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
r"""Saves out a GraphDef containing the architecture of the model.
To use it, run something like this, with a model name defined by slim:
bazel build tensorflow_models/slim:export_inference_graph
bazel-bin/tensorflow_models/slim/export_inference_graph \
--model_name=inception_v3 --output_file=/tmp/inception_v3_inf_graph.pb
If you then want to use the resulting model with your own or pretrained
checkpoints as part of a mobile model, you can run freeze_graph to get a graph
def with the variables inlined as constants using:
bazel build tensorflow/python/tools:freeze_graph
bazel-bin/tensorflow/python/tools/freeze_graph \
--input_graph=/tmp/inception_v3_inf_graph.pb \
--input_checkpoint=/tmp/checkpoints/inception_v3.ckpt \
--input_binary=true --output_graph=/tmp/frozen_inception_v3.pb \
--output_node_names=InceptionV3/Predictions/Reshape_1
The output node names will vary depending on the model, but you can inspect and
estimate them using the summarize_graph tool:
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph \
--in_graph=/tmp/inception_v3_inf_graph.pb
To run the resulting graph in C++, you can look at the label_image sample code:
bazel build tensorflow/examples/label_image:label_image
bazel-bin/tensorflow/examples/label_image/label_image \
--image=${HOME}/Pictures/flowers.jpg \
--input_layer=input \
--output_layer=InceptionV3/Predictions/Reshape_1 \
--graph=/tmp/frozen_inception_v3.pb \
--labels=/tmp/imagenet_slim_labels.txt \
--input_mean=0 \
--input_std=255 \
--logtostderr
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from tensorflow.python.platform import gfile
from datasets import dataset_factory
from nets import nets_factory
slim = tf.contrib.slim
tf.app.flags.DEFINE_string(
'model_name', 'inception_v3', 'The name of the architecture to save.')
tf.app.flags.DEFINE_boolean(
'is_training', False,
'Whether to save out a training-focused version of the model.')
tf.app.flags.DEFINE_integer(
'default_image_size', 224,
'The image size to use if the model does not define it.')
tf.app.flags.DEFINE_string('dataset_name', 'imagenet',
'The name of the dataset to use with the model.')
tf.app.flags.DEFINE_integer(
'labels_offset', 0,
'An offset for the labels in the dataset. This flag is primarily used to '
'evaluate the VGG and ResNet architectures which do not use a background '
'class for the ImageNet dataset.')
tf.app.flags.DEFINE_string(
'output_file', '', 'Where to save the resulting file to.')
tf.app.flags.DEFINE_string(
'dataset_dir', '', 'Directory to save intermediate dataset files to')
FLAGS = tf.app.flags.FLAGS
def main(_):
if not FLAGS.output_file:
raise ValueError('You must supply the path to save to with --output_file')
tf.logging.set_verbosity(tf.logging.INFO)
with tf.Graph().as_default() as graph:
dataset = dataset_factory.get_dataset(FLAGS.dataset_name, 'validation',
FLAGS.dataset_dir)
network_fn = nets_factory.get_network_fn(
FLAGS.model_name,
num_classes=(dataset.num_classes - FLAGS.labels_offset),
is_training=FLAGS.is_training)
if hasattr(network_fn, 'default_image_size'):
image_size = network_fn.default_image_size
else:
image_size = FLAGS.default_image_size
placeholder = tf.placeholder(name='input', dtype=tf.float32,
shape=[1, image_size, image_size, 3])
network_fn(placeholder)
graph_def = graph.as_graph_def()
with gfile.GFile(FLAGS.output_file, 'wb') as f:
f.write(graph_def.SerializeToString())
if __name__ == '__main__':
tf.app.run()
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for export_inference_graph."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import tensorflow as tf
from tensorflow.python.platform import gfile
from google3.third_party.tensorflow_models.slim import export_inference_graph
class ExportInferenceGraphTest(tf.test.TestCase):
def testExportInferenceGraph(self):
tmpdir = self.get_temp_dir()
output_file = os.path.join(tmpdir, 'inception_v3.pb')
flags = tf.app.flags.FLAGS
flags.output_file = output_file
flags.model_name = 'inception_v3'
flags.dataset_dir = tmpdir
export_inference_graph.main(None)
self.assertTrue(gfile.Exists(output_file))
if __name__ == '__main__':
tf.test.main()
...@@ -161,6 +161,9 @@ def resnet_v1(inputs, ...@@ -161,6 +161,9 @@ def resnet_v1(inputs,
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 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.
To use this parameter, the input images must be smaller than 300x300
pixels, in which case the output logit layer does not contain spatial
information and can be removed.
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.
...@@ -200,16 +203,14 @@ def resnet_v1(inputs, ...@@ -200,16 +203,14 @@ 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: if spatial_squeeze:
logits = tf.squeeze(net, [1, 2], name='SpatialSqueeze') net = 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 = slim.utils.convert_collection_to_dict(
end_points_collection) end_points_collection)
if num_classes is not None: if num_classes is not None:
end_points['predictions'] = slim.softmax(logits, scope='predictions') end_points['predictions'] = slim.softmax(net, scope='predictions')
return logits, end_points return net, end_points
resnet_v1.default_image_size = 224 resnet_v1.default_image_size = 224
......
...@@ -158,6 +158,9 @@ def resnet_v2(inputs, ...@@ -158,6 +158,9 @@ def resnet_v2(inputs,
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 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.
To use this parameter, the input images must be smaller than 300x300
pixels, in which case the output logit layer does not contain spatial
information and can be removed.
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.
...@@ -207,16 +210,14 @@ def resnet_v2(inputs, ...@@ -207,16 +210,14 @@ 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: if spatial_squeeze:
logits = tf.squeeze(net, [1, 2], name='SpatialSqueeze') net = 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 = slim.utils.convert_collection_to_dict(
end_points_collection) end_points_collection)
if num_classes is not None: if num_classes is not None:
end_points['predictions'] = slim.softmax(logits, scope='predictions') end_points['predictions'] = slim.softmax(net, scope='predictions')
return logits, end_points return net, end_points
resnet_v2.default_image_size = 224 resnet_v2.default_image_size = 224
......
...@@ -29,11 +29,14 @@ ...@@ -29,11 +29,14 @@
"## Installation and setup\n", "## Installation and setup\n",
"<a id='Install'></a>\n", "<a id='Install'></a>\n",
"\n", "\n",
"As of 8/28/16, the latest stable release of TF is r0.10, which does not contain the latest version of slim.\n", "Since the stable release of TF 1.0, the latest version of slim has been available as `tf.contrib.slim`.\n",
"To obtain the latest version of TF-Slim, please install the most recent nightly build of TF\n", "To test that your installation is working, execute the following command; it should run without raising any errors.\n",
"as explained [here](https://github.com/tensorflow/models/tree/master/slim#installing-latest-version-of-tf-slim).\n",
"\n", "\n",
"To use TF-Slim for image classification (as we do in this notebook), you also have to install the TF-Slim image models library from [here](https://github.com/tensorflow/models/tree/master/slim). Let's suppose you install this into a directory called TF_MODELS. Then you should change directory to TF_MODELS/slim **before** running this notebook, so that these files are in your python path.\n", "```\n",
"python -c \"import tensorflow.contrib.slim as slim; eval = slim.evaluation.evaluate_once\"\n",
"```\n",
"\n",
"Although, to use TF-Slim for image classification (as we do in this notebook), you also have to install the TF-Slim image models library from [here](https://github.com/tensorflow/models/tree/master/slim). Let's suppose you install this into a directory called TF_MODELS. Then you should change directory to TF_MODELS/slim **before** running this notebook, so that these files are in your python path.\n",
"\n", "\n",
"To check you've got these two steps to work, just execute the cell below. If it complains about unknown modules, restart the notebook after moving to the TF-Slim models directory.\n" "To check you've got these two steps to work, just execute the cell below. If it complains about unknown modules, restart the notebook after moving to the TF-Slim models directory.\n"
] ]
...@@ -42,10 +45,14 @@ ...@@ -42,10 +45,14 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from __future__ import absolute_import\n",
"from __future__ import division\n",
"from __future__ import print_function\n",
"\n",
"import matplotlib\n", "import matplotlib\n",
"%matplotlib inline\n", "%matplotlib inline\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
...@@ -57,7 +64,7 @@ ...@@ -57,7 +64,7 @@
"from datasets import dataset_utils\n", "from datasets import dataset_utils\n",
"\n", "\n",
"# Main slim library\n", "# Main slim library\n",
"slim = tf.contrib.slim" "from tensorflow.contrib import slim"
] ]
}, },
{ {
...@@ -143,7 +150,7 @@ ...@@ -143,7 +150,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -156,15 +163,15 @@ ...@@ -156,15 +163,15 @@
" predictions, end_points = regression_model(inputs)\n", " predictions, end_points = regression_model(inputs)\n",
"\n", "\n",
" # Print name and shape of each tensor.\n", " # Print name and shape of each tensor.\n",
" print \"Layers\"\n", " print(\"Layers\")\n",
" for k, v in end_points.items():\n", " for k, v in end_points.items():\n",
" print 'name = {}, shape = {}'.format(v.name, v.get_shape())\n", " print('name = {}, shape = {}'.format(v.name, v.get_shape()))\n",
"\n", "\n",
" # Print name and shape of parameter nodes (values not yet initialized)\n", " # Print name and shape of parameter nodes (values not yet initialized)\n",
" print \"\\n\"\n", " print(\"\\n\")\n",
" print \"Parameters\"\n", " print(\"Parameters\")\n",
" for v in slim.get_model_variables():\n", " for v in slim.get_model_variables():\n",
" print 'name = {}, shape = {}'.format(v.name, v.get_shape())\n" " print('name = {}, shape = {}'.format(v.name, v.get_shape()))\n"
] ]
}, },
{ {
...@@ -180,7 +187,7 @@ ...@@ -180,7 +187,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -228,7 +235,7 @@ ...@@ -228,7 +235,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -280,7 +287,7 @@ ...@@ -280,7 +287,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -330,7 +337,7 @@ ...@@ -330,7 +337,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -367,7 +374,7 @@ ...@@ -367,7 +374,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -441,7 +448,7 @@ ...@@ -441,7 +448,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -468,14 +475,14 @@ ...@@ -468,14 +475,14 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from datasets import flowers\n", "from datasets import flowers\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"\n", "\n",
"with tf.Graph().as_default(): \n", "with tf.Graph().as_default(): \n",
" dataset = flowers.get_split('train', flowers_data_dir)\n", " dataset = flowers.get_split('train', flowers_data_dir)\n",
...@@ -485,7 +492,7 @@ ...@@ -485,7 +492,7 @@
" \n", " \n",
" with tf.Session() as sess: \n", " with tf.Session() as sess: \n",
" with slim.queues.QueueRunners(sess):\n", " with slim.queues.QueueRunners(sess):\n",
" for i in xrange(4):\n", " for i in range(4):\n",
" np_image, np_label = sess.run([image, label])\n", " np_image, np_label = sess.run([image, label])\n",
" height, width, _ = np_image.shape\n", " height, width, _ = np_image.shape\n",
" class_name = name = dataset.labels_to_names[np_label]\n", " class_name = name = dataset.labels_to_names[np_label]\n",
...@@ -547,7 +554,7 @@ ...@@ -547,7 +554,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -599,14 +606,14 @@ ...@@ -599,14 +606,14 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from preprocessing import inception_preprocessing\n", "from preprocessing import inception_preprocessing\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"\n", "\n",
"\n", "\n",
"def load_batch(dataset, batch_size=32, height=299, width=299, is_training=False):\n", "def load_batch(dataset, batch_size=32, height=299, width=299, is_training=False):\n",
...@@ -651,7 +658,7 @@ ...@@ -651,7 +658,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -706,7 +713,7 @@ ...@@ -706,7 +713,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -771,7 +778,7 @@ ...@@ -771,7 +778,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -802,26 +809,30 @@ ...@@ -802,26 +809,30 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
"import os\n", "import os\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
"import urllib2\n", "\n",
"try:\n",
" import urllib2\n",
"except ImportError:\n",
" import urllib.request as urllib\n",
"\n", "\n",
"from datasets import imagenet\n", "from datasets import imagenet\n",
"from nets import inception\n", "from nets import inception\n",
"from preprocessing import inception_preprocessing\n", "from preprocessing import inception_preprocessing\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"\n", "\n",
"image_size = inception.inception_v1.default_image_size\n", "image_size = inception.inception_v1.default_image_size\n",
"\n", "\n",
"with tf.Graph().as_default():\n", "with tf.Graph().as_default():\n",
" url = 'https://upload.wikimedia.org/wikipedia/commons/7/70/EnglishCockerSpaniel_simon.jpg'\n", " url = 'https://upload.wikimedia.org/wikipedia/commons/7/70/EnglishCockerSpaniel_simon.jpg'\n",
" image_string = urllib2.urlopen(url).read()\n", " image_string = urllib.urlopen(url).read()\n",
" image = tf.image.decode_jpeg(image_string, channels=3)\n", " image = tf.image.decode_jpeg(image_string, channels=3)\n",
" processed_image = inception_preprocessing.preprocess_image(image, image_size, image_size, is_training=False)\n", " processed_image = inception_preprocessing.preprocess_image(image, image_size, image_size, is_training=False)\n",
" processed_images = tf.expand_dims(processed_image, 0)\n", " processed_images = tf.expand_dims(processed_image, 0)\n",
...@@ -902,19 +913,23 @@ ...@@ -902,19 +913,23 @@
"import numpy as np\n", "import numpy as np\n",
"import os\n", "import os\n",
"import tensorflow as tf\n", "import tensorflow as tf\n",
"import urllib2\n", "\n",
"try:\n",
" import urllib2\n",
"except ImportError:\n",
" import urllib.request as urllib\n",
"\n", "\n",
"from datasets import imagenet\n", "from datasets import imagenet\n",
"from nets import vgg\n", "from nets import vgg\n",
"from preprocessing import vgg_preprocessing\n", "from preprocessing import vgg_preprocessing\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"\n", "\n",
"image_size = vgg.vgg_16.default_image_size\n", "image_size = vgg.vgg_16.default_image_size\n",
"\n", "\n",
"with tf.Graph().as_default():\n", "with tf.Graph().as_default():\n",
" url = 'https://upload.wikimedia.org/wikipedia/commons/d/d9/First_Student_IC_school_bus_202076.jpg'\n", " url = 'https://upload.wikimedia.org/wikipedia/commons/d/d9/First_Student_IC_school_bus_202076.jpg'\n",
" image_string = urllib2.urlopen(url).read()\n", " image_string = urllib.urlopen(url).read()\n",
" image = tf.image.decode_jpeg(image_string, channels=3)\n", " image = tf.image.decode_jpeg(image_string, channels=3)\n",
" processed_image = vgg_preprocessing.preprocess_image(image, image_size, image_size, is_training=False)\n", " processed_image = vgg_preprocessing.preprocess_image(image, image_size, image_size, is_training=False)\n",
" processed_images = tf.expand_dims(processed_image, 0)\n", " processed_images = tf.expand_dims(processed_image, 0)\n",
...@@ -960,7 +975,7 @@ ...@@ -960,7 +975,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -972,7 +987,7 @@ ...@@ -972,7 +987,7 @@
"from nets import inception\n", "from nets import inception\n",
"from preprocessing import inception_preprocessing\n", "from preprocessing import inception_preprocessing\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"image_size = inception.inception_v1.default_image_size\n", "image_size = inception.inception_v1.default_image_size\n",
"\n", "\n",
"\n", "\n",
...@@ -1043,7 +1058,7 @@ ...@@ -1043,7 +1058,7 @@
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "collapsed": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -1052,7 +1067,7 @@ ...@@ -1052,7 +1067,7 @@
"from datasets import flowers\n", "from datasets import flowers\n",
"from nets import inception\n", "from nets import inception\n",
"\n", "\n",
"slim = tf.contrib.slim\n", "from tensorflow.contrib import slim\n",
"\n", "\n",
"image_size = inception.inception_v1.default_image_size\n", "image_size = inception.inception_v1.default_image_size\n",
"batch_size = 3\n", "batch_size = 3\n",
...@@ -1080,7 +1095,7 @@ ...@@ -1080,7 +1095,7 @@
" init_fn(sess)\n", " init_fn(sess)\n",
" np_probabilities, np_images_raw, np_labels = sess.run([probabilities, images_raw, labels])\n", " np_probabilities, np_images_raw, np_labels = sess.run([probabilities, images_raw, labels])\n",
" \n", " \n",
" for i in xrange(batch_size): \n", " for i in range(batch_size): \n",
" image = np_images_raw[i, :, :, :]\n", " image = np_images_raw[i, :, :, :]\n",
" true_label = np_labels[i]\n", " true_label = np_labels[i]\n",
" predicted_label = np.argmax(np_probabilities[i, :])\n", " predicted_label = np.argmax(np_probabilities[i, :])\n",
...@@ -1093,27 +1108,36 @@ ...@@ -1093,27 +1108,36 @@
" plt.axis('off')\n", " plt.axis('off')\n",
" plt.show()" " plt.show()"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.11" "version": "3.6.1"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }
...@@ -38,7 +38,7 @@ Avenue des Sapins ...@@ -38,7 +38,7 @@ Avenue des Sapins
## Installing and setting up the STREET model ## Installing and setting up the STREET model
[Install Tensorflow](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#virtualenv-installation) [Install Tensorflow](https://www.tensorflow.org/install/)
Install numpy: Install numpy:
......
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