Python networks.compression_model() Examples

The following are 25 code examples of networks.compression_model(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module networks , or try the search function .
Example #1
Source File: networks_test.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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()) 
Example #2
Source File: networks_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
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) 
Example #3
Source File: networks_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
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) 
Example #4
Source File: networks_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
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()) 
Example #5
Source File: networks_test.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
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) 
Example #6
Source File: eval.py    From multilabel-image-classification-tensorflow with MIT License 5 votes vote down vote up
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) 
Example #7
Source File: networks_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
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) 
Example #8
Source File: networks_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
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) 
Example #9
Source File: networks_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
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()) 
Example #10
Source File: networks_test.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
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) 
Example #11
Source File: eval.py    From g-tensorflow-models with Apache License 2.0 5 votes vote down vote up
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) 
Example #12
Source File: networks_test.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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) 
Example #13
Source File: networks_test.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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) 
Example #14
Source File: eval.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: networks_test.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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) 
Example #16
Source File: eval.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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) 
Example #17
Source File: networks_test.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
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) 
Example #18
Source File: networks_test.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
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) 
Example #19
Source File: networks_test.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
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()) 
Example #20
Source File: networks_test.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
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) 
Example #21
Source File: eval.py    From Gun-Detector with Apache License 2.0 5 votes vote down vote up
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) 
Example #22
Source File: networks_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #23
Source File: networks_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #24
Source File: networks_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
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()) 
Example #25
Source File: networks_test.py    From yolo_v2 with Apache License 2.0 5 votes vote down vote up
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)