日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pytorch使用DCN

發(fā)布時間:2023/12/16 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pytorch使用DCN 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

pytorch使用DCN

  • 前言
  • 正文

前言

關(guān)于DCN可形變卷積神經(jīng)網(wǎng)絡(luò)相信大家也都不陌生,使用額外的feature map區(qū)學(xué)習(xí)offset,以此達到可形變的效果。感覺和attention比較相似?
但是網(wǎng)絡(luò)實現(xiàn)的代碼版本各不相同,編譯環(huán)境存在很多難以協(xié)調(diào)等等的問題。而MMopenlab是一個非常不錯的工具,其有著實現(xiàn)可形變卷積的方法,因此本文只是做一個引入,如何像正常使卷積一樣的使用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)))

接下來是對兩個定義的結(jié)構(gòu)進行測試

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的參數(shù)量更大一些。

總結(jié)

以上是生活随笔為你收集整理的pytorch使用DCN的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。