我试图在删除之前使用Keras提供的代码.这是代码:
def precision(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def recall(y_true, y_pred):
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def fbeta_score(y_true, y_pred, beta=1):
if beta < 0:
raise ValueError('The lowest choosable beta is zero (only precision).')
# If there are no true positives, fix the F score at 0 like …Run Code Online (Sandbox Code Playgroud) 似乎已经有几个线程/问题,但在我看来,这已经解决了:
https://github.com/fchollet/keras/issues/6050
https://github.com/fchollet/keras/issues/3230
人们似乎遇到了变量初始化或度量标准为0的问题.
我需要计算不同的细分指标,并希望在我的Keras模型中包含tf.metric.mean_iou.这是迄今为止我能够想到的最好的:
def mean_iou(y_true, y_pred):
score, up_opt = tf.metrics.mean_iou(y_true, y_pred, NUM_CLASSES)
K.get_session().run(tf.local_variables_initializer())
return score
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=[mean_iou])
Run Code Online (Sandbox Code Playgroud)
此代码不会抛出任何错误,但mean_iou总是返回0.我相信这是因为不评估up_opt.我已经看到在TF 1.3之前,人们已经建议使用control_flow_ops.with_dependencies([up_opt],score)来实现这一点.这在TF 1.3中似乎不太可能.
总之,如何评估Keras 2.0.6中的TF 1.3指标?这似乎是一个非常重要的特征.
我在Keras(2.1.5)中使用TensorFlow后端训练了一个神经网络,我还使用了keras-contrib(2.0.8)库来添加CRF层作为网络的输出.
我想知道在使用NN对测试集进行预测后,如何获得每个类的精度,召回率和f1分数.
我有一个带有 5 个标签的多标签分类问题(例如[1 0 1 1 0])。因此,我希望我的模型在固定召回、精确召回 AUC 或 ROC AUC 等指标上有所改进。
使用binary_crossentropy与我想要优化的性能测量没有直接关系的损失函数(例如)是没有意义的。因此,我想使用 TensorFlowglobal_objectives.recall_at_precision_loss()或类似的作为损失函数。
我不是在寻找实现tf.metrics. 我已经在以下方面取得了成功:https : //stackoverflow.com/a/50566908/3399066
我认为我的问题可以分为两个问题:
global_objectives.recall_at_precision_loss()或类似?全局目标GitHub页面loss_layers_example.py上有一个文件(同上)。但是,由于我对TF没有太多经验,所以我不太了解如何使用它。另外,谷歌搜索TensorFlow recall_at_precision_loss example或TensorFlow Global objectives example不会给我任何更清晰的例子。
如何global_objectives.recall_at_precision_loss()在简单的 TF 示例中使用?
会像(在 Keras 中):model.compile(loss = ??.recall_at_precision_loss, ...)就足够了吗?我的感觉告诉我它比这更复杂,因为在 …
在我的项目中,我使用的是预制估算器DNNClassifier。这是我的估算器:
model = tf.estimator.DNNClassifier(
hidden_units=network,
feature_columns=feature_cols,
n_classes= 2,
activation_fn=tf.nn.relu,
optimizer=tf.train.ProximalAdagradOptimizer(
learning_rate=0.1,
l1_regularization_strength=0.001
),
config=chk_point_run_config,
model_dir=MODEL_CHECKPOINT_DIR
)
Run Code Online (Sandbox Code Playgroud)
当我使用评估模型时eval_res = model.evaluate(..),出现以下警告:
警告:tensorflow:梯形规则会产生不正确的PR-AUC。请改用“ careful_interpolation”。
我如何才能切换到autumn_interpolation以从该evaluate()方法获得正确的结果?
Tensorflow版本: 1.8