pytorch使用DCN

  • 前言
  • 正文

前言

关于DCN可形变卷积神经网络相信大家也都不陌生,使用额外的feature map区学习offset,以此达到可形变的效果。感觉和attention比较相似?
但是网络实现的代码版本各不相同,编译环境存在很多难以协调等等的问题。而MMopenlab是一个非常不错的工具,其有着实现可形变卷积的方法,因此本文只是做一个引入,如何像正常使卷积一样的使用DCN

正文

from mmcv.ops import DeformConv2dPack
import torch
from torch import nn
from thop import profile
import timeclass Conv(nn.Module):def __init__(self,indim,outdim,kerner=3,stride=1):super(Conv, self).__init__()self.conv1 = nn.Conv2d(indim,outdim,kernel_size=kerner,stride=stride,padding=kerner//2)self.act = nn.LeakyReLU(0.1)self.bn = nn.BatchNorm2d(outdim)def forward(self,x):return self.bn(self.act(self.conv1(x)))class Dconv(nn.Module):def __init__(self, indim, outdim, kerner=3, stride=1):super(Dconv, self).__init__()self.conv1 = DeformConv2dPack(indim, outdim, kernel_size=kerner, stride=stride, padding=kerner // 2,deform_groups=2)self.act = nn.LeakyReLU(0.1)self.bn = nn.BatchNorm2d(outdim)def forward(self, x):return self.bn(self.act(self.conv1(x)))

接下来是对两个定义的结构进行测试

conv1 = Conv(128,256).cuda()
dconv1 = Dconv(128,256).cuda()
input = torch.randn(4,128,640,640).cuda()t1 = time.time()
out1 = conv1(input)
t2 = time.time()
print('conv:',t2-t1)
total = sum([param.nelement() for param in conv1.parameters()])
print("Number of parameter: %.2fM" % (total / 1e6))
out2 = dconv1(input)
t3 =time.time()
print('dconv:',t3-t2)
total = sum([param.nelement() for param in dconv1.parameters()])
print("Number of parameter: %.2fM" % (total / 1e6))print(out1.shape)
print(out2.shape)

相比较正常的CONV而言,DCN的参数量更大一些。

pytorch使用DCN相关推荐

  1. 复现 MonoEF:Monocular 3D Object Detection: An Extrinsic Parameter Free Approach

    复现 MonoEF:Monocular 3D Object Detection: An Extrinsic Parameter Free Approach 时间:2022年7月13日 代码连接: ht ...

  2. dcn和dcnv2 torch

    dcn也叫可变形卷积 c++ cu版编译参考我的另一篇博客: DCNv2 windows编译 2021ok_jacke121的专栏-CSDN博客 pytorch版,输入x,参考我另一篇博客: 可变形卷 ...

  3. PyTorch开源物体检测工具包

    MMDetection是一个基于PyTorch的开源物体检测工具包.该工具包采用模块化设计,支持多种流行的物体检测和实例分割算法,并且可以灵活地进行拓展,在速度和显存消耗上也具有优势.(https:/ ...

  4. gan pytorch 实例_重新思考一阶段实例分割(Rethinking Single Shot Instance Segmentation)

    点击上方"CVer",选择加"星标"或"置顶" 重磅干货,第一时间送达 作者:谢恩泽 https://zhuanlan.zhihu.com/ ...

  5. pytorch C++部署模型 ONNX tensorRT

    (1) C++部署pytorch模型(上) (2) TensorRT5介绍及Pytorch转TensorRT5代码示例 TensorRT的使用步骤:(假设以及有一个训练好的模型) (1) 根据模型创建 ...

  6. 目标检测 dcn v2_使用Detectron2分6步进行目标检测

    目标检测 dcn v2 Have you ever tried training an object detection model using a custom dataset of your ow ...

  7. pytorch实现文本分类_使用变形金刚进行文本分类(Pytorch实现)

    pytorch实现文本分类 'Attention Is All You Need' "注意力就是你所需要的" New deep learning models are introd ...

  8. resnet系列+mobilenet v2+pytorch代码实现

    一.resnet系列backbone import torch.nn as nn import math import torch.utils.model_zoo as model_zooBatchN ...

  9. 《南溪的目标检测学习笔记》——DCN(DCNv2)的学习笔记

    1 前言 DCN是一个常见的技术,在Deformable-DETR跟PP-YOLO中都有用到DCN: 论文:<Deformable ConvNets v2: More Deformable, B ...

  10. Alphapose - Windows下Alphapose(Pytorch 1.1+)版本2021最新环境配置步骤以及踩坑说明

    文章目录 1 Alphapose 2 环境配置 2.1 官方安装说明 2.2 Anaconda创建虚拟环境Alphapose 2.3 获取Alphapose仓库 2.4 安装相关依赖库 2.4.1 激 ...

最新文章

  1. 清华唐杰:GPT-3表示能力已经接近人类了,但它有一个阿喀琉斯之踵
  2. dz 数据表分析!!!
  3. linux 内核探测kprobe 初步了解
  4. html的悬浮框 贼简单 记录一下
  5. 《统计学》学习笔记之分类数据分析
  6. linux shell 嵌套expect 与服务器交互脚本
  7. 小米全系865旗舰大降价,买就完事了!
  8. BZOJ1251序列终结者——非旋转treap
  9. 【李宏毅2020 ML/DL】P13 Backpropagation | 神经网络反向传播到底是怎么计算的
  10. 冒泡排序面向对象java_冒泡排序
  11. 区块链 以太坊 solidity 如何比较2个字符串相等
  12. 14.6.211213163AWVS扫描器破解流程
  13. iOS蓝牙开发学习(2)--连接、读写、DFU升级篇
  14. 如何申请免费163邮箱?如何申请163邮箱账号?
  15. 【R语言】【可视化】 之 维恩图
  16. cheng@ARM结构与编程之day3-MOV LSL
  17. Harmonious Graph(并查集)
  18. Pytorch SoftMax回归
  19. css -- 为什么:last-child 无效?
  20. FileZilla使用手册

热门文章

  1. vs2019无法启动程序 系统找不到指定文件
  2. 使用Apache搭建Web网站服务器
  3. android系统字体目录在哪个文件夹,安卓系统System目录下文件夹功能详解
  4. 数学规划求解器lp_solve超详细教程
  5. 如何用MATLAB读取大文本文件
  6. opc java_Java OPC 代码
  7. a标签实现下载图片功能
  8. scrapy框架—spiders
  9. CTF逆向(Reverse)知识点总结
  10. python中sys的用法