當前位置: 首頁>>代碼示例>>Python>>正文


Python inception.inception_v3方法代碼示例

本文整理匯總了Python中tensorflow.contrib.slim.nets.inception.inception_v3方法的典型用法代碼示例。如果您正苦於以下問題:Python inception.inception_v3方法的具體用法?Python inception.inception_v3怎麽用?Python inception.inception_v3使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.contrib.slim.nets.inception的用法示例。


在下文中一共展示了inception.inception_v3方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [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 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:19,代碼來源:test_imagenet_attacks.py

示例2: create_model

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [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)) 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:26,代碼來源:eval_on_adversarial.py

示例3: testBuildEndPoints

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testBuildEndPoints(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_v3(inputs, num_classes)
    self.assertTrue('Logits' in end_points)
    logits = end_points['Logits']
    self.assertListEqual(logits.get_shape().as_list(),
                         [batch_size, num_classes])
    self.assertTrue('AuxLogits' in end_points)
    aux_logits = end_points['AuxLogits']
    self.assertListEqual(aux_logits.get_shape().as_list(),
                         [batch_size, num_classes])
    self.assertTrue('Mixed_7c' in end_points)
    pre_pool = end_points['Mixed_7c']
    self.assertListEqual(pre_pool.get_shape().as_list(),
                         [batch_size, 8, 8, 2048])
    self.assertTrue('PreLogits' in end_points)
    pre_logits = end_points['PreLogits']
    self.assertListEqual(pre_logits.get_shape().as_list(),
                         [batch_size, 1, 1, 2048]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:25,代碼來源:inception_v3_test.py

示例4: testBuildEndPointsWithDepthMultiplierLessThanOne

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testBuildEndPointsWithDepthMultiplierLessThanOne(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_v3(inputs, num_classes)

    endpoint_keys = [key for key in end_points.keys()
                     if key.startswith('Mixed') or key.startswith('Conv')]

    _, end_points_with_multiplier = inception.inception_v3(
        inputs, num_classes, scope='depth_multiplied_net',
        depth_multiplier=0.5)

    for key in endpoint_keys:
      original_depth = end_points[key].get_shape().as_list()[3]
      new_depth = end_points_with_multiplier[key].get_shape().as_list()[3]
      self.assertEqual(0.5 * original_depth, new_depth) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:21,代碼來源:inception_v3_test.py

示例5: testBuildEndPointsWithDepthMultiplierGreaterThanOne

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testBuildEndPointsWithDepthMultiplierGreaterThanOne(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_v3(inputs, num_classes)

    endpoint_keys = [key for key in end_points.keys()
                     if key.startswith('Mixed') or key.startswith('Conv')]

    _, end_points_with_multiplier = inception.inception_v3(
        inputs, num_classes, scope='depth_multiplied_net',
        depth_multiplier=2.0)

    for key in endpoint_keys:
      original_depth = end_points[key].get_shape().as_list()[3]
      new_depth = end_points_with_multiplier[key].get_shape().as_list()[3]
      self.assertEqual(2.0 * original_depth, new_depth) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:21,代碼來源:inception_v3_test.py

示例6: testUnknownImageShape

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v3(inputs, num_classes)
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_7c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:18,代碼來源:inception_v3_test.py

示例7: testUnknownBatchSize

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testUnknownBatchSize(self):
    batch_size = 1
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.placeholder(tf.float32, (None, height, width, 3))
    logits, _ = inception.inception_v3(inputs, num_classes)
    self.assertTrue(logits.op.name.startswith('InceptionV3/Logits'))
    self.assertListEqual(logits.get_shape().as_list(),
                         [None, num_classes])
    images = tf.random_uniform((batch_size, height, width, 3))

    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      output = sess.run(logits, {inputs: images.eval()})
      self.assertEquals(output.shape, (batch_size, num_classes)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:18,代碼來源:inception_v3_test.py

示例8: testTrainEvalWithReuse

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testTrainEvalWithReuse(self):
    train_batch_size = 5
    eval_batch_size = 2
    height, width = 150, 150
    num_classes = 1000

    train_inputs = tf.random_uniform((train_batch_size, height, width, 3))
    inception.inception_v3(train_inputs, num_classes)
    eval_inputs = tf.random_uniform((eval_batch_size, height, width, 3))
    logits, _ = inception.inception_v3(eval_inputs, num_classes,
                                       is_training=False, reuse=True)
    predictions = tf.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (eval_batch_size,)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:19,代碼來源:inception_v3_test.py

示例9: __call__

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [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 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:14,代碼來源:attack_fgsm.py

示例10: main

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [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)) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:31,代碼來源:defense.py

示例11: inception

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [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'] 
開發者ID:evtimovi,項目名稱:robust_physical_perturbations,代碼行數:16,代碼來源:attack.py

示例12: testBuildClassificationNetwork

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testBuildClassificationNetwork(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.random_uniform((batch_size, height, width, 3))
    logits, end_points = inception.inception_v3(inputs, num_classes)
    self.assertTrue(logits.op.name.startswith('InceptionV3/Logits'))
    self.assertListEqual(logits.get_shape().as_list(),
                         [batch_size, num_classes])
    self.assertTrue('Predictions' in end_points)
    self.assertListEqual(end_points['Predictions'].get_shape().as_list(),
                         [batch_size, num_classes]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:15,代碼來源:inception_v3_test.py

示例13: testRaiseValueErrorWithInvalidDepthMultiplier

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testRaiseValueErrorWithInvalidDepthMultiplier(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000

    inputs = tf.random_uniform((batch_size, height, width, 3))
    with self.assertRaises(ValueError):
      _ = inception.inception_v3(inputs, num_classes, depth_multiplier=-0.1)
    with self.assertRaises(ValueError):
      _ = inception.inception_v3(inputs, num_classes, depth_multiplier=0.0) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:12,代碼來源:inception_v3_test.py

示例14: testEvaluation

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testEvaluation(self):
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000

    eval_inputs = tf.random_uniform((batch_size, height, width, 3))
    logits, _ = inception.inception_v3(eval_inputs, num_classes,
                                       is_training=False)
    predictions = tf.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (batch_size,)) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:inception_v3_test.py

示例15: testLogitsNotSqueezed

# 需要導入模塊: from tensorflow.contrib.slim.nets import inception [as 別名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 別名]
def testLogitsNotSqueezed(self):
    num_classes = 25
    images = tf.random_uniform([1, 299, 299, 3])
    logits, _ = inception.inception_v3(images,
                                       num_classes=num_classes,
                                       spatial_squeeze=False)

    with self.test_session() as sess:
      tf.global_variables_initializer().run()
      logits_out = sess.run(logits)
      self.assertListEqual(list(logits_out.shape), [1, 1, 1, num_classes]) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:13,代碼來源:inception_v3_test.py


注:本文中的tensorflow.contrib.slim.nets.inception.inception_v3方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。