tensorflow2.x实时绘制训练时的损失和准确率

sgd = SGD(lr=float(model_value[3]), decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
# validation_split:0~1之间的浮点数,用来指定训练集的一定比例数据作为验证集
history=model.fit(self.x_train, self.y_train, batch_size=self.batch_size, epochs=self.epoch_size, class_weight = 'auto', validation_split=0.1)
# 绘制训练 & 验证的准确率值
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Model accuracy')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show()

# 绘制训练 & 验证的损失值
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show()
print("savemodel---------------")
model.save(os.path.join(model_value[0],'model3_3.h5'))
#输出损失和精确度
score = model.evaluate(self.x_test, self.y_test, batch_size=self.batch_size)

 

你可能感兴趣的:(python)