Skip to content

Instantly share code, notes, and snippets.

@ak110
Created April 29, 2018 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak110/093dc123423b27f3d012c1beece21099 to your computer and use it in GitHub Desktop.
Save ak110/093dc123423b27f3d012c1beece21099 to your computer and use it in GitHub Desktop.
IoUの0.1~0.9を図にしてみた ref: https://qiita.com/ak11/items/8e0f42f358c1f822df27
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment