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


Python image_ops.decode_jpeg函数代码示例

本文整理汇总了Python中tensorflow.python.ops.image_ops.decode_jpeg函数的典型用法代码示例。如果您正苦于以下问题:Python decode_jpeg函数的具体用法?Python decode_jpeg怎么用?Python decode_jpeg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: testExisting

 def testExisting(self):
     # Read a real jpeg and verify shape
     path = "tensorflow/core/lib/jpeg/testdata/" "jpeg_merge_test1.jpg"
     with self.test_session() as sess:
         jpeg0 = io_ops.read_file(path)
         image0 = image_ops.decode_jpeg(jpeg0)
         image1 = image_ops.decode_jpeg(image_ops.encode_jpeg(image0))
         jpeg0, image0, image1 = sess.run([jpeg0, image0, image1])
         self.assertEqual(len(jpeg0), 3771)
         self.assertEqual(image0.shape, (256, 128, 3))
         self.assertLess(self.averageError(image0, image1), 0.8)
开发者ID:sarvex,项目名称:tensorflow,代码行数:11,代码来源:image_ops_test.py

示例2: _evalDecodeJpeg

  def _evalDecodeJpeg(self, image_name, parallelism, num_iters, tile=None):
    """Evaluate DecodeJpegOp for the given image.

    TODO(tanmingxing): add decoding+cropping as well.

    Args:
      image_name: a string of image file name (without suffix).
      parallelism: the number of concurrent decode_jpeg ops to be run.
      num_iters: number of iterations for evaluation.
      tile: if not None, tile the image to composite a larger fake image.

    Returns:
      The duration of the run in seconds.
    """
    ops.reset_default_graph()

    image_file_path = os.path.join(prefix_path, image_name)

    if tile is None:
      image_content = variable_scope.get_variable(
          'image_%s' % image_name,
          initializer=io_ops.read_file(image_file_path))
    else:
      single_image = image_ops.decode_jpeg(
          io_ops.read_file(image_file_path), channels=3, name='single_image')
      # Tile the image to composite a new larger image.
      tiled_image = array_ops.tile(single_image, tile)
      image_content = variable_scope.get_variable(
          'tiled_image_%s' % image_name,
          initializer=image_ops.encode_jpeg(tiled_image))

    with session.Session() as sess:
      sess.run(variables.global_variables_initializer())
      images = []
      for i in xrange(parallelism):
        images.append(
            image_ops.decode_jpeg(
                image_content, channels=3, name='image_%d' % (i)))

      r = control_flow_ops.group(*images)

      for _ in xrange(3):
        # Skip warm up time.
        sess.run(r)

      start_time = time.time()
      for _ in xrange(num_iters):
        sess.run(r)
    return time.time() - start_time
开发者ID:chdinh,项目名称:tensorflow,代码行数:49,代码来源:decode_jpeg_op_test.py

示例3: testCmyk

 def testCmyk(self):
     # Confirm that CMYK reads in as RGB
     base = "tensorflow/core/lib/jpeg/testdata"
     rgb_path = os.path.join(base, "jpeg_merge_test1.jpg")
     cmyk_path = os.path.join(base, "jpeg_merge_test1_cmyk.jpg")
     shape = 256, 128, 3
     for channels in 3, 0:
         with self.test_session() as sess:
             rgb = image_ops.decode_jpeg(io_ops.read_file(rgb_path), channels=channels)
             cmyk = image_ops.decode_jpeg(io_ops.read_file(cmyk_path), channels=channels)
             rgb, cmyk = sess.run([rgb, cmyk])
             self.assertEqual(rgb.shape, shape)
             self.assertEqual(cmyk.shape, shape)
             error = self.averageError(rgb, cmyk)
             self.assertLess(error, 4)
开发者ID:texttheater,项目名称:tensorflow,代码行数:15,代码来源:image_ops_test.py

示例4: testShape

 def testShape(self):
   with self.test_session() as sess:
     jpeg = constant_op.constant('nonsense')
     for channels in 0, 1, 3:
       image = image_ops.decode_jpeg(jpeg, channels=channels)
       self.assertEqual(image.get_shape().as_list(),
                        [None, None, channels or None])
开发者ID:hbali-sara,项目名称:tensorflow,代码行数:7,代码来源:image_ops_test.py

示例5: decode_jpeg

 def decode_jpeg():
   """Decodes a jpeg image with specified '_dct_method'."""
   return math_ops.cast(
       image_ops.decode_jpeg(
           image_buffer,
           channels=self._channels,
           dct_method=self._dct_method), self._dtype)
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:7,代码来源:tfexample_decoder.py

示例6: testSynthetic

  def testSynthetic(self):
    with self.test_session() as sess:
      # Encode it, then decode it, then encode it
      image0 = constant_op.constant(_SimpleColorRamp())
      jpeg0 = image_ops.encode_jpeg(image0)
      image1 = image_ops.decode_jpeg(jpeg0)
      image2 = image_ops.decode_jpeg(image_ops.encode_jpeg(image1))
      jpeg0, image0, image1, image2 = sess.run([jpeg0, image0, image1, image2])

      # The decoded-encoded image should be similar to the input
      self.assertLess(self.averageError(image0, image1), 0.6)

      # We should be very close to a fixpoint
      self.assertLess(self.averageError(image1, image2), 0.02)

      # Smooth ramps compress well (input size is 153600)
      self.assertGreaterEqual(len(jpeg0), 5000)
      self.assertLessEqual(len(jpeg0), 6000)
