【发布时间】:2020-12-13 18:25:08
【问题描述】:
我正在使用 TF 2.3 中的 tf.keras.preprocessing.image_dataset_from_directory 从目录加载图像(训练/测试拆分)。我得到的是一个带有形状的 tf.data.Dataset (tensorflow.python.data.ops.dataset_ops.BatchDatasetactually) 对象:
train_ds.take(1)
# <TakeDataset shapes: ((None, 256, 256, 3), (None, 6)), types: (tf.float32, tf.float32)>
for images, labels in train_ds.take(1):
print(images.shape)
print(images[0])
# (32, 256, 256, 3)
# tf.Tensor(
# [[[225.75 225.75 225.75 ]
# [225.75 225.75 225.75 ]
# [225.75 225.75 225.75 ]
# ...
# [215. 214. 209. ]
# [215. 214. 209. ]
# [215. 214. 209. ]]
#
# ...], shape=(256, 256, 3), dtype=float32)
我无法弄清楚如何使用该 Dataset 对象规范化图像 (/= 255)。我尝试使用/= 运算符本身、map 和apply 方法,甚至将该对象转换为here 中提到的列表。似乎没有任何效果,我真的很想在数据集级别解决这个问题,而不是在我的网络中添加规范化层。
有什么想法吗?
【问题讨论】:
-
你能展示一下你是如何使用
map对来自 tf 数据集的图像进行归一化的吗
标签: python tensorflow keras deep-learning tensorflow-datasets