Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 确定模型的输出。预测与类别的关系_Python_Python 3.x_Keras - Fatal编程技术网

Python 确定模型的输出。预测与类别的关系

Python 确定模型的输出。预测与类别的关系,python,python-3.x,keras,Python,Python 3.x,Keras,我试图找出如何从keras返回的一个热编码向量中确定类。问题是,我使用带有ImageDataGenerator的\u目录中的流\u来训练我的网络,导致keras自动将文件夹结构转换为我所知的类向量,我该如何解决这个问题 以下是我在代码中的培训安排: checkpoint = [ModelCheckpoint( 'model.checkpoint.hdf5', period=1 )] train_datagen = ImageDataGene

我试图找出如何从keras返回的一个热编码向量中确定类。问题是,我使用带有ImageDataGenerator的\u目录中的流\u来训练我的网络,导致keras自动将文件夹结构转换为我所知的类向量,我该如何解决这个问题

以下是我在代码中的培训安排:

    checkpoint = [ModelCheckpoint(
        'model.checkpoint.hdf5',
        period=1
   )]

    train_datagen = ImageDataGenerator(
        rotation_range=30)

    test_datagen = ImageDataGenerator(
        rotation_range=30)

    train_generator = train_datagen.flow_from_directory(
        '/train/',
        target_size=(x, y),
        batch_size=batch_size,
        class_mode='categorical')
    test_generator = test_datagen.flow_from_directory(
        '/test/',
        target_size=(x, y),
        batch_size=batch_size,
        class_mode='categorical')

    self.discriminator.fit_generator(
        train_generator,
        steps_per_epoch=10000,
        epochs=epochs,
        validation_data=test_generator,
        validation_steps=10,
        callbacks=checkpoint
    )
我的文件夹结构如下所示:

root/
    train/
        cow/
            0.jpg
            1.jpg
        pig/
            0.jpg
            1.jpg
    test/
        cow/
            0.jpg
            1.jpg
        pig/
            0.jpg
            1.jpg

keras中的预测指的是您自己的文件夹结构。如果列车由牛和猪组成。然后
cow=0
pig=1
。因此,如果predict返回0,则为cow,否则为pig。

keras中的predict指的是您自己的文件夹结构。如果列车由牛和猪组成。然后
cow=0
pig=1
。因此,如果预测返回0,则为cow,否则为pig

print(train_generator.class_indices)
{'cow': 0, 'pig': 1}
从文档中,“包含从类名到类索引映射的字典可以通过属性class_索引获得。”

从文档中,“包含从类名到类索引映射的字典可以通过属性class_索引获得。”