anchor设置 yolo_[DL]YOLO中anchor box是如何通过聚类确定的

from os import listdir

from os.path import isfile, join

import argparse

#import cv2

import numpy as np

import sys

import os

import shutil

import random

import math

def IOU(x,centroids):

'''

:param x: 某一个ground truth的w,h

:param centroids: anchor的w,h的集合[(w,h),(),...],共k个

:return: 单个ground truth box与所有k个anchor box的IoU值集合

'''

IoUs = []

w, h = x # ground truth的w,h

for centroid in centroids:

c_w,c_h = centroid #anchor的w,h

if c_w>=w and c_h>=h: #anchor包围ground truth

iou = w*h/(c_w*c_h)

elif c_w>=w and c_h<=h: #anchor宽矮

iou = w*c_h/(w*h + (c_w-w)*c_h)

elif c_w<=w and c_h>=h: #anchor瘦长

iou = c_w*h/(w*h + c_w*(c_h-h))

else: #ground truth包围anchor means both w,h are bigger than c_w and c_h respectively

iou = (c_w*c_h)/(w*h)

IoUs.append(iou) # will become (k,) shape

return np.array(IoUs)

def avg_IOU(X,centroids):

'''

:param X: ground truth的w,h的集合[(w,h),(),...]

:param centroids: anchor的w,h的集合[(w,h),(),...],共k个

'''

n,d = X.shape

sum = 0.

for i in range(X.shape[0]):

sum+= max(IOU(X[i],centroids)) #返回一

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值