目标检测和边界框

news/2024/7/10 1:24:19 标签: 目标检测, 深度学习, pytorch
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'))

在这里插入图片描述


http://www.niftyadmin.cn/n/764687.html

相关文章

Keep your Eyes on the Lane: Real-time Attention-guided Lane Detection

目录 1.Introduction 2. Related work 3. Proposed method 3.1. Lane and anchor representation 3.2. Backbone 3.4. Attention mechanism 3.5. Proposal prediction 3.7. Model training 3.8. Anchor fifiltering for speed effificiency 4. Experiments 4.2. CU…

LaneATT

Abstract 作者提出了一个实时、高性能的车道线检测算法,将其命名为LaneATT。 该方法基于anchor实现,且应用了注意力机制,轻量级版本的推理速度达到 250FPS全局信息可能对推断其位置至关重要,特别是在遮挡、缺失车道标记等情 况下…

A Keypoint-based Global Association Network for Lane Detection

目录 Abstract 2. Related Works 2.2. Deformable Modeling 3. Method 3.1. Global Keypoint Association 3.1.2 Starting Point Regression 3.1.3 Lane Construction 3.2. Lane-aware Feature Aggregator 4.Experiment 4.2.3 Ablation Study Abstract 提出一种新的…

Key Points Estimation and Point Instance

Abstract 在交通线路检测的情况下,需要考虑一个基本的感知模块,但需要考虑许多条件,如交通线路的数量和目标系统的计算能力。为了解决这些问题,本文提出了一种交通线路检测方法,即点实例网络(PINet);该方法…

VPGNet

在本文中,我们提出了一个统一的端到端可训练的多任务网络,联合处理在恶劣天气条件下以消失点引导的车道和道路标记检测和识别。我们解决了雨天和低光照条件,由于明显的挑战,到现在还没有得到广泛的研究。 为此,本文针对…

End-to-End Lane Marker Detection via Row-wise Classification

目录 Abstract 1. Introduction 2. Related Work 3. Proposed Method 3.1. Network Architecture Horizontal Reduction Module: 3.2. Training Lane Marker Vertex Location Loss: 4. Experiments 4.1. Results 4.2. Ablation Experiments The number of shared HRM: Loss fun…

P1449 后缀表达式

P1449 后缀表达式 题目描述 所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符号出现的顺序,严格地由左而右新进行(不用考虑运算符的优先级)。 如&a…

P1996 约瑟夫问题

约瑟夫问题 题目描述 nnn 个人围成一圈,从第一个人开始报数,数到 mmm 的人出列,再由下一个人重新从 111 开始报数,数到 mmm 的人再出圈,依次类推,直到所有的人都出圈,请输出依次出圈人的编号。 注意&…