我正在尝试使用 MNIST 数据集训练深度神经网络,这是我的 jupyter notebook 的一些代码:
第一个块工作正常:
# Select the hyperparameter batch size
BATCH_SIZE = 100
# Batch the train, validatiion and test data
train_data = train_data.batch(BATCH_SIZE)
validation_data = validation_data.batch(num_validation_samples)
test_data = test_data.batch(num_test_samples)
# Transform the validation data into tuples for the inputs and targets
validation_inputs, validation_targets = next(iter(validation_data))
# Defining model hyperparameters
input_size = 784
output_size = 10
hidden_layer_size = 50
# Defining the model
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28, 1)),
tf.keras.layers.Dense(hidden_layer_size, activation='relu'),
tf.keras.layers.Dense(hidden_layer_size, activation='relu'),
tf.keras.layers.Dense(output_size, activation='softmax')
])
# Select the optimizer algorithm and the loss function
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
天涯尽头无女友
相关分类