本文整理汇总了Python中networks.compression_model方法的典型用法代码示例。如果您正苦于以下问题:Python networks.compression_model方法的具体用法?Python networks.compression_model怎么用?Python networks.compression_model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networks
的用法示例。
在下文中一共展示了networks.compression_model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import networks [as 别名]
# 或者: from networks import compression_model [as 别名]
def main(_, run_eval_loop=True):
with tf.name_scope('inputs'):
images = data_provider.provide_data(
'validation', FLAGS.batch_size, dataset_dir=FLAGS.dataset_dir,
patch_size=FLAGS.patch_size)
# In order for variables to load, use the same variable scope as in the
# train job.
with tf.variable_scope('generator'):
reconstructions, _, prebinary = networks.compression_model(
images,
num_bits=FLAGS.bits_per_patch,
depth=FLAGS.model_depth,
is_training=False)
summaries.add_reconstruction_summaries(images, reconstructions, prebinary)
# Visualize losses.
pixel_loss_per_example = tf.reduce_mean(
tf.abs(images - reconstructions), axis=[1, 2, 3])
pixel_loss = tf.reduce_mean(pixel_loss_per_example)
tf.summary.histogram('pixel_l1_loss_hist', pixel_loss_per_example)
tf.summary.scalar('pixel_l1_loss', pixel_loss)
# Create ops to write images to disk.
uint8_images = data_provider.float_image_to_uint8(images)
uint8_reconstructions = data_provider.float_image_to_uint8(reconstructions)
uint8_reshaped = summaries.stack_images(uint8_images, uint8_reconstructions)
image_write_ops = tf.write_file(
'%s/%s'% (FLAGS.eval_dir, 'compression.png'),
tf.image.encode_png(uint8_reshaped[0]))
# For unit testing, use `run_eval_loop=False`.
if not run_eval_loop: return
tf.contrib.training.evaluate_repeatedly(
FLAGS.checkpoint_dir,
master=FLAGS.master,
hooks=[tf.contrib.training.SummaryAtEndHook(FLAGS.eval_dir),
tf.contrib.training.StopAfterNEvalsHook(1)],
eval_ops=image_write_ops,
max_number_of_evaluations=FLAGS.max_number_of_evaluations)
示例2: test_generator_run
# 需要导入模块: import networks [as 别名]
# 或者: from networks import compression_model [as 别名]
def test_generator_run(self):
img_batch = tf.zeros([3, 16, 16, 3])
model_output = networks.compression_model(img_batch)
with self.test_session() as sess:
sess.run(tf.global_variables_initializer())
sess.run(model_output)
示例3: test_generator_graph
# 需要导入模块: import networks [as 别名]
# 或者: from networks import compression_model [as 别名]
def test_generator_graph(self):
for i, batch_size in zip(xrange(3, 7), xrange(3, 11, 2)):
tf.reset_default_graph()
patch_size = 2 ** i
bits = 2 ** i
img = tf.ones([batch_size, patch_size, patch_size, 3])
uncompressed, binary_codes, prebinary = networks.compression_model(
img, bits)
self.assertAllEqual([batch_size, patch_size, patch_size, 3],
uncompressed.shape.as_list())
self.assertEqual([batch_size, bits], binary_codes.shape.as_list())
self.assertEqual([batch_size, bits], prebinary.shape.as_list())
示例4: test_generator_invalid_input
# 需要导入模块: import networks [as 别名]
# 或者: from networks import compression_model [as 别名]
def test_generator_invalid_input(self):
wrong_dim_input = tf.zeros([5, 32, 32])
with self.assertRaisesRegexp(ValueError, 'Shape .* must have rank 4'):
networks.compression_model(wrong_dim_input)
not_fully_defined = tf.placeholder(tf.float32, [3, None, 32, 3])
with self.assertRaisesRegexp(ValueError, 'Shape .* is not fully defined'):
networks.compression_model(not_fully_defined)
示例5: test_discriminator_invalid_input
# 需要导入模块: import networks [as 别名]
# 或者: from networks import compression_model [as 别名]
def test_discriminator_invalid_input(self):
wrong_dim_input = tf.zeros([5, 32, 32])
with self.assertRaisesRegexp(ValueError, 'Shape must be rank 4'):
networks.discriminator(wrong_dim_input)
not_fully_defined = tf.placeholder(tf.float32, [3, None, 32, 3])
with self.assertRaisesRegexp(ValueError, 'Shape .* is not fully defined'):
networks.compression_model(not_fully_defined)