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


Python inception.inception_v3_arg_scope方法代碼示例

本文整理匯總了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 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:19,代碼來源:test_imagenet_attacks.py

示例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 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:25,代碼來源:model.py

示例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 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:27,代碼來源:model.py

示例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)) 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:26,代碼來源:eval_on_adversarial.py

示例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 
開發者ID:scotthuang1989,項目名稱:object_detection_with_tensorflow,代碼行數:27,代碼來源:model.py

示例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 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:14,代碼來源:attack_fgsm.py

示例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)) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:31,代碼來源:defense.py

示例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'] 
開發者ID:evtimovi,項目名稱:robust_physical_perturbations,代碼行數:16,代碼來源:attack.py

示例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) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:11,代碼來源:inception_v3_test.py

示例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 
開發者ID:cihangxie,項目名稱:DI-2-FGSM,代碼行數:30,代碼來源:attack.py

示例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 
開發者ID:wenxichen,項目名稱:tensorflow_yolo2,代碼行數:13,代碼來源:imagenet_train_inception_resnet.py

示例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 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:14,代碼來源:attack_fgsm.py

示例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)) 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:32,代碼來源:defense.py

示例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)) 
開發者ID:tensorflow,項目名稱:cleverhans,代碼行數:31,代碼來源:defense.py

示例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) 
開發者ID:StephanZheng,項目名稱:neural-fingerprinting,代碼行數:53,代碼來源:attack_step_target_class.py


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