Python Keras ImageGenerator:索引器:列表索引超出范围

Python Keras ImageGenerator:索引器:列表索引超出范围,python,python-3.x,pandas,image-processing,keras,Python,Python 3.x,Pandas,Image Processing,Keras,我将数据从kaggle内核加载到我的机器上进行重新编程,现在代码不起作用,但在同一python环境下的keras上工作 下面是代码和bug def flow_from_dataframe(img_data_gen, in_df, path_col, y_col, **dflow_args): base_dir = os.path.dirname(in_df[[path_col]].values[0]) print('## Ignore next message from kera

我将数据从kaggle内核加载到我的机器上进行重新编程,现在代码不起作用,但在同一python环境下的keras上工作

下面是代码和bug

def flow_from_dataframe(img_data_gen, in_df, path_col, y_col, **dflow_args):
    base_dir = os.path.dirname(in_df[[path_col]].values[0])
    print('## Ignore next message from keras, values are replaced anyways')
    df_gen = img_data_gen.flow_from_directory(base_dir, 
                                     class_mode = 'sparse',
                                    **dflow_args)
    df_gen.filenames = in_df[path_col].values
    df_gen.classes = np.stack(in_df[y_col].values)
    df_gen.samples = in_df.shape[0]
    df_gen.n = in_df.shape[0]
    df_gen._set_index_array()
    df_gen.directory = '' # since we have the full path
    print('Reinserting dataframe: {} images'.format(in_df.shape[0]))
    return df_gen


train_gen = flow_from_dataframe(core_idg, train_df, 
                             path_col = 'path',
                            y_col = 'disease_vec', 
                            target_size = IMG_SIZE,
                             color_mode = 'rgb',
                            batch_size = 32)

valid_gen = flow_from_dataframe(core_idg, valid_df, 
                             path_col = 'path',
                            y_col = 'disease_vec', 
                            target_size = IMG_SIZE,
                             color_mode = 'rgb',
                            batch_size = 256) # we can use much larger batches for evaluation
# used a fixed dataset for evaluating the algorithm
test_X, test_Y = next(flow_from_dataframe(core_idg, 
                               valid_df, 
                             path_col = 'path',
                            y_col = 'disease_vec', 
                            target_size = IMG_SIZE,
                             color_mode = 'rgb',
                            batch_size = 1024)) # one big batch

t_x, t_y = next(train_gen)
fig, m_axs = plt.subplots(4, 4, figsize = (16, 16))
我可以看到路径和路径列表,但不确定它来自哪里

Found 0 images belonging to 0 classes.
Reinserting dataframe: 10000 images
Traceback (most recent call last):
  File "main.py", line 181, in <module>
    batch_size = 32)) # one big batch
  File "/home/user/.conda/envs/test_env/lib/python3.6/site-packages/keras_prepro         cessing/image/iterator.py", line 104, in __next__
    return self.next(*args, **kwargs)
  File "/home/user/.conda/envs/test_env/lib/python3.6/site-packages/keras_prepro         cessing/image/iterator.py", line 116, in next
    return self._get_batches_of_transformed_samples(index_array)
  File "/home/user/.conda/envs/test_env/lib/python3.6/site-packages/keras_prepro         cessing/image/iterator.py", line 227, in _get_batches_of_transformed_samples
    img = load_img(filepaths[j],
找到了属于0个类的0个图像。
重新插入数据帧:10000个图像
回溯(最近一次呼叫最后一次):
文件“main.py”,第181行,在
批次_size=32)#一个大批次
文件“/home/user/.conda/envs/test_env/lib/python3.6/site-packages/keras_prepo-processing/image/iterator.py”,第104行,下一页__
返回self.next(*args,**kwargs)
文件“/home/user/.conda/envs/test_env/lib/python3.6/site-packages/keras_prepo processing/image/iterator.py”,下一页第116行
返回self.\u获取\u批次\u转换的\u样本(索引\u数组)
文件“/home/user/.conda/envs/test\u env/lib/python3.6/site-packages/keras\u prepo-processing/image/iterator.py”,第227行,在转换样本的批处理中
img=load_img(文件路径[j],

发生错误的原因是
文件路径
为空列表。将图像路径添加到
文件路径
中:

df_gen.filepath.extend(df_gen.filenames)

你能从数据框中打印
base\u dir
的值吗?@Anwarvic../data/images\u 003/images,当我做cd../data/images\u 001/images/和ls时,它会打印所有的图像。我有12个像images003一样的图像文件夹,每个都有一个文件夹/images,然后在所有的imagesbase\u dir=../data/images\u 003/imagesOK,great..您现在可以打印
列车生成目录吗
?它不打印任何内容,无论是在内核中还是在我的机器中