当前位置: 首页>>代码示例>>Python>>正文


Python networks.generator方法代码示例

本文整理汇总了Python中networks.generator方法的典型用法代码示例。如果您正苦于以下问题:Python networks.generator方法的具体用法?Python networks.generator怎么用?Python networks.generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networks的用法示例。


在下文中一共展示了networks.generator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_generated_data

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _get_generated_data(num_images_generated, conditional_eval, num_classes):
  """Get generated images."""
  noise = tf.random_normal([num_images_generated, 64])
  # If conditional, generate class-specific images.
  if conditional_eval:
    conditioning = util.get_generator_conditioning(
        num_images_generated, num_classes)
    generator_inputs = (noise, conditioning)
    generator_fn = networks.conditional_generator
  else:
    generator_inputs = noise
    generator_fn = networks.generator
  # In order for variables to load, use the same variable scope as in the
  # train job.
  with tf.variable_scope('Generator'):
    data = generator_fn(generator_inputs)

  return data 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:20,代码来源:eval.py

示例2: _get_generated_data

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _get_generated_data(num_images_generated, conditional_eval, num_classes):
  """Get generated images."""
  noise = tf.random_normal([num_images_generated, 64])
  # If conditional, generate class-specific images.
  if conditional_eval:
    conditioning = util.get_generator_conditioning(
        num_images_generated, num_classes)
    generator_inputs = (noise, conditioning)
    generator_fn = networks.conditional_generator
  else:
    generator_inputs = noise
    generator_fn = networks.generator
  # In order for variables to load, use the same variable scope as in the
  # train job.
  with tf.variable_scope('Generator'):
    data = generator_fn(generator_inputs, is_training=False)

  return data 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:20,代码来源:eval.py

示例3: _define_model

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _define_model(images_x, images_y):
  """Defines a CycleGAN model that maps between images_x and images_y.

  Args:
    images_x: A 4D float `Tensor` of NHWC format.  Images in set X.
    images_y: A 4D float `Tensor` of NHWC format.  Images in set Y.

  Returns:
    A `CycleGANModel` namedtuple.
  """
  cyclegan_model = tfgan.cyclegan_model(
      generator_fn=networks.generator,
      discriminator_fn=networks.discriminator,
      data_x=images_x,
      data_y=images_y)

  # Add summaries for generated images.
  tfgan.eval.add_image_comparison_summaries(
      cyclegan_model, num_comparisons=3, display_diffs=False)
  tfgan.eval.add_gan_model_image_summaries(
      cyclegan_model, grid_size=int(np.sqrt(FLAGS.batch_size)))

  return cyclegan_model 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:25,代码来源:train.py

示例4: _get_optimizer

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _get_optimizer(gen_lr, dis_lr):
  """Returns generator optimizer and discriminator optimizer.

  Args:
    gen_lr: A scalar float `Tensor` or a Python number.  The Generator learning
        rate.
    dis_lr: A scalar float `Tensor` or a Python number.  The Discriminator
        learning rate.

  Returns:
    A tuple of generator optimizer and discriminator optimizer.
  """
  # beta1 follows
  # https://github.com/junyanz/CycleGAN/blob/master/options.lua
  gen_opt = tf.train.AdamOptimizer(gen_lr, beta1=0.5, use_locking=True)
  dis_opt = tf.train.AdamOptimizer(dis_lr, beta1=0.5, use_locking=True)
  return gen_opt, dis_opt 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:19,代码来源:train.py

示例5: make_inference_graph

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def make_inference_graph(model_name, patch_dim):
  """Build the inference graph for either the X2Y or Y2X GAN.

  Args:
    model_name: The var scope name 'ModelX2Y' or 'ModelY2X'.
    patch_dim: An integer size of patches to feed to the generator.

  Returns:
    Tuple of (input_placeholder, generated_tensor).
  """
  input_hwc_pl = tf.placeholder(tf.float32, [None, None, 3])

  # Expand HWC to NHWC
  images_x = tf.expand_dims(
      data_provider.full_image_to_patch(input_hwc_pl, patch_dim), 0)

  with tf.variable_scope(model_name):
    with tf.variable_scope('Generator'):
      generated = networks.generator(images_x)
  return input_hwc_pl, generated 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:22,代码来源:inference_demo.py

示例6: _define_model

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _define_model(images_x, images_y):
  """Defines a CycleGAN model that maps between images_x and images_y.

  Args:
    images_x: A 4D float `Tensor` of NHWC format.  Images in set X.
    images_y: A 4D float `Tensor` of NHWC format.  Images in set Y.

  Returns:
    A `CycleGANModel` namedtuple.
  """
  cyclegan_model = tfgan.cyclegan_model(
      generator_fn=networks.generator,
      discriminator_fn=networks.discriminator,
      data_x=images_x,
      data_y=images_y)

  # Add summaries for generated images.
  tfgan.eval.add_cyclegan_image_summaries(cyclegan_model)

  return cyclegan_model 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:22,代码来源:train.py

