Ego ren
Ego ren

Reputation: 91

Test data being used for validation data in keras fit_generator

I use keras(tensorflow) to train my model. I use the function fit_generator cause I use ImageDataGenerator to make data augmentation.

Here's my question,I find there's two kind of training process.The former I don't know what it is, but the later is just the model is learning from the original data.And the situation is below:

...

    145/147 [============================>.] - ETA: 0s - loss: 1.5847 - acc: 0.5120
    146/147 [============================>.] - ETA: 0s - loss: 1.5838 - acc: 0.5117
...

it seems that this epoch will end ,but then a new training start in this epoch.

...
     32/1567 [..............................] - ETA: 3:11 - loss: 1.8080 - acc: 0.4688
     64/1567 [>.............................] - ETA: 2:58 - loss: 1.7491 - acc: 0.5000
...

Besides I post relating code right here

datagen = keras.preprocessing.image.ImageDataGenerator( featurewise_std_normalization=True, rotation_range=20,
                                 width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True)
datagen.fit(trainX)
model.fit_generator(datagen.flow(trainX, trainY, batch_size=BATCH_SIZE),
                            steps_per_epoch=trainX.shape[0]//BATCH_SIZE, epochs=10,
                            validation_data=(testX,testY),
                            verbose=1,callbacks=[tb_cb,reduce_lr,early])

Did I do some thing wrong? And I don't find any solution

Relly hopeing that someone can help me ,thank you

--------------------------------Updata---------------------------------

At first I thought it's steps_per_epoch's fault.But I am wrong. When I restart the training without steps_per_epoch. It shows again.

By elimination, I found it is caused by validation_data.I don't know why,and I can't delete validation_data cause it must be used if I use tensorboard in the callbacks. And I find it will process so fast if I delete the function of tensorboard and leave the validation_data.

here's my tensorboard function in callbacks:

 tb_cb = keras.callbacks.TensorBoard(log_dir=board_file, write_images=1, histogram_freq=1)

There must be some relationship between keras.callbacks.TensorBoard and validation_data

In addition, as the api for validation_steps says:

Only relevant if validation_data is a generator. Total number of steps (batches of samples) to yield from generator before stopping. Optional for Sequence: if unspecified, will use the len(validation_data) as a number of steps.

And I can tell that the steps of new training process actually equals to the number of my validation data.

Upvotes: 2

Views: 5751

Answers (1)

Ego ren
Ego ren

Reputation: 91

fit_generator also create a validation data generator.So it's validation process is also divided in batchs, and what I see after training is just the intermediate result。And model won't train on the validation data.

here's some relative discussion about that:

Test data being used for validation data?

Test data being used for validation data in chinese

Upvotes: 3

Related Questions