tensorflowを使ってディープラーニングのセマンティックセグメンテーションのモデルをトレーニングしたのですが、モデルの評価をするためにIoU(Intersection over Union)をtensorflow.keras.metricsのライブラリを使って求めようとするとなぜかMean IoU=1だと表示されます。トレーニングの間、Loss(binary crossentropy)は徐々に減少していたので、IoUが1だというのは間違っていると思うのですが、正しい値の算出方法がわかりません。
以下が実際に試してみたコードです。追加の情報が必要であればコメントをお願いします。
python
1from tensorflow.keras.metrics import MeanIoU 2 3#Test generator using validation data. 4test_image_batch, test_mask_batch = val_img_gen.__next__() 5print(test_mask_batch.shape) #(32, 256, 256, 3) 6 7#Convert categorical to integer for visualization and IoU calculation 8test_mask_batch_argmax = np.argmax(test_mask_batch, axis=3) 9test_pred_batch = (model.predict(test_image_batch)> 0.5).astype(np.uint8) 10print(test_pred_batch.shape) # (32, 256, 256, 1) 11test_pred_batch_argmax = np.argmax(test_pred_batch, axis=3) 12print(test_mask_batch.shape) #(32, 256, 256, 3) 13 14n_classes = 2 15IOU_keras = MeanIoU(num_classes=n_classes) 16IOU_keras.update_state(test_pred_batch_argmax, test_mask_batch_argmax) 17print("Mean IoU =", IOU_keras.result().numpy()) 18 19#output -- Mean IoU = 1.0
あなたの回答
tips
プレビュー