示例7: define_train_ops

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def define_train_ops(gan_model, gan_loss, **kwargs):
  """Defines progressive GAN train ops.

  Args:
    gan_model: A `GANModel` namedtuple.
    gan_loss: A `GANLoss` namedtuple.
    **kwargs: A dictionary of
        'adam_beta1': A float of Adam optimizer beta1.
        'adam_beta2': A float of Adam optimizer beta2.
        'generator_learning_rate': A float of generator learning rate.
        'discriminator_learning_rate': A float of discriminator learning rate.

  Returns:
    A tuple of `GANTrainOps` namedtuple and a list variables tracking the state
    of optimizers.
  """
  with tf.variable_scope('progressive_gan_train_ops') as var_scope:
    beta1, beta2 = kwargs['adam_beta1'], kwargs['adam_beta2']
    gen_opt = tf.train.AdamOptimizer(kwargs['generator_learning_rate'], beta1,
                                     beta2)
    dis_opt = tf.train.AdamOptimizer(kwargs['discriminator_learning_rate'],
                                     beta1, beta2)
    gan_train_ops = tfgan.gan_train_ops(gan_model, gan_loss, gen_opt, dis_opt)
  return gan_train_ops, tf.get_collection(
      tf.GraphKeys.GLOBAL_VARIABLES, scope=var_scope.name) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:27,代码来源:train.py

示例8: generate_fixed_z

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def generate_fixed_z():
    label = tf.placeholder(tf.float32, [None, NUMS_CLASS])
    z = tf.placeholder(tf.float32, [None, 100])
    labeled_z = tf.concat([z, label], axis=1)
    G = generator("generator")
    fake_img = G(labeled_z)
    sess = tf.Session()
    sess.run(tf.global_variables_initializer())
    saver = tf.train.Saver()
    saver.restore(sess, "./save_para/model.ckpt")


    LABELS, Z = label_from_0_to_1()
    if not os.path.exists("./generate_fixed_noise"):
        os.mkdir("./generate_fixed_noise")
    FAKE_IMG = sess.run(fake_img, feed_dict={label: LABELS, z: Z})
    for i in range(10):
        Image.fromarray(np.uint8((FAKE_IMG[i, :, :, :] + 1) * 127.5)).save("./generate_fixed_noise/" + str(i) + ".jpg") 
开发者ID:MingtaoGuo,项目名称:DCGAN_WGAN_WGAN-GP_LSGAN_SNGAN_RSGAN_BEGAN_ACGAN_PGGAN_TensorFlow,代码行数:20,代码来源:generate.py

示例9: generate_fixed_label

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def generate_fixed_label():
    label = tf.placeholder(tf.int32, [None])
    z = tf.placeholder(tf.float32, [None, 100])
    one_hot_label = tf.one_hot(label, NUMS_CLASS)
    labeled_z = tf.concat([z, one_hot_label], axis=1)
    G = generator("generator")
    fake_img = G(labeled_z)
    sess = tf.Session()
    sess.run(tf.global_variables_initializer())
    saver = tf.train.Saver()
    saver.restore(sess, "./save_para/model.ckpt")

    Z = from_noise0_to_noise1()
    LABELS = np.ones([10])#woman: LABELS = np.ones([10]), man: LABELS = np.zeros([10])
    if not os.path.exists("./generate_fixed_label"):
        os.mkdir("./generate_fixed_label")
    FAKE_IMG = sess.run(fake_img, feed_dict={label: LABELS, z: Z})
    for i in range(10):
        Image.fromarray(np.uint8((FAKE_IMG[i, :, :, :] + 1) * 127.5)).save("./generate_fixed_label/" + str(i) + "_" + str(int(LABELS[i])) + ".jpg") 
开发者ID:MingtaoGuo,项目名称:DCGAN_WGAN_WGAN-GP_LSGAN_SNGAN_RSGAN_BEGAN_ACGAN_PGGAN_TensorFlow,代码行数:21,代码来源:generate.py

示例10: test_generator

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def test_generator(self):
    tf.set_random_seed(1234)
    batch_size = 100
    noise = tf.random_normal([batch_size, 64])
    image = networks.generator(noise)
    with self.test_session(use_gpu=True) as sess:
      sess.run(tf.global_variables_initializer())
      image_np = image.eval()

    self.assertAllEqual([batch_size, 32, 32, 3], image_np.shape)
    self.assertTrue(np.all(np.abs(image_np) <= 1)) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:13,代码来源:networks_test.py

示例11: test_generator_graph

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def test_generator_graph(self):
    for shape in ([4, 32, 32], [3, 128, 128], [2, 80, 400]):
      tf.reset_default_graph()
      img = tf.ones(shape + [3])
      output_imgs = networks.generator(img)

      self.assertAllEqual(shape + [3], output_imgs.shape.as_list()) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:9,代码来源:networks_test.py

示例12: test_generator_graph_unknown_batch_dim

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def test_generator_graph_unknown_batch_dim(self):
    img = tf.placeholder(tf.float32, shape=[None, 32, 32, 3])
    output_imgs = networks.generator(img)

    self.assertAllEqual([None, 32, 32, 3], output_imgs.shape.as_list()) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:7,代码来源:networks_test.py

示例13: test_generator_invalid_input

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def test_generator_invalid_input(self):
    with self.assertRaisesRegexp(ValueError, 'must have rank 4'):
      networks.generator(tf.zeros([28, 28, 3])) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:5,代码来源:networks_test.py

示例14: _lr

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def _lr(gen_lr_base, dis_lr_base):
  """Return the generator and discriminator learning rates."""
  gen_lr = tf.train.exponential_decay(
      learning_rate=gen_lr_base,
      global_step=tf.train.get_or_create_global_step(),
      decay_steps=100000,
      decay_rate=0.8,
      staircase=True,)
  dis_lr = dis_lr_base

  return gen_lr, dis_lr 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:13,代码来源:train.py

示例15: test_generator_run_multi_channel

# 需要导入模块: import networks [as 别名]
# 或者: from networks import generator [as 别名]
def test_generator_run_multi_channel(self):
    img_batch = tf.zeros([3, 128, 128, 5])
    model_output = networks.generator(img_batch)
    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      sess.run(model_output) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:8,代码来源:networks_test.py


注:本文中的networks.generator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。