【发布时间】:2021-07-27 16:37:06
【问题描述】:
我正在制作一个神经网络架构来预测图像是建筑物、森林、冰川、山脉、海洋还是街道。 Link 到数据集。
我正在使用tf.keras.preprocessing.image.ImageDataGenerator() 来加载和预处理我的数据。目录如下所示:
该目录包含大小为 150x150 的图像,如下所示:
代码:
train_batch = tf.keras.preprocessing.image.ImageDataGenerator().flow_from_directory(directory=train_path, color_mode='rgb')
test_batch = tf.keras.preprocessing.image.ImageDataGenerator().flow_from_directory(directory=test_path)
>>> Found 14034 images belonging to 6 classes.
Found 3000 images belonging to 6 classes.
img, labels = next(train_batch)
label_first_10 = labels[:10]
img_first_10 = img[:10]
class_name = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
def plotImages(images_arr):
fig, axes = plt.subplots(1, 10, figsize=(20,20))
axes = axes.flatten()
for img, ax in zip(images_arr, axes):
ax.imshow(img)
ax.axis('off')
plt.tight_layout()
plt.show()
>>>
您可以看到我们几乎看不见的图像,甚至我都无法确定它来自哪个班级!所以,我不确定模型是否能够在这些类型的图像上进行训练。 任何人都可以设置其他一些超参数设置,以便我的图像可见并且可以被人眼识别。
【问题讨论】:
-
试试
ax.imshow(img / 255.0) -
感谢@Frightera,它成功了!但除以 255.0 时,它有何变化?
标签: python tensorflow image-processing keras deep-learning