本文整理匯總了Python中tensorflow.python.ops.image_ops.encode_jpeg方法的典型用法代碼示例。如果您正苦於以下問題:Python image_ops.encode_jpeg方法的具體用法?Python image_ops.encode_jpeg怎麽用?Python image_ops.encode_jpeg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.ops.image_ops
的用法示例。
在下文中一共展示了image_ops.encode_jpeg方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testSynthetic
# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_jpeg [as 別名]
def testSynthetic(self):
with self.test_session(use_gpu=True) 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)
示例2: _encoder
# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_jpeg [as 別名]
def _encoder(image, image_format):
assert image_format in ['jpeg', 'png']
if image_format == 'jpeg':
tf_image = constant_op.constant(image, dtype=dtypes.uint8)
return image_ops.encode_jpeg(tf_image)
if image_format == 'png':
tf_image = constant_op.constant(image, dtype=dtypes.uint8)
return image_ops.encode_png(tf_image)
示例3: _Encoder
# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_jpeg [as 別名]
def _Encoder(self, image, image_format):
assert image_format in ['jpeg', 'JPEG', 'png', 'PNG', 'raw', 'RAW']
if image_format in ['jpeg', 'JPEG']:
tf_image = constant_op.constant(image, dtype=dtypes.uint8)
return image_ops.encode_jpeg(tf_image)
if image_format in ['png', 'PNG']:
tf_image = constant_op.constant(image, dtype=dtypes.uint8)
return image_ops.encode_png(tf_image)
if image_format in ['raw', 'RAW']:
return constant_op.constant(image.tostring(), dtype=dtypes.string)
示例4: _Encoder
# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_jpeg [as 別名]
def _Encoder(self, image, image_format):
assert image_format in ['jpeg', 'JPEG', 'png', 'PNG', 'raw', 'RAW']
if image_format in ['jpeg', 'JPEG']:
tf_image = tf.constant(image, dtype=tf.uint8)
return image_ops.encode_jpeg(tf_image)
if image_format in ['png', 'PNG']:
tf_image = tf.constant(image, dtype=tf.uint8)
return image_ops.encode_png(tf_image)
if image_format in ['raw', 'RAW']:
# If machine is big endian, change the byte ordering in case of dtype
# float32 so that it should be interpreted correctly.
if image.dtype == np.float32 and sys.byteorder == 'big':
image = image.astype('<f4')
return tf.constant(image.tostring(), dtype=tf.string)
示例5: testExisting
# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_jpeg [as 別名]
def testExisting(self):
# Read a real jpeg and verify shape
path = ('tensorflow/core/lib/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_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)