开发者ID:hbali-sara,项目名称:tensorflow,代码行数:18,代码来源:image_ops_test.py

示例7: testJpeg

 def testJpeg(self):
   # Read a real jpeg and verify shape
   path = os.path.join(prefix_path, "jpeg", "testdata", "jpeg_merge_test1.jpg")
   with self.test_session(use_gpu=True) as sess:
     jpeg0 = io_ops.read_file(path)
     image0 = image_ops.decode_image(jpeg0)
     image1 = image_ops.decode_jpeg(jpeg0)
     jpeg0, image0, image1 = sess.run([jpeg0, image0, image1])
     self.assertEqual(len(jpeg0), 3771)
     self.assertEqual(image0.shape, (256, 128, 3))
     self.assertAllEqual(image0, image1)
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:11,代码来源:decode_image_op_test.py

示例8: testJpeg

  def testJpeg(self):
    # Read a real jpeg and verify shape
    path = os.path.join(prefix_path, "jpeg", "testdata", "jpeg_merge_test1.jpg")
    with self.session(use_gpu=True) as sess:
      jpeg0 = io_ops.read_file(path)
      image0 = image_ops.decode_image(jpeg0)
      image1 = image_ops.decode_jpeg(jpeg0)
      jpeg0, image0, image1 = self.evaluate([jpeg0, image0, image1])
      self.assertEqual(len(jpeg0), 3771)
      self.assertEqual(image0.shape, (256, 128, 3))
      self.assertAllEqual(image0, image1)

      bad_channels = image_ops.decode_image(jpeg0, channels=4)
      with self.assertRaises(errors_impl.InvalidArgumentError):
        self.evaluate(bad_channels)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:15,代码来源:decode_image_op_test.py

示例9: decode_jpg

 def decode_jpg():
   return image_ops.decode_jpeg(image_buffer, self._channels)
开发者ID:821760408-sp,项目名称:tensorflow,代码行数:2,代码来源:tfexample_decoder.py

示例10: DecodeJpg

 def DecodeJpg():
   return image_ops.decode_jpeg(image_buffer, 3)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:2,代码来源:tfexample_decoder_test.py

示例11: _evalDecodeJpeg

  def _evalDecodeJpeg(self,
                      image_name,
                      parallelism,
                      num_iters,
                      crop_during_decode=None,
                      crop_window=None,
                      tile=None):
    """Evaluate DecodeJpegOp for the given image.

    TODO(tanmingxing): add decoding+cropping as well.

    Args:
      image_name: a string of image file name (without suffix).
      parallelism: the number of concurrent decode_jpeg ops to be run.
      num_iters: number of iterations for evaluation.
      crop_during_decode: If true, use fused DecodeAndCropJpeg instead of
          separate decode and crop ops. It is ignored if crop_window is None.
      crop_window: if not None, crop the decoded image. Depending on
          crop_during_decode, cropping could happen during or after decoding.
      tile: if not None, tile the image to composite a larger fake image.

    Returns:
      The duration of the run in seconds.
    """
    ops.reset_default_graph()

    image_file_path = os.path.join(prefix_path, image_name)

    if tile is None:
      image_content = variable_scope.get_variable(
          'image_%s' % image_name,
          initializer=io_ops.read_file(image_file_path))
    else:
      single_image = image_ops.decode_jpeg(
          io_ops.read_file(image_file_path), channels=3, name='single_image')
      # Tile the image to composite a new larger image.
      tiled_image = array_ops.tile(single_image, tile)
      image_content = variable_scope.get_variable(
          'tiled_image_%s' % image_name,
          initializer=image_ops.encode_jpeg(tiled_image))

    with session.Session() as sess:
      sess.run(variables.global_variables_initializer())
      images = []
      for _ in xrange(parallelism):
        if crop_window is None:
          # No crop.
          image = image_ops.decode_jpeg(image_content, channels=3)
        elif crop_during_decode:
          # combined decode and crop.
          image = image_ops.decode_and_crop_jpeg(
              image_content, crop_window, channels=3)
        else:
          # separate decode and crop.
          image = image_ops.decode_jpeg(image_content, channels=3)
          image = image_ops.crop_to_bounding_box(
              image,
              offset_height=crop_window[0],
              offset_width=crop_window[1],
              target_height=crop_window[2],
              target_width=crop_window[3])

        images.append(image)
      r = control_flow_ops.group(*images)

      for _ in xrange(3):
        # Skip warm up time.
        sess.run(r)

      start_time = time.time()
      for _ in xrange(num_iters):
        sess.run(r)
    return time.time() - start_time
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:73,代码来源:decode_jpeg_op_test.py

示例12: decode_jpg

 def decode_jpg():
   if self._dtype != dtypes.uint8:
     raise ValueError(
         'jpeg decoder can only be used to decode to tf.uint8 but %s was '
         'requested for a jpeg image.' % self._dtype)
   return image_ops.decode_jpeg(image_buffer, self._channels)
开发者ID:LUTAN,项目名称:tensorflow,代码行数:6,代码来源:tfexample_decoder.py


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