qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.74k stars 1.04k forks source link

Batch_size ignored #337

Open APWx opened 4 years ago

APWx commented 4 years ago

Hi, I am using the following model.

# preprocess input
x_train = preprocess_input(x_train)
x_val = preprocess_input(x_val)

# define model
model = Unet(BACKBONE, encoder_weights='imagenet')
model.compile('adamax', loss=bce_jaccard_loss, metrics=[iou_score])

# model.summary()
# fit model
model.fit(
    x=x_train,
    y=y_train,
    batch_size=16,
    epochs=200,
    validation_data=(x_val, y_val))

However, no matter what batch_size am using, model always trains as if the batch size was set to one even though it is 16. That is, the number of steps per epoch is equal to the number of samples in the training data set. I would appreciate any help on that issue.

JordanMakesMaps commented 4 years ago

It might be because the steps_per_epoch variable isn't set, have you given that a try?

steps_per_epoch: Integer or `None`.
                Total number of steps (batches of samples)
                before declaring one epoch finished and starting the
                next epoch. When training with input tensors such as
                TensorFlow data tensors, the default `None` is equal to
                the number of samples in your dataset divided by
                the batch size, or 1 if that cannot be determined.

See here for Keras' training.py

APWx commented 4 years ago

Thank you for your response and sorry for a super late reply. I have recently came back to the project and noticed that although the number of steps per epoch is equal to the number of samples, the stepsize/increment is actually equal to the batch size. It seems, that it is just a matter of convention for some models for example we can have: sample_size = 20 batch_size = 5 and during the training see for every epoch: a) 1/4 , 2/4, 3/4, 4/4 OR b) 5/20, 10/20, 15/20, 20/20

What I have observed was option b). It's just when you have thousads of steps to complete the epoch and they progress fast it is hard to notice the increment whether its 1, 10 or 100. The bottom line is that the model provides very resonable results so all is ok.