当前位置:网站首页>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'))

边栏推荐
- 目标检测和边界框
- 自用的一套Jenkins样式
- Tail -f pause method
- Spark3.x入门到精通-阶段七(spark动态资源分配)
- Slackware 14.2 installing KDE 5 plasma
- Spark introduction to proficient - external part (operation and maintenance and simple operation of standaone cluster)
- Flink introduction to practice - phase II (illustrated runtime architecture)
- What if Jenkins forgets his password?
- CAN FD如何应用Vector诊断工具链?
- RNN卷积神经网络
猜你喜欢

三伏天逛逛北京动物园

SQL skimming summary SQL leetcode review

Basic lighting knowledge of shader introduction

@ConditionalOnMissingBean 如何实现覆盖第三方组件中的 Bean

Xiaoyi and you talk about how to realize c-v2x HIL test in v2x test series (2022 version)

OpenSUSE install Netease cloud music (tumblefeed) (LEAP)

Read gptp in a quarter of an hour

xgboos-hperopt

Install SQL developer for Galaxy Kirin desktop operating system v10sp1 (x86)

京东购买意向预测(四)
随机推荐
SQL skimming summary SQL leetcode review
Review of 4246 Algorithms for Data Science
Component emit Foundation
FMC sub card: 8-channel 125msps sampling rate 16 bit AD acquisition sub card
High concurrency day04 (Zab protocol, observer, NC, Avro, RPC)
express
Slackware 14.2 installing KDE 5 plasma
How can FD apply the vector diagnostic tool chain?
京东购买意向预测(三)
Flutter3.0(framework框架)——UI渲染
Canel-简介&使用
Spark3.x-mysql method of actual combat to achieve Kafka precise one-time consumption
This article introduces you to SOA interface testing
OpenSUSE install Netease cloud music (tumblefeed) (LEAP)
How to choose flash for new products?
实操教程:CANoe在CAN总线测试中的应用
一刻钟读懂gPTP
PCIe bus architecture high performance data preprocessing board / K7 325t FMC interface data acquisition and transmission card
机器学习之随机森林
js数组交集、差集和并集