我已经使用CNN模型进行二进制图像分类。我能够获得准确性和损失,但不知道如何获得此类模型的混淆矩阵。还有如何绘制精度和损耗图?
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
import numpy as np
X = np.array(pickle.load(open("X.pickle","rb")))
Y = np.array(pickle.load(open("Y.pickle","rb")))
#scaling our image data
X = X/255.0
model = Sequential()
#model.add(Conv2D(64 ,(3,3), input_shape = X.shape[1:]))
model.add(Conv2D(64 ,(3,3), input_shape = X.shape[1:]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Conv2D(128 ,(3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Conv2D(256 ,(3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Conv2D(512 ,(3,3)))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Flatten())
model.add(Dense(2048))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss="binary_crossentropy",
optimizer = "adam",
metrics = ['accuracy'])
model.fit(X, Y, batch_size=32, epochs = 15, validation_split=0.1)
答案 0 :(得分:0)
在使用Tensorflow和Keras训练模型时,建议的绘制损失和准确性的方法是使用Tensorboard(https://www.tensorflow.org/tensorboard/get_started)
Tensorflow还提供了计算混淆矩阵的功能:https://www.tensorflow.org/api_docs/python/tf/math/confusion_matrix