本文整理汇总了Python中tensorflow.python.ops.image_ops.decode_png函数的典型用法代码示例。如果您正苦于以下问题:Python decode_png函数的具体用法?Python decode_png怎么用?Python decode_png使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decode_png函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testExisting
def testExisting(self):
# Read some real PNGs, converting to different channel numbers
prefix = 'tensorflow/core/lib/png/testdata/'
inputs = (1, 'lena_gray.png'), (4, 'lena_rgba.png')
for channels_in, filename in inputs:
for channels in 0, 1, 3, 4:
with self.test_session() as sess:
png0 = io_ops.read_file(prefix + filename)
image0 = image_ops.decode_png(png0, channels=channels)
png0, image0 = sess.run([png0, image0])
self.assertEqual(image0.shape, (26, 51, channels or channels_in))
if channels == channels_in:
image1 = image_ops.decode_png(image_ops.encode_png(image0))
self.assertAllEqual(image0, image1.eval())
开发者ID:hbali-sara,项目名称:tensorflow,代码行数:14,代码来源:image_ops_test.py
示例2: testImageSummaryUint8
def testImageSummaryUint8(self):
np.random.seed(7)
with self.test_session() as sess:
for depth in 1, 3, 4:
shape = (4, 5, 7) + (depth,)
# Build a random uint8 image
images = np.random.randint(256, size=shape).astype(np.uint8)
tf_images = tf.convert_to_tensor(images)
self.assertEqual(tf_images.dtype, tf.uint8)
# Summarize
summ = tf.image_summary("img", tf_images)
value = sess.run(summ)
self.assertEqual([], summ.get_shape())
image_summ = self._AsSummary(value)
# Decode the first image and check consistency.
# Since we're uint8, everything should be exact.
image = image_ops.decode_png(
image_summ.value[0].image.encoded_image_string).eval()
self.assertAllEqual(image, images[0])
# Check the rest of the proto
self._CheckProto(image_summ, shape)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:25,代码来源:summary_image_op_test.py
示例3: testImageSummary
def testImageSummary(self):
np.random.seed(7)
with self.test_session() as sess:
for depth in 1, 3, 4:
shape = (4, 5, 7) + (depth,)
bad_color = [255, 0, 0, 255][:depth]
for positive in False, True:
# Build a mostly random image with one nan
const = np.random.randn(*shape).astype(np.float32)
const[0, 1, 2] = 0 # Make the nan entry not the max
if positive:
const = 1 + np.maximum(const, 0)
scale = 255 / const.reshape(4, -1).max(axis=1)
offset = 0
else:
scale = 127 / np.abs(const.reshape(4, -1)).max(axis=1)
offset = 128
adjusted = np.floor(scale[:, None, None, None] * const + offset)
const[0, 1, 2, depth // 2] = np.nan
# Summarize
summ = tf.image_summary("img", const)
value = sess.run(summ)
self.assertEqual([], summ.get_shape())
image_summ = self._AsSummary(value)
# Decode the first image and check consistency
image = image_ops.decode_png(
image_summ.value[0].image.encoded_image_string).eval()
self.assertAllEqual(image[1, 2], bad_color)
image[1, 2] = adjusted[0, 1, 2]
self.assertAllClose(image, adjusted[0])
# Check the rest of the proto
self._CheckProto(image_summ, shape)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:35,代码来源:summary_image_op_test.py
示例4: testShape
def testShape(self):
with self.test_session() as sess:
png = constant_op.constant('nonsense')
for channels in 0, 1, 3:
image = image_ops.decode_png(png, channels=channels)
self.assertEqual(image.get_shape().as_list(),
[None, None, channels or None])
开发者ID:hbali-sara,项目名称:tensorflow,代码行数:7,代码来源:image_ops_test.py
示例5: testSyntheticTwoChannelUint16
def testSyntheticTwoChannelUint16(self):
with self.test_session() as sess:
# Strip the b channel from an rgb image to get a two-channel image.
gray_alpha = _SimpleColorRamp()[:, :, 0:2]
image0 = constant_op.constant(gray_alpha, dtype=dtypes.uint16)
png0 = image_ops.encode_png(image0, compression=7)
image1 = image_ops.decode_png(png0, dtype=dtypes.uint16)
png0, image0, image1 = sess.run([png0, image0, image1])
self.assertEqual(2, image0.shape[-1])
self.assertAllEqual(image0, image1)
开发者ID:0-T-0,项目名称:tensorflow,代码行数:10,代码来源:image_ops_test.py
示例6: testEndpointsTensorAndMetadataAssets
def testEndpointsTensorAndMetadataAssets(self):
g = ops.Graph()
with g.as_default():
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
metadata = projector_plugin.EmbeddingMetadata(3)
metadata.add_column('labels', ['a', 'b', 'c'])
manager.add_metadata_for_embedding_variable('test', metadata)
expected_tensor = np.array([[1, 2], [3, 4], [5, 6]])
image1 = np.array([[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]])
image2 = np.array([[[10, 20, 30], [40, 50, 60]],
[[70, 80, 90], [100, 110, 120]]])
manager.add_embedding('emb', expected_tensor, metadata, [image1, image2],
[2, 2])
fw = writer.FileWriter(self.log_dir, graph=g)
fw.close()
self._SetupWSGIApp()
run_json = self._GetJson('/data/plugin/projector/runs')
self.assertTrue(run_json)
run = run_json[0]
metadata_query = '/data/plugin/projector/metadata?run=%s&name=emb' % run
metadata_tsv = self._Get(metadata_query).data
self.assertEqual(metadata_tsv, b'a\nb\nc\n')
unk_metadata_query = '/data/plugin/projector/metadata?run=%s&name=q' % run
response = self._Get(unk_metadata_query)
self.assertEqual(response.status_code, 400)
tensor_query = '/data/plugin/projector/tensor?run=%s&name=emb' % run
tensor_bytes = self._Get(tensor_query).data
self._AssertTensorResponse(tensor_bytes, expected_tensor)
unk_tensor_query = '/data/plugin/projector/tensor?run=%s&name=var1' % run
response = self._Get(unk_tensor_query)
self.assertEqual(response.status_code, 400)
image_query = '/data/plugin/projector/sprite_image?run=%s&name=emb' % run
image_bytes = self._Get(image_query).data
with ops.Graph().as_default():
s = session.Session()
image_array = image_ops.decode_png(image_bytes).eval(session=s).tolist()
expected_sprite_image = [
[[1, 2, 3], [4, 5, 6], [10, 20, 30], [40, 50, 60]],
[[7, 8, 9], [10, 11, 12], [70, 80, 90], [100, 110, 120]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
]
self.assertEqual(image_array, expected_sprite_image)
开发者ID:chenjun0210,项目名称:tensorflow,代码行数:53,代码来源:projector_plugin_test.py
示例7: testPng
def testPng(self):
# Read some real PNGs, converting to different channel numbers
inputs = [(1, "lena_gray.png")]
for channels_in, filename in inputs:
for channels in 0, 1, 3, 4:
with self.cached_session(use_gpu=True) as sess:
path = os.path.join(prefix_path, "png", "testdata", filename)
png0 = io_ops.read_file(path)
image0 = image_ops.decode_image(png0, channels=channels)
image1 = image_ops.decode_png(png0, channels=channels)
png0, image0, image1 = self.evaluate([png0, image0, image1])
self.assertEqual(image0.shape, (26, 51, channels or channels_in))
self.assertAllEqual(image0, image1)
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:13,代码来源:decode_image_op_test.py
示例8: testSynthetic
def testSynthetic(self):
with self.test_session() as sess:
# Encode it, then decode it
image0 = constant_op.constant(_SimpleColorRamp())
png0 = image_ops.encode_png(image0, compression=7)
image1 = image_ops.decode_png(png0)
png0, image0, image1 = sess.run([png0, image0, image1])
# PNG is lossless
self.assertAllEqual(image0, image1)
# Smooth ramps compress well, but not too well
self.assertGreaterEqual(len(png0), 400)
self.assertLessEqual(len(png0), 750)
开发者ID:hbali-sara,项目名称:tensorflow,代码行数:14,代码来源:image_ops_test.py
示例9: testImageSummary
def testImageSummary(self):
np.random.seed(7)
with self.test_session() as sess:
for depth in 1, 3, 4:
shape = (4, 5, 7) + (depth,)
bad_color = [255, 0, 0, 255][:depth]
for positive in False, True:
# Build a mostly random image with one nan
const = np.random.randn(*shape)
const[0, 1, 2] = 0 # Make the nan entry not the max
if positive:
const = 1 + np.maximum(const, 0)
scale = 255 / const.reshape(4, -1).max(axis=1)
offset = 0
else:
scale = 127 / np.abs(const.reshape(4, -1)).max(axis=1)
offset = 128
adjusted = np.floor(scale[:, None, None, None] * const + offset)
const[0, 1, 2, depth // 2] = np.nan
# Summarize
summ = tf.image_summary("img", const)
value = sess.run(summ)
self.assertEqual([], summ.get_shape())
image_summ = self._AsSummary(value)
# Decode the first image and check consistency
image = image_ops.decode_png(image_summ.value[0].image.encoded_image_string).eval()
self.assertAllEqual(image[1, 2], bad_color)
image[1, 2] = adjusted[0, 1, 2]
self.assertAllClose(image, adjusted[0])
# Check the rest of the proto
# Only the first 3 images are returned.
for v in image_summ.value:
v.image.ClearField("encoded_image_string")
expected = "\n".join(
"""
value {
tag: "img/image/%d"
image { height: %d width: %d colorspace: %d }
}"""
% ((i,) + shape[1:])
for i in xrange(3)
)
self.assertProtoEquals(expected, image_summ)
开发者ID:adeelzaman,项目名称:tensorflow,代码行数:46,代码来源:summary_image_op_test.py
示例10: test16bit
def test16bit(self):
img_bytes = [[0, 255], [1024, 1024 + 255]]
# Encoded PNG bytes resulting from encoding the above img_bytes
# using go's image/png encoder.
encoded_bytes = [
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0,
2, 0, 0, 0, 2, 16, 0, 0, 0, 0, 7, 77, 142, 187, 0, 0, 0, 21, 73, 68, 65,
84, 120, 156, 98, 98, 96, 96, 248, 207, 194, 2, 36, 1, 1, 0, 0, 255,
255, 6, 60, 1, 10, 68, 160, 26, 131, 0, 0, 0, 0, 73, 69, 78, 68, 174,
66, 96, 130
]
byte_string = bytes(bytearray(encoded_bytes))
img_in = constant_op.constant(byte_string, dtype=dtypes.string)
decode = array_ops.squeeze(
image_ops.decode_png(
img_in, dtype=dtypes.uint16))
with self.cached_session():
decoded = self.evaluate(decode)
self.assertAllEqual(decoded, img_bytes)
开发者ID:JonathanRaiman,项目名称:tensorflow,代码行数:21,代码来源:decode_png_op_test.py
示例11: testAddEmbeddingWithThumbnails
def testAddEmbeddingWithThumbnails(self):
manager = plugin_asset.get_plugin_asset(
projector_plugin.ProjectorPluginAsset)
image1 = np.array([[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]]])
image2 = np.array([[[10, 20, 30], [40, 50, 60]],
[[70, 80, 90], [100, 110, 120]]])
manager.add_embedding(
'test',
np.array([[1], [2], [3]]),
thumbnails=[image1, image2],
thumbnail_dim=[2, 2])
assets = manager.assets()
config = projector_config_pb2.ProjectorConfig()
embedding = config.embeddings.add()
embedding.tensor_name = 'test'
embedding.tensor_shape.extend([3, 1])
embedding.tensor_path = 'test_values.tsv'
embedding.sprite.image_path = 'test_sprite.png'
embedding.sprite.single_image_dim.extend([2, 2])
expected_config_pbtxt = text_format.MessageToString(config)
self.assertEqual(assets['projector_config.pbtxt'], expected_config_pbtxt)
self.assertEqual(assets['test_values.tsv'], b'1\n2\n3\n')
png_bytes = assets['test_sprite.png']
with ops.Graph().as_default():
s = session.Session()
image_array = image_ops.decode_png(png_bytes).eval(session=s).tolist()
expected_master_image = [
[[1, 2, 3], [4, 5, 6], [10, 20, 30], [40, 50, 60]],
[[7, 8, 9], [10, 11, 12], [70, 80, 90], [100, 110, 120]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]],
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
]
self.assertEqual(image_array, expected_master_image)
开发者ID:LugarkPirog,项目名称:tensorflow,代码行数:39,代码来源:projector_plugin_test.py
示例12: decode_png
def decode_png():
return image_ops.decode_png(image_buffer, self._channels)
开发者ID:821760408-sp,项目名称:tensorflow,代码行数:2,代码来源:tfexample_decoder.py
示例13: DecodePng
def DecodePng():
return image_ops.decode_png(image_buffer, 3)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:2,代码来源:tfexample_decoder_test.py
示例14: load_image
def load_image(self, image_file, sess):
image_op = image_ops.decode_png(
io_ops.read_file(image_file), dtype=dtypes.uint8, channels=4)[:, :, 0:3]
return sess.run(image_op)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:4,代码来源:sparse_image_warp_test.py
注:本文中的tensorflow.python.ops.image_ops.decode_png函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论