Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 索引器:列出keras的model.fit_生成器中超出范围的索引_Python 3.x_Tensorflow_Keras_Deep Learning - Fatal编程技术网

Python 3.x 索引器:列出keras的model.fit_生成器中超出范围的索引

Python 3.x 索引器:列出keras的model.fit_生成器中超出范围的索引,python-3.x,tensorflow,keras,deep-learning,Python 3.x,Tensorflow,Keras,Deep Learning,我尝试在model.fit\u generator中训练我的网络并面对这个错误 model.fit_generator( train_gen, validation_data=valid_gen, epochs=NUM_EPOCHS, steps_per_epoch=len(train_gen), validation_steps=len(valid_gen)

我尝试在
model.fit\u generator
中训练我的网络并面对这个错误

model.fit_generator(
                    train_gen, validation_data=valid_gen,
                    epochs=NUM_EPOCHS, steps_per_epoch=len(train_gen),
                    validation_steps=len(valid_gen)
                    )
报告了一个错误
索引器:列表索引超出范围
,我将在末尾附加
回溯
,因为它太长了

train\u gen
valid\u gen
由创建。我已经检查了
len(train\u gen)
len(valid\u gen)
,但我看不出问题出在哪里。 如果需要更多信息,请告诉我,谢谢

已附加回溯

IndexError                                Traceback (most recent call last)
<ipython-input-21-d09c3e50a215> in <module>
      1 history = model.fit_generator(train_gen, validation_data=valid_gen,
      2                               epochs=NUM_EPOCHS, steps_per_epoch=len(train_gen),
----> 3                               validation_steps=len(valid_gen))

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   1416             use_multiprocessing=use_multiprocessing,
   1417             shuffle=shuffle,
-> 1418             initial_epoch=initial_epoch)
   1419 
   1420     @interfaces.legacy_generator_methods_support

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/engine/training_generator.py in fit_generator(model, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
    179             batch_index = 0
    180             while steps_done < steps_per_epoch:
--> 181                 generator_output = next(output_generator)
    182 
    183                 if not hasattr(generator_output, '__len__'):

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data_utils.py in get(self)
    707                     "`use_multiprocessing=False, workers > 1`."
    708                     "For more information see issue #1638.")
--> 709             six.reraise(*sys.exc_info())

~/anaconda3/envs/fastai/lib/python3.7/site-packages/six.py in reraise(tp, value, tb)
    691             if value.__traceback__ is not tb:
    692                 raise value.with_traceback(tb)
--> 693             raise value
    694         finally:
    695             value = None

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data_utils.py in get(self)
    683         try:
    684             while self.is_running():
--> 685                 inputs = self.queue.get(block=True).get()
    686                 self.queue.task_done()
    687                 if inputs is not None:

~/anaconda3/envs/fastai/lib/python3.7/multiprocessing/pool.py in get(self, timeout)
    681             return self._value
    682         else:
--> 683             raise self._value
    684 
    685     def _set(self, i, obj):

~/anaconda3/envs/fastai/lib/python3.7/multiprocessing/pool.py in worker(inqueue, outqueue, initializer, initargs, maxtasks, wrap_exception)
    119         job, i, func, args, kwds = task
    120         try:
