如何获取Keras中ImageDataGenerator的.flow_from_directory函数扫描的类名?

我想制作一个用户友好的GUI图像分类器,用户只需指向数据集目录即可训练模型,然后他们可以向程序提供任何图像,程序将显示图像中对象的概率和标签。但是,我如何获取Keras中ImageDataGenerator的.flow_from_directory函数扫描的类名呢?


回答:

根据文档说明,“可以通过class_indices属性获取类名到类索引的映射字典。

https://keras.io/preprocessing/image/#flow_from_directory

在下面的示例中,train_data_dir包含两个子文件夹,catdog

train_datagen = ImageDataGenerator(rescale=1. / 255)train_generator = train_datagen.flow_from_directory(    train_data_dir,    target_size=(img_width, img_height),    color_mode='grayscale',    shuffle = True,    batch_size=batch_size,    class_mode='binary')print(train_generator.class_indices){'cat': 0, 'dog': 1}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注