当前位置:网站首页>目标检测和边界框
目标检测和边界框
2022-07-17 05:28:00 【Recursi】
import torch
from d2l import torch as d2l
d2l.set_figsize()
img = d2l.plt.imread('./catdog.jpg')
d2l.plt.imshow(img)
#@save
def box_corner_to_center(boxes):
"""从左上右下到中间宽和高"""
x1,y1,x2,y2 = boxes[:,0],boxes[:,1],boxes[:,2],boxes[:,3]
cx = (x1 + x2)/2
cy = (y1 + y2)/2
w = x2 - x1
h = y2 - y1
boxes = torch.stack((cx,cy,w,h),axis = -1)
return boxes
#@save
def box_center_to_corner(boxes):
"""从中间宽高到左上右下"""
cx,cy,w,h = boxes[:,0],boxes[:,1],boxes[:,2],boxes[:,3]
x1 = cx - 0.5*w
y1 = cy - 0.5*h
x2 = cx + 0.5*w
y2 = cy + 0.5*h
boxes = torch.stack((x1,y1,x2,y2),axis = -1)
return boxes
dog_bbox,cat_bbox = [60.0,45.0,378.0,516.0],[400.0,112.0,655.0,493.0]
boxes = torch.tensor((dog_bbox, cat_bbox))
def bbox_to_rect(bbox,color):
return d2l.plt.Rectangle(
xy = (bbox[0],bbox[1]),width = bbox[2] - bbox[0],height = bbox[3] - bbox[1],
fill = False,edgecolor = color,linewidth = 2
)
img = d2l.plt.imread('./catdog.jpg')
fig = d2l.plt.imshow(img)
fig.axes.add_patch(bbox_to_rect(dog_bbox, 'blue'))
fig.axes.add_patch(bbox_to_rect(cat_bbox, 'red'))

边栏推荐
猜你喜欢
随机推荐
泰坦尼克号乘客获救预测(进阶)
Solve MySQL (1064) error: 1064 - you have an error in your SQL syntax;
Review of 4705 NLP
express
MySQL decompression installation steps (Windows)
Comparative analysis of the differences between nor and NAND
Xiaodi network security note information collection CDN bypass technology (7)
FreeBSD 12 changing the background of the startup interface
实时数据仓库-从0到1实时数据仓库设计&实现(SparkStreaming3.x)
环境变量和文件夹放置位置
Review of 4121 Computer System for Data Science
A2B音频总线在智能座舱中的应用
一文带你了解SOA接口测试
Summary of Statistics for Interview
Summary of Statistics for Interview
Flink入门到实战-阶段二(图解运行时架构)
Cracking Metric/Business Case/Product Sense Problems
Redis(二) - Jedis
Review - 5703 Statistical Inference and Modeling
Spark3.x entry to proficiency - stage 6 (RDD advanced operator explanation & Illustration & shuffle tuning)