--> 121             result = (True, func(*args, **kwds))
    122         except Exception as e:
    123             if wrap_exception and func is not _helper_reraises_exception:

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data_utils.py in next_sample(uid)
    624         The next value of generator `uid`.
    625     """
--> 626     return six.next(_SHARED_SEQUENCES[uid])
    627 
    628 

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py in __next__(self, *args, **kwargs)
    102 
    103     def __next__(self, *args, **kwargs):
--> 104         return self.next(*args, **kwargs)
    105 
    106     def next(self):

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py in next(self)
    114         # The transformation of images is not under thread lock
    115         # so it can be done in parallel
--> 116         return self._get_batches_of_transformed_samples(index_array)
    117 
    118     def _get_batches_of_transformed_samples(self, index_array):

~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py in _get_batches_of_transformed_samples(self, index_array)
    225         filepaths = self.filepaths
    226         for i, j in enumerate(index_array):
--> 227             img = load_img(filepaths[j],
    228                            color_mode=self.color_mode,
    229                            target_size=self.target_size,

IndexError: list index out of range
索引器错误回溯(最近一次调用)
在里面
1历史记录=型号。装配发电机(列车发电机,验证数据=有效发电机,
2个历元=NUM_历元,每历元步长=len(列车生成),
---->3个验证步骤=长度(有效长度))
包装中的~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/legacy/interfaces.py(*args,**kwargs)
89 warnings.warn('Update your`'+object\u name+'`调用+
90'Keras 2 API:'+签名,堆栈级别=2)
--->91返回函数(*args,**kwargs)
92包装器._原始函数=func
93返回包装器
~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/engine/training.py-in-fit\u生成器(self、生成器、每个历元的步骤、历元、冗余、回调、验证数据、验证步骤、类权重、最大队列大小、工作者、使用多处理、无序、初始历元)
1416使用多处理=使用多处理,
1417洗牌=洗牌,
->1418初始_历元=初始_历元)
1419
1420@interfaces.legacy\u生成器\u方法\u支持
~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/engine/training\u generator.py in-fit\u generator(模型、生成器、每个历元的步骤、历元、冗余、回调、验证数据、验证步骤、类权重、最大队列大小、工作者、使用多处理、无序、初始历元)
179批次指数=0
180当步骤完成时<每个步骤:
-->181发电机输出=下一个(发电机输出)
182
183如果不是HASTATR(发电机输出,'''.'透镜''.'':
get(self)中的~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data_utils.py
707“`use_multiprocessing=False,workers>1`。”
708“有关更多信息,请参阅第1638期。”)
-->709六.重新播放(*sys.exc_info())
~/anaconda3/envs/fastai/lib/python3.7/site-packages/six.py in reraise(tp,value,tb)
691如果值.\uuuu回溯\uuuuu不是tb:
692通过回溯(tb)提升值
-->693提高价值
694最后:
695值=无
get(self)中的~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data_utils.py
683试试:
684当self.u正在运行()时:
-->685 inputs=self.queue.get(block=True).get()
686 self.queue.task_done()
687如果输入不是无:
get中的~/anaconda3/envs/fastai/lib/python3.7/multiprocessing/pool.py(self,超时)
681返回自身值
682其他:
-->683提高自我价值
684
685 def_装置(自、i、obj):
~/anaconda3/envs/fastai/lib/python3.7/multiprocessing/pool.py in worker(inqueue、outqueue、初始值设定项、initargs、maxtasks、wrap_异常)
119作业,i,func,参数,kwds=任务
120尝试:
-->121结果=(真,函数(*args,**kwds))
122例外情况除外,如e:
123如果换行异常和func不是_helper _重新出现_异常:
下一个样本(uid)中的~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras/utils/data\u utils.py
624生成器“uid”的下一个值。
625     """
-->626返回六。下一步(\u共享\u序列[uid])
627
628
~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras\u preprocessing/image/iterator.py in\uuuuuuuu next\uuuuuuu(self,*args,**kwargs)
102
103定义下一个定义(self,*args,**kwargs):
-->104返回自下一步(*args,**kwargs)
105
106 def next(自我):
下一步中的~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras_preprocessing/image/iterator.py(self)
114#图像转换未处于线程锁定状态
115#因此可以并行进行
-->116返回自身。获取转换样本的批次(索引数组)
117
118 def_获取_转换_样本的批次(自、索引_数组):
~/anaconda3/envs/fastai/lib/python3.7/site-packages/keras\u preprocessing/image/iterator.py in\u get\u batches\u of\u transformed\u样本(self,index\u数组)
225 filepath=self.filepath
226表示枚举中的i,j(索引数组):
-->227 img=load_img(文件路径[j],
228颜色_模式=self.color_模式,
229目标大小=自我目标大小,
索引器:列表索引超出范围