煤油ImageDataGenerator.flow_来自_dataframe继续装载

2024-10-05 14:23:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究斯坦福大学的MURA dataset。我尝试使用Keras的ImageDataGenerator加载数据集。数据在以下层次结构中:

The directory hierarchy

study1_positive文件夹包含这些图像。在

ImageDataGenerator.flow_from_directory不能与此文件夹结构一起使用,因此我尝试使用flow_from_dataframe方法。在

但是,当运行时,代码会继续执行并且不会停止。在

下面是我传递给flow_from_directory方法的Pandas数据帧的格式:

The DataFrame passed to flow_from_dataframe

我还尝试将标签分别改为“异常”和“正常”来代替1和0。在

编辑:

我粘贴了下面的代码:

train_imggen = ImageDataGenerator(rescale=1./255, rotation_range=30,
                              horizontal_flip=True)

train_loader = train_imggen.flow_from_dataframe(traindf, '.', shuffle=True,
                                            x_col='path', y_col='label',
                                            color_mode='grayscale',
                                            target_size=(320,320), 
                                            class_mode='binary', 
                                            batch_size=8)

Tags: 数据方法代码from文件夹truedataframesize
1条回答
网友
1楼 · 发布于 2024-10-05 14:23:42

找到了解决方案here。显然,当前的flow_from_dataframe不处理相对路径。在

  1. Clone my "fix_found_0_images" branch. git clone -b fix_found_0_images_bug https://github.com/smurak/keras-preprocessing.git
  2. Move the "keras_preprocessing" subdirectory to your working directory.
  3. Import it.
import keras
from keras_preprocessing import image
...
train_imggen = image.ImageDataGenerator(...)

相关问题 更多 >