@创建于:20210415
@修改于:20210415
1、背景
keras 2.3.1中的fit方法返回的history类对象。具体代码中明确写有下面的介绍:
Returns:
A History
object. Its History.history
attribute is
a record of training loss values and metrics values
at successive epochs, as well as validation loss values
and validation metrics values (if applicable).
2、返回内容介绍
History类对象包含两个属性,分别为epoch(训练轮数)和history。History所包含的内容是由compile参数的metrics确定的。
metrics的含义是衡量指标,评价指标,在compile方法中metrics默认为None。loss是损失函数。metrics是复数形式,说明可以不止一个,loss是单数形式,只能为1个。
self.model.compile(loss='mse', optimizer='adam')
history = self.model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=verbose)
# save_model(model=self.model, filepath=model_path, overwrite=True, include_optimizer=True)
self.model.save(filepath=model_path, overwrite=True, include_optimizer=True)
print(history)
print(type(history))
print(history.history)
print(type(history.history))
# 输出内容
<tensorflow.python.keras.callbacks.History object at 0x000002520AB2F430>
<class 'tensorflow.python.keras.callbacks.History'>
{'loss': [789094.4375, 。。。。。, 231444.59375]}
<class 'dict'>
history对象的history内容(history.history)是字典类型,键的内容受metrics的设置影响,值的长度与epochs值一致。
查看keras 训练模型 history.history的关键字
print(history.history.keys())