Model.fit() 在 Tensorflow 2 中输出

Model.fit() output in Tensorflow 2

我正在尝试将 TF 2.0 用于批量大小为 128 的 MNIST 数据集。

在学习过程中,我在 EPOCH 中收到以下消息。如果我的批量大小是 128,375 表示什么?

纪元 13/200 375/375 [==============================] - 2 秒 4 毫秒/步 - 损失:0.2351 - 精度:0.9330 - val_loss: 0.2258 - val_accuracy: 0.9370

import tensorflow as tf
import numpy as np
from tensorflow import keras
# Network and training parameters.
EPOCHS = 200
BATCH_SIZE = 128
VERBOSE = 1
NB_CLASSES = 10   # number of outputs = number of digits
N_HIDDEN = 128
VALIDATION_SPLIT = 0.2 # how much TRAIN is reserved for VALIDATION
# Loading MNIST dataset.
# verify
# You can verify that the split between train and test is 60,000, and 10,000 respectively. 
# Labels have one-hot representation.is automatically applied
mnist = keras.datasets.mnist
(X_train, Y_train), (X_test, Y_test) = mnist.load_data()
# X_train is 60000 rows of 28x28 values; we  --> reshape it to 
# 60000 x 784.
RESHAPED = 784
#
X_train = X_train.reshape(60000, RESHAPED)
X_test = X_test.reshape(10000, RESHAPED)
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
# Normalize inputs to be within in [0, 1].
X_train /= 255
X_test /= 255
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')
# One-hot representation of the labels.
Y_train = tf.keras.utils.to_categorical(Y_train, NB_CLASSES)
Y_test = tf.keras.utils.to_categorical(Y_test, NB_CLASSES)

model = tf.keras.models.Sequential()
model.add(keras.layers.Dense(N_HIDDEN,
          input_shape=(RESHAPED,),
          name='dense_layer', activation='relu'))
model.add(keras.layers.Dense(N_HIDDEN,
          name='dense_layer_2', activation='relu'))
model.add(keras.layers.Dense(NB_CLASSES,
          name='dense_layer_3', activation='softmax'))

# Compiling the model.
model.compile(optimizer='SGD', 
              loss='categorical_crossentropy',
              metrics=['accuracy'])


# Training the model.
model.fit(X_train, Y_train,
               batch_size=BATCH_SIZE, epochs=EPOCHS,
               verbose=VERBOSE, validation_split=VALIDATION_SPLIT)

375 是每个时期的步数您的模型必须完成才能完成一个时期。 (每个时期您的模型将处理 steps_per_epoch 个批次)

steps_per_epoch = len(X_train) // batch_size

但对于您的情况,因为您已将 validation_split 参数指定为 model.fit()

的 0.20 值
steps_per_epoch = (len(X_train)*(1-VALIDATION_SPLIT)) // batch_size

所以插入值,

steps = ((60,000) * (1-0.20)) // 128 = 375