Home>
print (train_images.shape)
print (train_labels.shape)
(60000, 784)
(60000, 10)


When sample data is taken out from keras and preprocessed, there are 60,000 data, but when training

model = Sequential ()
model.add (Dense (256, activation ='sigmoid', input_shape = (784,)))
model.add (Dense (128, activation ='sigmoid'))
model.add (Dropout (rate = 0.5))
model.add (Dense (10, activation ='softmax'))
model.compile (loss ='categorical_crossentropy', optimizer = SGD (lr = 0.1), metrics = ['acc'])
history = model.fit (train_images, train_labels, batch_size = 500,
    epochs = 5, validation_split = 0.2)
Epoch 1/5
96/96 [==============================] --1s 6ms/step --loss: 2.0732 --acc: 0.2885 --val_loss : 1.0056 --val_acc: 0.8280
Epoch 2/5
96/96 [==============================] --0s 5ms/step --loss: 1.0491 --acc: 0.7057 --val_loss : 0.5946 --val_acc: 0.8853
..
..
..


I have only trained 96. Since the contents of the book are pasted, there is no mistake in the code.
The environment uses Google Colad.
With the same code in the book

Train on 48000 samples, validate on 12000 samples
Epoch 1/5
48000/48000 [==============================] --2s 36us/sample --loss: 1.6872 --acc: 0.4570 --val_loss : 0.9593 --val_acc: 0.8463
Epoch 2/5
48000/48000 [==============================] --2s 35us/sample --loss: 0.9088 --acc: 0.7503 --val_loss : 0.5725 --val_acc: 0.8845
..
..
..


The result will be output. The first Train on 48000 ,,, and so on are not output either.
This is the very first part of the book "AlphaZore: Introduction to Artificial Intelligence Programming Practice".
I don't know what caused it because the code remains the same and the Google Colad settings remain the same.
Please let me know if anyone knows.

  • Answer # 1

    I have never purchased or read a book, so I will answer based on my personal interpretation.
    In conclusion, if you want a result similar to what you expect,

    history = model.fit (train_images, train_labels, batch_size = 1, epochs = 5, validation_split = 0.2)


    I think you can get the same result.
    The relationship between batch_size and validation_split is as follows.

    60000 (total number of images) = 96 (output result) * 500 (batch_size) + 60000 (total number of images) * 0.2 (validation_split)


    Also note that batch_size is 32 by default.

  • Answer # 2

    It has the following settings in model.fit ().

    batch_size = 500I'm learning 500 at the same time

    validation_split = 0.220% of the total data is passed to test

    From the above, 60000 x 0.8 ÷ 500 is 96 times.
    Therefore, the idea that "only 96 are used" is wrong, and all the data is used for either train or test.
    (I'm not sure why it's different from the book, but it should behave correctly)

Related articles