- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 PIL.Image.open 和 tf.image.decode_jpeg 将图像文件解析为数组。但发现PIL.Image.open()中的像素值与tf.image.decode_jpeg不一样。为什么会出现这种情况?
谢谢!
代码输出:
tf 100 100 [132 145 161]
pil 100 100 [134 147 164]
我的代码:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
import math
import time
import numpy as np
import tensorflow as tf
def decode_jpeg(image_file):
from PIL import Image
im = Image.open(image_file)
data = np.array(im)
return data
def tfimageread(filenames):
filename_queue = tf.train.string_input_producer(filenames)
reader = tf.WholeFileReader(name='image_reader')
key, value = reader.read(filename_queue)
uint8image = tf.image.decode_jpeg(value, channels=3)
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = []
for qr in tf.get_collection(tf.GraphKeys.QUEUE_RUNNERS):
threads.extend(qr.create_threads(sess, coord=coord, daemon=True, start=True))
image = sess.run(uint8image)
coord.request_stop()
coord.join(threads, stop_grace_period_secs=10)
return image
if __name__ == '__main__':
image_file = '。/o_1bchv9keu625336862107241874241888.jpg'
image_tf = tfimageread([image_file])
image_pil = decode_jpeg(image_file)
i, j = 100, 100
print ("tf %d %d %s" % (i,j,image_tf[i][j]))
print ("pil %d %d %s" % (i,j,image_pil[i][j]))
最佳答案
此问题的一个常见原因是tensorflow在解压缩jpeg时尝试走捷径。这提供了 pretty large speedup对于图像读取,这可能是训练某些 CNN 的瓶颈,但确实会稍微抖动像素值。
幸运的是,开发人员已经提供了关闭其中一些效率的选项。特别是,请查看 argument dct_method
。
尝试将对 tf.image.decode_jpeg
的调用更改为:
tf.image.decode_jpeg(value, channels=3, dct_method='INTEGER_ACCURATE')
您可能还需要困惑 fancy_upscaling
,具体取决于您正在阅读的图像类型以及您的软件正在使用的 libjpeg 底层版本中发生的其他事情。
关于python - PIL.Image.open和tf.image.decode_jpeg返回值的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44514897/
我正在使用一个脚本将图像加载到 TensorFlow,这显然适合每个人,但当我尝试它时,我最终得到黑色图像(零矩阵)。我用几个图像文件尝试过,它总是为零,当我故意拼错图像位置字符串时,它会报告错误(正
我尝试设置一个图像管道,为 Tensorflow 构建一个图像数据集来裁剪图像。 我关注了这个 tutorial但我想将文件裁剪为正方形,而不是在不保留纵横比的情况下调整其大小。 我无法弄清楚如何获得
我已经按照本教程构建了一个通过 tensorflow 服务进行图像分类的服务器/客户端演示 https://github.com/tmlabonte/tendies/blob/master/minim
我使用 SequenceExample 将每个示例的可变数量的 jpg 帧存储到 TFRecord 中: tf.compat.as_bytes(cv2.imencode(".jpg", frame)[
今天我正在测试一些 tensorflow (python) 代码。它是著名的 MNIST 集上的神经网络。 一切正常,所以我通读了代码并研究了该网络的结构。 当涉及到图片输入时,我发现了如下代码: i
我尝试使用 Tensorflow 加载文件并可视化结果,但出现 TypeError: Image data无法转换为 float import tensorflow as tf import matp
我是一名优秀的程序员,十分优秀!