我使用函数tf.keras.preprocessing.image_dataset_from_directory(),当我检查加载的图像的内容时,我发现它包含随机像素值,与原始图像不一致。
这就是我所说的功能:
ds = tf.keras.preprocessing.image_dataset_from_directory(
images_path,
label_mode=None,
shuffle=False,
seed=None,
image_size=(input_height, input_width),
batch_size=batch_size
)
然后我对数据集的第一个元素进行采样,如下所示:
it = iter(ds)
img = next(it).numpy()
生成的图像包含类似164.3462的值,这没有意义,因为原始图像文件只有整数作为像素值。如果要转换为float32,我希望所有像素的值的小数部分都应为.0。
我错过了什么吗?我只想以原始值或以.0开头的原始值加载图像,以防需要float32。
怎么了?
答案 0 :(得分:0)
那是因为在尝试将图像调整为image_dataset_from_directory
时,bilinear
使用默认的'(input_height, input_width)
'插值。检查this链接以了解插值方法的其他选项。
答案 1 :(得分:0)
要使用原始值,请使用“最近”作为插值来调整图像大小。
ds = tf.keras.preprocessing.image_dataset_from_directory(
images_path,
label_mode=None,
shuffle=False,
seed=None,
interpolation='nearest',
image_size=(input_height, input_width),
batch_size=batch_size
)