Person-Segmentation-Keras icon indicating copy to clipboard operation
Person-Segmentation-Keras copied to clipboard

StopIteration()

Open Moyao6 opened this issue 6 years ago • 4 comments

Thanks for your code first. The program always breaks in the process of training. The error message is stopiteration. How can I solve this problem? Can you show me your keras version?

Moyao6 avatar Aug 28 '18 04:08 Moyao6

@Moyao6

Can you share the whole error message?

TianzhongSong avatar Aug 29 '18 00:08 TianzhongSong

I get the same error: 937/937 [==============================] - 458s 488ms/step - loss: 0.0376 - acc: 0.9922 - val_loss: 0.0496 - val_acc: 0.9975

Epoch 00001: val_acc improved from -inf to 0.99750, saving model to ./unet_seg_weights.h5 Epoch 2/20 936/937 [============================>.] - ETA: 0s - loss: 0.0168 - acc: 0.9972Traceback (most recent call last): File "laurent.py", line 147, in callbacks=[checkpoint], File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/engine/training.py", line 1415, in fit_generator initial_epoch=initial_epoch) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/engine/training_generator.py", line 230, in fit_generator workers=0) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/engine/training.py", line 1469, in evaluate_generator verbose=verbose) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/engine/training_generator.py", line 327, in evaluate_generator generator_output = next(output_generator) File "/home/denoue/.conda/envs/myenv/lib/python3.6/site-packages/keras/utils/data_utils.py", line 785, in get raise StopIteration() StopIteration

ldenoue avatar Sep 24 '18 19:09 ldenoue

I "fixed" the problem by removing the validation computations in fit_generator, as such:

#history = 
model.fit_generator(train,
                        steps_per_epoch=len(trainitems) // train_batch_size,
                        #validation_data=val,
                        #validation_steps=len(valitems) // val_batch_size,
                        epochs=epochs,
                        #callbacks=[checkpoint],
                                  )
#plot_history(history, './results/', 'unet')
#save_history(history, './results/', 'unet')
model.save(save_file)

ldenoue avatar Sep 24 '18 20:09 ldenoue

I have solved this problem. The problem is caused by the validation_generator not have continue running? add while True. like this: else: while True: for j in range(len(items) // batch_size): x, y = get_batch(items[j * batch_size:(j + 1) * batch_size], root_path, n_classes, input_height, input_width) yield np.array(x), np.array(y)

mgq1507 avatar Nov 28 '18 09:11 mgq1507