Help us understand the problem. What is going on with this article?

IoUの0.1~0.9を図にしてみた

More than 1 year has passed since last update.

はじめに

物体検出とかではIoU(Intersection over Union、Jaccard index)をよく使いますが、どのくらいの数値でどのくらいの重なり具合なのかがよくわからなかったので図にしてみました。

IoU == 0.9

#1 iou=0.90, offset=0.03.png

IoU == 0.8

#2 iou=0.80, offset=0.06.png

IoU == 0.7

#3 iou=0.70, offset=0.09.png

IoU == 0.6

#4 iou=0.60, offset=0.13.png

IoU == 0.5

#5 iou=0.50, offset=0.18.png

IoU == 0.4

#6 iou=0.40, offset=0.24.png

IoU == 0.3

#7 iou=0.30, offset=0.32.png

IoU == 0.2

#8 iou=0.20, offset=0.42.png

IoU == 0.1

#9 iou=0.10, offset=0.57.png

コード

plot_iou.py
import matplotlib
import matplotlib.pyplot as plt

import numpy as np

for i, iou in enumerate(np.linspace(1, 0, 11)):
    #   ↓t
    # □□□
    # □□□
    # □□■□□
    #   □□□
    #   □□□

    # inter = (1 - t) ** 2
    # union = 2 - inter
    # iou = inter / union
    # https://www.wolframalpha.com/input/?dataset=&i=Solve%5Bu+%3D%3D+(1+-+t)%5E2+%2F+(2+-+(1+-+t)%5E2)+%26%26+0+<%3D+t+%26%26+t+<%3D+1+%26%26+0+<%3D+u+%26%26+u+<%3D+1,+t%5D
    # → t = 1 - sqrt(2) sqrt(u/(1 + u))
    t = 1 - np.sqrt(2 * iou / (1 + iou))
    print(f'#{i} iou={iou:.2f}, offset={t:.2f}')

    fig = plt.figure()
    ax = plt.axes()
    ax.add_patch(matplotlib.patches.Rectangle(xy=(0 / 2, 0.5 + 0 / 2), width=0.5, height=0.5, color='#9999ff77'))
    ax.add_patch(matplotlib.patches.Rectangle(xy=(t / 2, 0.5 - t / 2), width=0.5, height=0.5, color='#99ff9977'))
    ax.set_aspect('equal')
    plt.savefig(f'#{i} iou={iou:.2f}, offset={t:.2f}.png')
    plt.close()
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away