what raises StopIteration in mine Keras Model.fit_generator

前端 未结 3 1504
我在风中等你
我在风中等你 2021-01-12 14:20

I have next code:

from sklearn.model_selection import train_test_split
from scipy.misc import imresize

def _chunks(l, n):
    \"\"\"Yield successive n-sized         


        
3条回答
  •  一整个雨季
    2021-01-12 15:04

    I also met this problem, and I find a method is that you can insert "while True" block in data generator func. But I cannot get source. You can refer to my code following:

    while True:
         assert len(inputs) == len(targets)
         indices = np.arange(len(inputs))
         if shuffle:
            np.random.shuffle(indices)
         if batchsize > len(indices):
            sys.stderr.write('BatchSize out of index size')
         batchsize = len(indices)
         for start_idx in range(0, len(inputs) - batchsize + 1, batchsize):
             if shuffle:
                excerpt = indices[start_idx:start_idx + batchsize]
             else:
                excerpt = slice(start_idx, start_idx + batchsize)
             yield inputs[excerpt], targets[excerpt]
    

提交回复
热议问题