本文介绍了是否可以从目录更改Keras流的类索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自己的图像数据生成器.它将生成0、90、180和270度旋转的图像批处理版本,并将它们及其类返回.我使用内置的ImageDataGenerator函数来测试模型.但是,flow_from_directory会生成不同的类索引. train_generator.class_indices的输出是{'0': 0, '90': 1, '180': 2, '270': 3}.但是test_generator.class_indices返回{'0': 0, '180': 1, '270': 2, '90': 3}.我可以简单地更改旋转角度的顺序,但是此问题是由操作系统的文件系统引起的,因此我将在其他操作系统上运行代码.在这种情况下,我需要一个自动化的解决方案.有没有办法改变flow_from_directory方法的类索引?

I am using my own image data generator. It generates 0 ,90, 180 and 270 degrees rotated versions of image batches and returns them with their classes. I use built in ImageDataGenerator function to test the model. However flow_from_directory generates different class indices. Output of train_generator.class_indices is {'0': 0, '90': 1, '180': 2, '270': 3}. But test_generator.class_indices returns {'0': 0, '180': 1, '270': 2, '90': 3}. Simply I can change order of rotation angles but this problem is caused by the file system of operating system and I will run the code on a different operating system. In this case I need an automated solution. Is there a way to change the class indices of flow_from_directory method?

推荐答案

看起来可以做到

flow_from_directory(directory, 
                    classes={'0': 0, 
                             '90': 1, 
                             '180': 2, 
                             '270': 3}
                   )

这篇关于是否可以从目录更改Keras流的类索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:52