当前位置:网站首页>Object detection and bounding box
Object detection and bounding box
2022-07-19 07:47: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):
""" From top left to bottom right to middle width and height """
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):
""" From middle width and height to top left and bottom right """
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'))

边栏推荐
猜你喜欢

Product Case Interviews

How does Jenkins set the mailbox to automatically send mail?

MySql

PyCharm 界面设置

PCIe bus architecture high performance data preprocessing board / K7 325t FMC interface data acquisition and transmission card

导出文件or下载文件

修改滚动条样式

RNN卷积神经网络

Cracking Metric/Business Case/Product Sense Problems

Spark入门到精通-番外篇(Standaone集群的运维和简单操作)
随机推荐
SSM integration
Spark3.x entry to proficiency - stage 3 (in-depth analysis of the whole process of spark data processing)
Gentoo installation tutorial (systemd+gnome)
六十、清除缓存
正则表达示提取匹配内容
持续集成如何进行Jenkins管理?
4-channel fmc+ baseband signal processing board (4-channel 2G instantaneous bandwidth ad+da)
Spark3.x-实战之mysql方式实现kafka精准一次性消费
CAN FD如何应用Vector诊断工具链?
4-channel FMC interface baseband signal processing board (2 FMC interfaces, 2 fmc+ interfaces)
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Spark3.x-mysql method of actual combat to achieve Kafka precise one-time consumption
五十九 获取原型图大小
导出文件or下载文件
flowable 查询、完成、作废、删除 任务
Understanding of v2x test series v2x phase II application scenario
High concurrency day02 (concurrent package)
Install SQL developer for Galaxy Kirin desktop operating system v10sp1 (x86)
Prevent blackmail attacks through data encryption schemes
Flutter3.0 (framework) - UI rendering