gpt4 book ai didi

python - 为什么 tf.image.decode_jpeg 可以解码 png?

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:39 24 4
gpt4 key购买 nike

今天我正在测试一些 tensorflow (python) 代码。它是著名的 MNIST 集上的神经网络。

一切正常,所以我通读了代码并研究了该网络的结构。

当涉及到图片输入时,我发现了如下代码:

image_string = tf.read_file(filename)

image_decoded = tf.image.decode_jpeg(image_string, channels=3)

代码使用“decode_jpeg”而不是“decode_png”。而且我没有看到任何错误。

但是,我 100% 确定图像是 PNG 格式。

我用过

od -c -b 1.png

查看这些图像,它们是 PNG。

那么,为什么“decode_jpeg”可以在 PNG 上工作?是否有任何可能由此引起的潜在问题?

最佳答案

documentation for tensorflow状态:

This op also supports decoding PNGs and non-animated GIFs since the interface is the same, though it is cleaner to use tf.image.decode_image.

所以本质上这是一个设计决策,因为接口(interface)是相同的,只是处理它,而不是抛出一个错误,迫使用户使用正确的 API 调用。

关于python - 为什么 tf.image.decode_jpeg 可以解码 png?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52092881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com