我正在研究一个 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])
Run Code Online (Sandbox Code Playgroud)
有什么方法可以打印骰子分数列表而不是平均值。所以在每个时期的输出是:
Epoch 107/200
- 13s - loss: 0.8896 - dice_metric: [dice_class_1, ... dice_class_10] - val_loss: 3.3417 - …Run Code Online (Sandbox Code Playgroud)