- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试训练模型并在每个时期结束时计算精度和召回率。
自定义指标
class Metrics(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.precision = []
self.recall = []
def on_epoch_end(self, epoch, logs={}):
print(type(self.validation_data))
print(self.validation_data)
predict = np.round(np.asarray(self.model.predict(self.validation_data[0])))
targ = self.validation_data[1]
precision_score = sklm.precision_score(targ, predict)
recall = sklm.recall_score(targ, predict)
self.precision.append(precision_score)
self.recall.append(recall)
def avg_precision_score(self):
return np.mean(self.precision_score)
def avg_recall_score(self):
return np.mean(self.recall)
training_set = train_datagen.flow_from_directory('train/',
target_size=(dim_x,dim_y),
batch_size=8, # 16 32
class_mode='categorical')
test_set = test_datagen.flow_from_directory('test/',
target_size=(dim_x,dim_y),
batch_size=8, # 16 32
class_mode='categorical')
metrics = Metrics()
history = classifier.fit_generator(
training_set,
steps_per_epoch=2,#50,
epochs=1, # 25
validation_data=test_set,
validation_steps=10,
callbacks=[metrics]
)
最佳答案
找到了这个问题的解决方案。
在问题评论中提及
https://github.com/keras-team/keras/issues/10472
class Metrics(Callback):
def __init__(self, val_data, batch_size = 20):
super().__init__()
self.validation_data = val_data
self.batch_size = batch_size
关于python - 使用数据生成器时,Keras 自定义指标 self.validation_data 为 none,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61939790/
我从下面的链接下载并运行文件 https://github.com/keunwoochoi/keras_callbacks_example 但是它具有错误“顺序没有属性” validation_dat
所以我有一个预测输出功率的 GRU 模型。对于训练数据,我有一个 csv 文件,其中包含 2018 年的数据,而对于我的测试数据,它是一个不同的 csv 文件,其中包含 2019 年的数据。 我只需要
validation_data可以传递给model.fit,但是这个参数如何影响训练,以及如何确认validation_data的优化参数?我知道验证数据集用于模型调整最佳参数。但我无法想象有和没有
我决定从 keras 切换到 tf.keras(建议使用 here)。因此我安装了 tf.__version__=2.0.0和 tf.keras.__version__=2.2.4-tf .在我的旧版
我一直在尝试训练模型并在每个时期结束时计算精度和召回率。 自定义指标 class Metrics(keras.callbacks.Callback): def on_train_begin(s
我是 Python 和机器学习的新手。我对 keras model.fiit 中的句子“validation_data will override validation_split”感到困惑。这是否意
所以我通过以下代码让我的 keras 模型与 tf.Dataset 一起工作: # Initialize batch generators(returns tf.Dataset) batch_trai
起初它工作正常,然后我尝试在创建模型时调整一些参数,之后, print(model.history.history) 给我一本空字典。 如果有帮助,这是我的整个代码, import numpy as
我是一名优秀的程序员,十分优秀!