Keras 创建三个类而不是两个

use*_*617 5 python linode python-2.7 keras tensorflow

我正在尝试训练一个模型来识别包含森林的火与图像的图像。我正在使用 Linode 在远程服务器上训练模型。我使用的是 Python 2.7 和 Ubuntu 16.04.5。

当我在本地或在 Jupyter 笔记本中运行以下代码时,它会创建 2 个类,但是当我想在服务器上运行它时,它会创建 3 个类。

对模型进行分类的代码:

def onehot(x): return np.array(OneHotEncoder().fit_transform(x.reshape(-1,1)).todense())


model = keras.applications.InceptionV3(weights='imagenet', include_top=False)


batch_size=16

train_datagen = ImageDataGenerator(
        rescale=1./255,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True)


train_generator = train_datagen.flow_from_directory(
        'datareal/train',  # this is the target directory
        batch_size=batch_size,
        target_size=(224, 224),
        class_mode='binary')

test_datagen = ImageDataGenerator(rescale=1./255)

validation_generator = test_datagen.flow_from_directory(
        'datareal/valid',
        batch_size=batch_size,
        target_size=(224, 224),
        class_mode='binary')


x = model.output
x = GlobalAveragePooling2D()(x)
# let's add a fully-connected layer
x = Dense(1024, activation='relu')(x)
# and a logistic layer -- let's say we have 2 classes
predictions = Dense(2, activation='softmax')(x)
newmodel = Model(inputs=model.input, outputs=predictions)

newmodel.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])
Run Code Online (Sandbox Code Playgroud)

输出:

Found 173 images belonging to 3 classes.
Found 40 images belonging to 3 classes.
Run Code Online (Sandbox Code Playgroud)

包含所有图像的目录结构如下:

datareal
        valid
                forest
                fire
        train
                forest
                fire
Run Code Online (Sandbox Code Playgroud)

我如何让模型只标记 2 个类而不是 3 个?

use*_*617 4

我想到了。问题是我的火车和验证文件夹中仍然有一些隐藏文件夹。