【发布时间】:2020-09-02 11:57:57
【问题描述】:
from keras.preprocessing.image import ImageDataGenerator
WIDTH = 299
HEIGHT = 299
BATCH_SIZE = 32
# data prep
train_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
validation_datagen = ImageDataGenerator(
preprocessing_function=preprocess_input,
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
train_generator = train_datagen.flow_from_directory(
TRAIN_DIR,
target_size=(HEIGHT, WIDTH),
batch_size=BATCH_SIZE,
class_mode='categorical')
validation_generator = validation_datagen.flow_from_directory(
TEST_DIR,
target_size=(HEIGHT, WIDTH),
batch_size=BATCH_SIZE,
class_mode='categorical')
对于这部分代码,我的输出应该是“找到属于 2 个类的 39 个图像。
找到属于 2 个类别的 49 张图像”。但我得到了 3 个类别。
请帮帮我。在此先感谢。还有谁能告诉我它是根据什么分类的
完整代码请查看此链接https://colab.research.google.com/drive/18AN2AUM5sEsTMGUzFUL0FLSULtXF4Ps0
【问题讨论】:
-
该问题与 Keras 无关。这是 Colab 笔记本中的预处理步骤。出于某种原因,您的培训目录中有 3 个文件夹。我运行你的代码没有问题。你篡改了文件夹吗?
-
@NicolasGervais 这就是我的训练目录的声明方式“TRAIN_DIR = '/content/drive/My Drive/train'”并且训练目录 Cat 和 Dog 中只有两个子文件夹。没有文件夹受阻
-
删除 Colab 创建的文件夹 !rmdir Path_of_Folder/.ipynb_checkpoints
标签: python python-3.x tensorflow keras neural-network