盘点目标检测中的特征融合技巧(根据YOLO v4总结)
极市平台
共 13121字,需浏览 27分钟
·
2020-07-28 15:25
加入极市专业CV交流群,与 10000+来自港科大、北大、清华、中科院、CMU、腾讯、百度 等名校名企视觉开发者互动交流!
同时提供每月大咖直播分享、真实项目需求对接、干货资讯汇总,行业技术交流。关注 极市平台 公众号 ,回复 加群,立刻申请入群~
特征融合分类
Feature Pyramid Network(FPN)
![](https://filescdn.proginn.com/cf0c20b0fbdf1f95010899b9c297b0b4/0161387646b16ee12fd33487ff0fb0ce.webp)
import torch.nn as nn
import torch.nn.functional as F
import math
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, in_planes, planes, stride=1, downsample=None):
super(Bottleneck, self).__init__()
self.bottleneck = nn.Sequential(
nn.Conv2d(in_planes, planes, 1, bias=False),
nn.BatchNorm2d(planes),
nn.ReLU(inplace=True),
nn.Conv2d(planes, planes, 3, stride, 1, bias=False),
nn.BatchNorm2d(planes),
nn.ReLU(inplace=True),
nn.Conv2d(planes, self.expansion * planes, 1, bias=False),
nn.BatchNorm2d(self.expansion * planes),
)
self.relu = nn.ReLU(inplace=True)
self.downsample = downsample
def forward(self, x):
identity = x
out = self.bottleneck(x)
if self.downsample is not None:
identity = self.downsample(x)
out += identity
out = self.relu(out)
return out
class FPN(nn.Module):
def __init__(self, layers):
super(FPN, self).__init__()
self.inplanes = 64
self.conv1 = nn.Conv2d(3, 64, 7, 2, 3, bias=False)
self.bn1 = nn.BatchNorm2d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool2d(3, 2, 1)
self.layer1 = self._make_layer(64, layers[0])
self.layer2 = self._make_layer(128, layers[1], 2)
self.layer3 = self._make_layer(256, layers[2], 2)
self.layer4 = self._make_layer(512, layers[3], 2)
self.toplayer = nn.Conv2d(2048, 256, 1, 1, 0)
self.smooth1 = nn.Conv2d(256, 256, 3, 1, 1)
self.smooth2 = nn.Conv2d(256, 256, 3, 1, 1)
self.smooth3 = nn.Conv2d(256, 256, 3, 1, 1)
self.latlayer1 = nn.Conv2d(1024, 256, 1, 1, 0)
self.latlayer2 = nn.Conv2d( 512, 256, 1, 1, 0)
self.latlayer3 = nn.Conv2d( 256, 256, 1, 1, 0)
def _make_layer(self, planes, blocks, stride=1):
downsample = None
if stride != 1 or self.inplanes != Bottleneck.expansion * planes:
downsample = nn.Sequential(
nn.Conv2d(self.inplanes, Bottleneck.expansion * planes, 1, stride, bias=False),
nn.BatchNorm2d(Bottleneck.expansion * planes)
)
layers = []
layers.append(Bottleneck(self.inplanes, planes, stride, downsample))
self.inplanes = planes * Bottleneck.expansion
for i in range(1, blocks):
layers.append(Bottleneck(self.inplanes, planes))
return nn.Sequential(*layers)
def _upsample_add(self, x, y):
_,_,H,W = y.shape
return F.upsample(x, size=(H,W), mode='bilinear') + y
def forward(self, x):
c1 = self.maxpool(self.relu(self.bn1(self.conv1(x))))
c2 = self.layer1(c1)
c3 = self.layer2(c2)
c4 = self.layer3(c3)
c5 = self.layer4(c4)
p5 = self.toplayer(c5)
p4 = self._upsample_add(p5, self.latlayer1(c4))
p3 = self._upsample_add(p4, self.latlayer2(c3))
p2 = self._upsample_add(p3, self.latlayer3(c2))
p4 = self.smooth1(p4)
p3 = self.smooth2(p3)
p2 = self.smooth3(p2)
return p2, p3, p4, p5
PANet(Path Aggregation Network)
![](https://filescdn.proginn.com/d1ea8d4e8603f9e5d56bfdde07bc8962/d3b1e6a2a2bae621847b68213221a40f.webp)
![](https://filescdn.proginn.com/54b74bd5cad1d9328e119a7b107dfa7c/0b6bfd2238a273ad66f4c6b2bd31f445.webp)
![](https://filescdn.proginn.com/23ccd806f9bb441a0df07be0da1f0cb1/b80db4ecf5589c65ba3f5a7a3dc6f44b.webp)
![](https://filescdn.proginn.com/f23a34a6ed37a1615dd59a22b4d56819/4580de23685530b88894edeef194f7c5.webp)
![](https://filescdn.proginn.com/11653616a8e6d55028f1503a4b578475/1f9eba30968b7b276cbe941c31973ef5.webp)
MLFPN
![](https://filescdn.proginn.com/af4ff76eb482db2afca64e6c049ef945/e4c7fc048ecaa1b798b537e9a70f5311.webp)
![](https://filescdn.proginn.com/9a9f9d49ca9a4d5d75082b7c7d024806/b7ccd624751a64fc3e832ad9b80ba8db.webp)
![](https://filescdn.proginn.com/abf6ec73c1bbc7eb6dce8261c4a5a9e4/1b06f217593081e9cd70905221278261.webp)
![](https://filescdn.proginn.com/c749f77db73faa601b0bc0661bd1c0e1/262794e50677d92c7a8bba94b285d1ea.webp)
![](https://filescdn.proginn.com/475b1bbe801a5c5cd7f998b2391be0c6/fdb633a89d5fc9cff621ebc0154dd6f0.webp)
![](https://filescdn.proginn.com/f150974a9501e7ac5e69bb33a9d56f60/13fed376e048650db661b498b2f1fd5e.webp)
ASFF:自适应特征融合方式
![](https://filescdn.proginn.com/a55848db6381026b809a8e2f01d88622/25ecc6c9a5de6e5c61549171afd9763a.webp)
![](https://filescdn.proginn.com/d6885584a05ee50b30415b215992f303/9b416295310caaec91e6976892fb8ef1.webp)
![](https://filescdn.proginn.com/7b4fcc5e06e977536279e80af974267a/a76daf816070e3fa6813d561fa9b6ff3.webp)
![](https://filescdn.proginn.com/24587d9e3b2542c9da17d6870aca7028/6845f11c058aa72cc9b0ea3955c86737.webp)
![](https://filescdn.proginn.com/e2981c1a01045027a6320ccb82ad13d4/7188807a4ea404c7fb25d85062ba8be2.webp)
![](https://filescdn.proginn.com/5c17d269a635fc53256eaea7b68d1b08/f7c5509e79e1a105e365ad132ffc9ab6.webp)
![](https://filescdn.proginn.com/626d210a1cf74eb3a9452132785fde58/c4fcc5ff3a080bceee8b4022699704d5.webp)
![](https://filescdn.proginn.com/36157f2d6c73b79431f5ec9666e38492/eb512c7709a3a918183fffe09049b9a0.webp)
![](https://filescdn.proginn.com/a2be917193185b8c93e0945999940412/41dc539056a1bcd7a8cad8884a4c2a4d.webp)
Bi-FPN
![](https://filescdn.proginn.com/26bb22f286c21a449b72864e8558b38e/d5feb1ddfab3a53f7cd96f9de8314e55.webp)
![](https://filescdn.proginn.com/b72719eee2c160ff444231226c93ea74/b4bff0cd2ac833b06b5cf602ef57fb76.webp)
![](https://filescdn.proginn.com/3436d7a8f584121861904460943f4d9c/6e2f7e5c1d6a5069f15cd08c9efa21f9.webp)
![](https://filescdn.proginn.com/7f197fb155f430d7672a544c9950855d/fee8518b5d6d240760a217a552b1d9ab.webp)
![](https://filescdn.proginn.com/4a57eb8da8f4fffa86f15741ffd4d98f/d645603311eab9816067ee3b861838a1.webp)
![](https://filescdn.proginn.com/22bdf5e3759d2576833bc3978aac48f2/43c9776989e6abeef67954f2d6764041.webp)
评论