gpt4 book ai didi

python - 训练期间每类验证的准确性

转载 作者:行者123 更新时间:2023-12-02 16:31:37 25 4
gpt4 key购买 nike

Keras 在训练期间给出了整体训练验证的准确性。

enter image description here

有什么方法可以在训练期间获得每类验证准确性

更新来自 Pycharm 的错误日志

File "C:/Users/wj96hq/PycharmProjects/PedestrianClassification/Awareness.py", line 82, in <module>
shuffle=True, callbacks=callbacks)
File "C:\Users\wj96hq\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py", line 66, in _method_wrapper
return method(self, *args, **kwargs)
File "C:\Users\wj96hq\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py", line 876, in fit
callbacks.on_epoch_end(epoch, epoch_logs)
File "C:\Users\wj96hq\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\callbacks.py", line 365, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "C:/Users/wj96hq/PycharmProjects/PedestrianClassification/Awareness.py", line 36, in on_epoch_end
x_test, y_test = self.validation_data[0], self.validation_data[1]
TypeError: 'NoneType' object is not subscriptable

最佳答案

使用它来获得每个类的准确性:


model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])


class Metrics(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self._data = []

def on_epoch_end(self, batch, logs={}):
x_test, y_test = self.validation_data[0], self.validation_data[1]
y_predict = np.asarray(model.predict(x_test))

true = np.argmax(y_test, axis=1)
pred = np.argmax(y_predict, axis=1)

cm = confusion_matrix(true, pred)
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
self._data.append({
'classLevelaccuracy':cm.diagonal() ,
})
return

def get_data(self):
return self._data

metrics = Metrics()
history = model.fit(x_train, y_train, epochs=100, validation_data=(x_test, y_test), callbacks=[metrics])
metrics.get_data()

您可以在指标类中更改代码。随心所欲..并且这个工作。你只需使用 metrics.get_data() 获取所有信息..

关于python - 训练期间每类验证的准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63394030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com