IndexError:列表索引超出了keras的model.fit_generator

时间:2019-06-27 13:35:03

标签: python-3.x tensorflow keras deep-learning

我尝试训练我的网络并在model.fit_generator中遇到此错误。

model.fit_generator(
                    train_gen, validation_data=valid_gen,
                    epochs=NUM_EPOCHS, steps_per_epoch=len(train_gen),
                    validation_steps=len(valid_gen)
                    )

报告错误IndexError: list index out of range,由于结尾太长,我将在结尾附加Traceback

train_genvalid_genflow_from_directory创建。我已经检查了len(train_gen)len(valid_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

0 个答案:

没有答案