使用Tensorflow训练模型时数据大小发生变化

时间:2020-05-05 16:27:52

标签: python tensorflow keras neural-network conv-neural-network

我正在尝试在“ Cifar10”数据集上训练CNN。我导入它,当我检查形状时:

cifar10 = tf.keras.datasets.cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
y_train, y_test = y_train.flatten(), y_test.flatten()
print("x_train.shape:", x_train.shape)
print("y_train.shape", y_train.shape)

我得到的是:

x_train.shape: (50000, 32, 32, 3)
y_train.shape (50000,)

这表示我的数据有50000个实例。但是,在训练模型时:

r = model.fit(x_train, y_train, epochs=2)

日志显示:

Epoch 1/2
1563/1563 [==============================] - 7s 5ms/step - loss: 1.4601 - accuracy: 0.4819
Epoch 2/2
1563/1563 [==============================] - 7s 5ms/step - loss: 1.1266 - accuracy: 0.6025

这是说只有1563个实例。可能是什么原因造成的?

完整的笔记本可用here

1 个答案:

答案 0 :(得分:1)

在网络运行过程中看到的不是实例的数量,而是批次的数量。默认情况下,我想您的函数会将您的实例分为若干批,然后通过训练它们进行处理。我猜每个批次的默认大小是32,因此,您总共有1563个批次。

如果查看fit function的说明,则会看到默认的batch_size = 32。

相关问题