本文整理汇总了Python中tensorflow.contrib.slim.nets.inception.inception_v3_arg_scope方法的典型用法代码示例。如果您正苦于以下问题:Python inception.inception_v3_arg_scope方法的具体用法?Python inception.inception_v3_arg_scope怎么用?Python inception.inception_v3_arg_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim.nets.inception
的用法示例。
在下文中一共展示了inception.inception_v3_arg_scope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def __call__(self, x_input, return_logits=False):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
# Inception preprocessing uses [-1, 1]-scaled input.
x_input = x_input * 2.0 - 1.0
_, end_points = inception.inception_v3(
x_input, num_classes=self.nb_classes, is_training=False,
reuse=reuse)
self.built = True
self.logits = end_points['Logits']
# Strip off the extra reshape op at the output
self.probs = end_points['Predictions'].op.inputs[0]
if return_logits:
return self.logits
else:
return self.probs
示例2: conv_tower_fn
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def conv_tower_fn(self, images, is_training=True, reuse=None):
"""Computes convolutional features using the InceptionV3 model.
Args:
images: A tensor of shape [batch_size, height, width, channels].
is_training: whether is training or not.
reuse: whether or not the network and its variables should be reused. To
be able to reuse 'scope' must be given.
Returns:
A tensor of shape [batch_size, OH, OW, N], where OWxOH is resolution of
output feature map and N is number of output features (depends on the
network architecture).
"""
mparams = self._mparams['conv_tower_fn']
logging.debug('Using final_endpoint=%s', mparams.final_endpoint)
with tf.variable_scope('conv_tower_fn/INCE'):
if reuse:
tf.get_variable_scope().reuse_variables()
with slim.arg_scope(inception.inception_v3_arg_scope()):
net, _ = inception.inception_v3_base(
images, final_endpoint=mparams.final_endpoint)
return net
示例3: conv_tower_fn
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def conv_tower_fn(self, images, is_training=True, reuse=None):
"""Computes convolutional features using the InceptionV3 model.
Args:
images: A tensor of shape [batch_size, height, width, channels].
is_training: whether is training or not.
reuse: whether or not the network and its variables should be reused. To
be able to reuse 'scope' must be given.
Returns:
A tensor of shape [batch_size, OH, OW, N], where OWxOH is resolution of
output feature map and N is number of output features (depends on the
network architecture).
"""
mparams = self._mparams['conv_tower_fn']
logging.debug('Using final_endpoint=%s', mparams.final_endpoint)
with tf.variable_scope('conv_tower_fn/INCE'):
if reuse:
tf.get_variable_scope().reuse_variables()
with slim.arg_scope(inception.inception_v3_arg_scope()):
with slim.arg_scope([slim.batch_norm, slim.dropout],
is_training=is_training):
net, _ = inception.inception_v3_base(
images, final_endpoint=mparams.final_endpoint)
return net
示例4: create_model
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def create_model(x, reuse=None):
"""Create model graph.
Args:
x: input images
reuse: reuse parameter which will be passed to underlying variable scopes.
Should be None first call and True every subsequent call.
Returns:
(logits, end_points) - tuple of model logits and enpoints
Raises:
ValueError: if model type specified by --model_name flag is invalid.
"""
if FLAGS.model_name == 'inception_v3':
with slim.arg_scope(inception.inception_v3_arg_scope()):
return inception.inception_v3(
x, num_classes=NUM_CLASSES, is_training=False, reuse=reuse)
elif FLAGS.model_name == 'inception_resnet_v2':
with slim.arg_scope(inception_resnet_v2.inception_resnet_v2_arg_scope()):
return inception_resnet_v2.inception_resnet_v2(
x, num_classes=NUM_CLASSES, is_training=False, reuse=reuse)
else:
raise ValueError('Invalid model name: %s' % (FLAGS.model_name))
示例5: conv_tower_fn
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def conv_tower_fn(self, images, is_training=True, reuse=None):
"""Computes convolutional features using the InceptionV3 model.
Args:
images: A tensor of shape [batch_size, height, width, channels].
is_training: whether is training or not.
reuse: whether or not the network and its variables should be reused. To
be able to reuse 'scope' must be given.
Returns:
A tensor of shape [batch_size, OH, OW, N], where OWxOH is resolution of
output feature map and N is number of output features (depends on the
network architecture).
"""
mparams = self._mparams['conv_tower_fn']
logging.debug('Using final_endpoint=%s', mparams.final_endpoint)
with tf.variable_scope('conv_tower_fn/INCE'):
if reuse:
tf.get_variable_scope().reuse_variables()
with slim.arg_scope(
[slim.batch_norm, slim.dropout], is_training=is_training):
with slim.arg_scope(inception.inception_v3_arg_scope()):
net, _ = inception.inception_v3_base(
images, final_endpoint=mparams.final_endpoint)
return net
示例6: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def __call__(self, x_input):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=self.num_classes, is_training=False,
reuse=reuse)
self.built = True
output = end_points['Predictions']
# Strip off the extra reshape op at the output
probs = output.op.inputs[0]
return probs
示例7: main
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(_):
batch_shape = [FLAGS.batch_size, FLAGS.image_height, FLAGS.image_width, 3]
num_classes = 1001
tf.logging.set_verbosity(tf.logging.INFO)
with tf.Graph().as_default():
# Prepare graph
x_input = tf.placeholder(tf.float32, shape=batch_shape)
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=num_classes, is_training=False)
predicted_labels = tf.argmax(end_points['Predictions'], 1)
# Run computation
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(
scaffold=tf.train.Scaffold(saver=saver),
checkpoint_filename_with_path=FLAGS.checkpoint_path,
master=FLAGS.master)
with tf.train.MonitoredSession(session_creator=session_creator) as sess:
with tf.gfile.Open(FLAGS.output_file, 'w') as out_file:
for filenames, images in load_images(FLAGS.input_dir, batch_shape):
labels = sess.run(predicted_labels, feed_dict={x_input: images})
for filename, label in zip(filenames, labels):
out_file.write('{0},{1}\n'.format(filename, label))
示例8: inception
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def inception(x_input):
'''
Builds the inception network model,
loads its weights from FLAGS.checkpoint_path,
and returns the softmax activations tensor.
'''
from tensorflow.contrib.slim.nets import inception as inception_tf
slim = tf.contrib.slim
with slim.arg_scope(inception_tf.inception_v3_arg_scope()):
_, end_points = inception_tf.inception_v3(x_input, \
num_classes=FLAGS.num_classes, \
is_training=False)
return end_points['Logits']
示例9: testModelHasExpectedNumberOfParameters
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def testModelHasExpectedNumberOfParameters(self):
batch_size = 5
height, width = 299, 299
inputs = tf.random_uniform((batch_size, height, width, 3))
with slim.arg_scope(inception.inception_v3_arg_scope()):
inception.inception_v3_base(inputs)
total_params, _ = slim.model_analyzer.analyze_vars(
slim.get_model_variables())
self.assertAlmostEqual(21802784, total_params)
示例10: graph
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def graph(x, y, i, x_max, x_min, grad):
eps = 2.0 * FLAGS.max_epsilon / 255.0
eps_iter = 2.0 / 255.0
num_classes = 1001
momentum = FLAGS.momentum
with slim.arg_scope(inception.inception_v3_arg_scope()):
logits, end_points = inception.inception_v3(
input_diversity(x), num_classes=num_classes, is_training=False)
pred = tf.argmax(end_points['Predictions'], 1)
# here is the way to stable gt lables
first_round = tf.cast(tf.equal(i, 0), tf.int64)
y = first_round * pred + (1 - first_round) * y
one_hot = tf.one_hot(y, num_classes)
cross_entropy = tf.losses.softmax_cross_entropy(one_hot, logits)
# compute the gradient info
noise = tf.gradients(cross_entropy, x)[0]
noise = noise / tf.reduce_mean(tf.abs(noise), [1,2,3], keep_dims=True)
# accumulate the gradient
noise = momentum * grad + noise
x = x + eps_iter * tf.sign(noise)
x = tf.clip_by_value(x, x_min, x_max)
i = tf.add(i, 1)
return x, y, i, x_max, x_min, noise
示例11: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def __call__(self, x_input):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=self.num_classes, is_training=False,
reuse=reuse)
self.built = True
output = end_points['Predictions']
probs = output.op.inputs[0]
return probs
示例12: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def __call__(self, x_input):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=self.nb_classes, is_training=False,
reuse=reuse)
self.built = True
output = end_points['Predictions']
# Strip off the extra reshape op at the output
probs = output.op.inputs[0]
return probs
示例13: main
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(_):
"""Run the sample defense"""
batch_shape = [FLAGS.batch_size, FLAGS.image_height, FLAGS.image_width, 3]
nb_classes = 1001
tf.logging.set_verbosity(tf.logging.INFO)
with tf.Graph().as_default():
# Prepare graph
x_input = tf.placeholder(tf.float32, shape=batch_shape)
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=nb_classes, is_training=False)
predicted_labels = tf.argmax(end_points['Predictions'], 1)
# Run computation
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(
scaffold=tf.train.Scaffold(saver=saver),
checkpoint_filename_with_path=FLAGS.checkpoint_path,
master=FLAGS.master)
with tf.train.MonitoredSession(session_creator=session_creator) as sess:
with tf.gfile.Open(FLAGS.output_file, 'w') as out_file:
for filenames, images in load_images(FLAGS.input_dir, batch_shape):
labels = sess.run(predicted_labels, feed_dict={x_input: images})
for filename, label in zip(filenames, labels):
out_file.write('{0},{1}\n'.format(filename, label))
示例14: main
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(_):
batch_shape = [FLAGS.batch_size, FLAGS.image_height, FLAGS.image_width, 3]
nb_classes = 1001
tf.logging.set_verbosity(tf.logging.INFO)
with tf.Graph().as_default():
# Prepare graph
x_input = tf.placeholder(tf.float32, shape=batch_shape)
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=nb_classes, is_training=False)
predicted_labels = tf.argmax(end_points['Predictions'], 1)
# Run computation
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(
scaffold=tf.train.Scaffold(saver=saver),
checkpoint_filename_with_path=FLAGS.checkpoint_path,
master=FLAGS.master)
with tf.train.MonitoredSession(session_creator=session_creator) as sess:
with tf.gfile.Open(FLAGS.output_file, 'w') as out_file:
for filenames, images in load_images(FLAGS.input_dir, batch_shape):
labels = sess.run(predicted_labels, feed_dict={x_input: images})
for filename, label in zip(filenames, labels):
out_file.write('{0},{1}\n'.format(filename, label))
示例15: main
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(_):
# Images for inception classifier are normalized to be in [-1, 1] interval,
# eps is a difference between pixels so it should be in [0, 2] interval.
# Renormalizing epsilon from [0, 255] to [0, 2].
eps = 2.0 * FLAGS.max_epsilon / 255.0
batch_shape = [FLAGS.batch_size, FLAGS.image_height, FLAGS.image_width, 3]
num_classes = 1001
tf.logging.set_verbosity(tf.logging.INFO)
all_images_taget_class = load_target_class(FLAGS.input_dir)
with tf.Graph().as_default():
# Prepare graph
x_input = tf.placeholder(tf.float32, shape=batch_shape)
with slim.arg_scope(inception.inception_v3_arg_scope()):
logits, end_points = inception.inception_v3(
x_input, num_classes=num_classes, is_training=False)
target_class_input = tf.placeholder(tf.int32, shape=[FLAGS.batch_size])
one_hot_target_class = tf.one_hot(target_class_input, num_classes)
cross_entropy = tf.losses.softmax_cross_entropy(one_hot_target_class,
logits,
label_smoothing=0.1,
weights=1.0)
cross_entropy += tf.losses.softmax_cross_entropy(one_hot_target_class,
end_points['AuxLogits'],
label_smoothing=0.1,
weights=0.4)
x_adv = x_input - eps * tf.sign(tf.gradients(cross_entropy, x_input)[0])
x_adv = tf.clip_by_value(x_adv, -1.0, 1.0)
# Run computation
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(
scaffold=tf.train.Scaffold(saver=saver),
checkpoint_filename_with_path=FLAGS.checkpoint_path,
master=FLAGS.master)
with tf.train.MonitoredSession(session_creator=session_creator) as sess:
for filenames, images in load_images(FLAGS.input_dir, batch_shape):
target_class_for_batch = (
[all_images_taget_class[n] for n in filenames]
+ [0] * (FLAGS.batch_size - len(filenames)))
adv_images = sess.run(x_adv,
feed_dict={
x_input: images,
target_class_input: target_class_for_batch
})
save_images(adv_images, filenames, FLAGS.output_dir)