欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

yolov3 anchor 理解

发布时间:2025/4/5 编程问答 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 yolov3 anchor 理解 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
yolov3 中的anchor 的框框是在训练集中聚类所得,在yolov3 中每个格子有9个anchor
mask52= [0,1,2]mask26= [3,4,5]mask13= [6,7,8]anchors=[ 10,13, 16,30, 33,23,30,61, 62,45, 59,119,116,90, 156,198, 373,326]
  • yolov3 有9个anchor 点
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 19 20:54:27 2021@author: ledi """#!/usr/bin/env python # -*- coding:utf-8 -*- import cv2 def showPrioriBox():#输入图片尺寸INPUT_SIZE = 416mask52= [0,1,2]mask26= [3,4,5]mask13= [6,7,8]#0--->(10,13) #1--->(16,30) .....anchors=[ 10,13, 16,30, 33,23,30,61, 62,45, 59,119,116,90, 156,198, 373,326]FEATURE_MAP_SIZE=26SHOW_ALL_FLAG = True # 显示所有的方框GRID_SHOW_FLAG =True# cap = cv2.VideoCapture("street.jpg")picPath = './car.jpg'picName = picPath.split('/')[-1]img = cv2.imread(picPath)print("original img.shape: ",img.shape) # (1330, 1330, 3)img = cv2.resize(img,(INPUT_SIZE, INPUT_SIZE))# 显示网格if GRID_SHOW_FLAG:height, width, channels = img.shapeGRID_SIZEX = int(INPUT_SIZE/FEATURE_MAP_SIZE)for x in range(0, width - 1, GRID_SIZEX):cv2.line(img, (x, 0), (x, height), (150, 150, 255), 1, 1) # x gridGRID_SIZEY = int(INPUT_SIZE / FEATURE_MAP_SIZE)for y in range(0, height - 1, GRID_SIZEY):cv2.line(img, (0, y), (width, y), (150, 150, 255), 1, 1) # x grid# END:显示网格 # cv2.imshow('Hehe', img) # cv2.imwrite('./' + picName.split('.')[0] + '_grid.' + picName.split('.')[1], img)if SHOW_ALL_FLAG or FEATURE_MAP_SIZE==13:for ele in mask13:# print(ele)# import cv2 图片 起点 终点 颜色 厚度# cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2 )# x1,y1 ------# | |# | |# | |# --------x2,y2cv2.rectangle(img, (int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2]), int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2 + 1]) ),(int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2]),int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2 + 1])), (0, 255-ele*10, 0), 2)# cv2.imwrite('./' + picName.split('.')[0] + '_saveMask13.' + picName.split('.')[1], img)# cv2.imshow('img', img)if SHOW_ALL_FLAG or FEATURE_MAP_SIZE==26:for ele in mask26:# print(ele)cv2.rectangle(img, (int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2]), int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2 + 1]) ),(int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2]),int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2 + 1]) ), (255, 255-ele*10, 0), 2)# cv2.imwrite('./' + picName.split('.')[0] + '_saveMask26.' + picName.split('.')[1], img)if SHOW_ALL_FLAG or FEATURE_MAP_SIZE==52:for ele in mask52:# print(ele)cv2.rectangle(img, (int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2]), int(INPUT_SIZE * 0.5 - 0.5*anchors[ ele * 2 + 1]) ),(int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2]),int(INPUT_SIZE * 0.5 + 0.5*anchors[ ele * 2 + 1])), (0, 255-ele*10, 255), 1)# cv2.imwrite('./' + picName.split('.')[0] + '_saveMask52.' + picName.split('.')[1], img)cv2.imwrite('./' + picName.split('.')[0] + '_allSave.' + picName.split('.')[1], img)cv2.imshow('img', img)while cv2.waitKey(1000) != 27: # loop if not get ESC.if cv2.getWindowProperty('img', cv2.WND_PROP_VISIBLE) <= 0:breakcv2.destroyAllWindows()if __name__ == '__main__':showPrioriBox()

总结

以上是生活随笔为你收集整理的yolov3 anchor 理解的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。