Reputation: 439
I am trying to train the MNIST digit dataset using deep MLP on Google colab. I have reshaped the input and performed data preprocessing.The model code is as below:
#define the model layers
model = Sequential()
model.add(Dense(512, input_shape = input_shape, activation = "relu"))
model.add(Dense(256, activation = "relu"))
model.add(Dropout(0.1))
model.add(Dense(128,activation = "relu"))
model.add(Dense(64,activation = "relu"))
model.add(Dropout(0.1))
model.add(Flatten())
model.add(Dense(tar_class,activation = "sigmoid"))
model.compile(optimizer = "adam",
loss = "categorical_crossentropy",
metrics = ["accuracy"])
model.summary()
history = model.fit(X_train,y_train,
epochs = 10,
validation_split = 0.1,
batch_size = 64,
verbose = True)
When I run the model.fit code, the training happens only for 844 samples in the dataset and not for 60000 samples. However, this code works well in my local jupyter notebook. I want to work on Colab so that I can use GPU to train the model, which is quick compared to my local machine.
Can anyone please help me out here?
Upvotes: 1
Views: 531
Reputation: 3574
The 844 does not represent the number of samples it is getting trained on, but it represents number of steps per epoch.
What is the number of steps?
The number of steps is equivalent no of passes ie(1 pass = 1 Forward Pass + 1 Backward pass)
that occurs in an epoch.
The number of steps is calculated as:
no_of_steps_per_epoch = ceil(Total_no_of_samples / batch_size)
For completion of one epoch, you have to iterate over the entire dataset. ie. iterate over all the batches.
For eg:
X_train has 60000 samples.
You have specified validation_split as 0.1. Therefore, 0.1 % of this X_train will be used as validation data. ie. It will not be used for training.
Therefore, the number of samples for training will be (60000 - 6000) = 54000.
Now you have specified batch_size as 64.
Therefore,
no_of_steps_per_epoch = ceil(54000/64) = ceil(843.74) = 844
This is how you get 844.
It does not mean you are training on 844 samples.
Upvotes: 5