計算類 0 和/或 1 的 Intersection-Over-Union 指標。
用法
tf.keras.metrics.BinaryIoU(
target_class_ids:Union[List[int], Tuple[int, ...]] = (0, 1),
threshold=0.5,
name=None,
dtype=None
)參數
-
target_class_ids返回指標的目標類 ID 的元組或列表。選項是[0],[1]或[0, 1]。使用[0](或[1]),返回類 0(或類 1)的 IoU 度量。使用[0, 1],將返回兩個類的 IoU 平均值。 -
threshold如果 logit 低於threshold,則適用於預測 logits 的閾值將它們轉換為預測類 0 或如果 logit 高於threshold則將其轉換為預測類 1。 -
name(可選)指標實例的字符串名稱。 -
dtype(可選)度量結果的數據類型。
一般定義和計算:
Intersection-Over-Union 是語義圖像分割的常用評估指標。
對於單個類,IoU 指標定義如下:
iou = true_positives / (true_positives + false_positives + false_negatives)
為了計算 IoU,預測被累積在一個混淆矩陣中,由 sample_weight 加權,然後從中計算度量。
如果 sample_weight 是 None ,則權重默認為 1。使用 0 的 sample_weight 來屏蔽值。
此類可用於計算二進製分類任務的 IoU,其中預測以 logits 形式提供。首先將 threshold 應用於預測值,以便將低於 threshold 的值轉換為 0 類,將高於 threshold 的值轉換為 1 類。
然後計算類 0 和 1 的 IoU,返回由 target_class_ids 指定的類的 IoU 平均值。
注意:使用 threshold=0 時,此指標具有與 IoU 相同的行為。
單機使用:
m = tf.keras.metrics.BinaryIoU(target_class_id=[0, 1], threshold=0.3)
m.update_state([0, 1, 0, 1], [0.1, 0.2, 0.4, 0.7])
m.result().numpy()
0.33333334
m.reset_state()
m.update_state([0, 1, 0, 1], [0.1, 0.2, 0.4, 0.7],
sample_weight=[0.2, 0.3, 0.4, 0.1])
# cm = [[0.2, 0.4],
# [0.3, 0.1]]
# sum_row = [0.6, 0.4], sum_col = [0.5, 0.5], true_positives = [0.2, 0.1]
# iou = [0.222, 0.125]
m.result().numpy()
0.17
compile() API 的用法:
model.compile(
optimizer='sgd',
loss='mse',
metrics=[tf.keras.metrics.BinaryIoU(target_class_id=[0], threshold=0.5)])
相關用法
- Python tf.keras.metrics.BinaryIoU.merge_state用法及代碼示例
- Python tf.keras.metrics.BinaryAccuracy用法及代碼示例
- Python tf.keras.metrics.BinaryCrossentropy用法及代碼示例
- Python tf.keras.metrics.BinaryCrossentropy.merge_state用法及代碼示例
- Python tf.keras.metrics.BinaryAccuracy.merge_state用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
- Python tf.keras.metrics.Hinge用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalAccuracy.merge_state用法及代碼示例
- Python tf.keras.metrics.RootMeanSquaredError用法及代碼示例
- Python tf.keras.metrics.SparseCategoricalCrossentropy.merge_state用法及代碼示例
- Python tf.keras.metrics.sparse_categorical_accuracy用法及代碼示例
- Python tf.keras.metrics.FalseNegatives用法及代碼示例
- Python tf.keras.metrics.TrueNegatives用法及代碼示例
- Python tf.keras.metrics.RecallAtPrecision.merge_state用法及代碼示例
- Python tf.keras.metrics.SpecificityAtSensitivity用法及代碼示例
- Python tf.keras.metrics.Mean用法及代碼示例
- Python tf.keras.metrics.poisson用法及代碼示例
- Python tf.keras.metrics.LogCoshError用法及代碼示例
- Python tf.keras.metrics.MeanSquaredLogarithmicError用法及代碼示例
- Python tf.keras.metrics.FalsePositives.merge_state用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.keras.metrics.BinaryIoU。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
