【发布时间】:2018-12-25 23:07:37
【问题描述】:
我正在开发一个 U-net 架构,以在 10 个类中执行分段。我想在每个时代之后计算每个班级的骰子系数。
我的网络的输出是每个类别的分割掩码堆栈,形状为(b_size, rows, cols, num_classes)。在这个输出上,我通过以下方式计算每个类的骰子系数:
def dice_metric(ground_truth, prediction):
# initialize list with dice scores for each category
dice_score_list = list()
# get list of tensors with shape (rows, cols)
ground_truth_unstacked = reshape_ground_truth(ground_truth)
prediction_unstacked = tf.unstack(prediction, axis=-1)
for (ground_truth_map, prediction_map) in zip(ground_truth_unstacked, prediction_unstacked):
# calculate dice score for every class
dice_i = dice_score(ground_truth_map, prediction_map)
dice_score_list.append(dice_i)
return tf.reduce_mean(dice_score_list, axis=[0])
有什么方法可以打印骰子分数列表而不是平均值。所以在每个时期的输出是:
Epoch 107/200
- 13s - loss: 0.8896 - dice_metric: [dice_class_1, ... dice_class_10] - val_loss: 3.3417 - val_dice_metric: [val_dice_class_1, ... val_dice_class_10]
Custom Metrics 上的 Keras 文档仅考虑单个张量值(即,“自定义指标可以在编译步骤中传递。该函数需要采用 (y_true, y_pred)
作为参数并返回一个单个张量值。"
是否有任何方法/解决方法可以输出具有多个值的指标?
【问题讨论】:
-
您似乎在问 2 个问题 - 第一个是关于对 Dice 分数列表进行评估,第二个是关于 tf.Print 在 Jupyter 中不起作用。有a bug 不会打印到jupyter notebook
-
不,我的问题是如何在屏幕上打印非单值张量。
-
我认为不可能重复该问题。我在问如何为每个时代打印一个具有多个值的指标(在这种情况下每个类一个)
标签: tensorflow keras tensor