保存模型注意点 When saving a model’s weights, tf.keras defaults to the checkpoint format. Pass save_format=‘h5’ to use HDF5 (or pass a filename that ends in .h5).
kernel开头的参数 其表示的是w
fit 用于训练,其返回值是一个history。其里面记录了训练的时候的一些参数 所以其最后可以用于可视化
model = tf.keras.Sequential([# Adds a densely-connected layer with 64 units to the model:
keras.layers.Dense(64, activation='relu', input_shape=(32,)),# Add another:
keras.layers.Dense(64, activation='relu'),# Add a softmax layer with 10 output units:
keras.layers.Dense(10, activation='softmax')])
model.compile(optimizer=tf.keras.optimizers.RMSprop(0.01),
loss=tf.keras.losses.CategoricalCrossentropy(),
metrics=[tf.keras.metrics.CategoricalAccuracy()])#%%
data = np.random.random((1000,32))
labels = np.random.random((1000,10))
val_data = np.random.random((100,32))
val_labels = np.random.random((100,10))
history = model.fit(data, labels, epochs=10, batch_size=32,
validation_data=(val_data, val_labels))# 得到是一个字典
history.history.keys()# 输出如下
dict_keys(['loss','categorical_accuracy','val_loss','val_categorical_accuracy'])
保存模型注意点When saving a model’s weights, tf.keras defaults to the checkpoint format. Pass save_format=‘h5’ to use HDF5 (or pass a filename that ends in .h5).kernel开头的参数其表示的是wfit用于训练,其返回值是一个history。...