将BiO-Net中的卷积替换为可变形卷积,bio-net代码如下
时间: 2024-05-06 07:20:08 浏览: 158
深度学习 修改卷积层
```python
import torch
import torch.nn as nn
import torch.nn.functional as F
from deform_conv import DeformConv2d
class BiONet(nn.Module):
def __init__(self):
super(BiONet, self).__init__()
self.conv1 = DeformConv2d(3, 64, kernel_size=3, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(64)
self.conv2 = DeformConv2d(64, 64, kernel_size=3, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(64)
self.conv3 = DeformConv2d(64, 128, kernel_size=3, padding=1, bias=False)
self.bn3 = nn.BatchNorm2d(128)
self.conv4 = DeformConv2d(128, 128, kernel_size=3, padding=1, bias=False)
self.bn4 = nn.BatchNorm2d(128)
self.conv5 = DeformConv2d(128, 256, kernel_size=3, padding=1, bias=False)
self.bn5 = nn.BatchNorm2d(256)
self.conv6 = DeformConv2d(256, 256, kernel_size=3, padding=1, bias=False)
self.bn6 = nn.BatchNorm2d(256)
self.conv7 = DeformConv2d(256, 512, kernel_size=3, padding=1, bias=False)
self.bn7 = nn.BatchNorm2d(512)
self.conv8 = DeformConv2d(512, 512, kernel_size=3, padding=1, bias=False)
self.bn8 = nn.BatchNorm2d(512)
self.conv9 = DeformConv2d(512, 1024, kernel_size=3, padding=1, bias=False)
self.bn9 = nn.BatchNorm2d(1024)
self.conv10 = DeformConv2d(1024, 1024, kernel_size=3, padding=1, bias=False)
self.bn10 = nn.BatchNorm2d(1024)
self.pool = nn.AvgPool2d(kernel_size=8)
self.fc = nn.Linear(1024, 10)
def forward(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
x = F.max_pool2d(x, kernel_size=2, stride=2)
x = F.relu(self.bn3(self.conv3(x)))
x = F.relu(self.bn4(self.conv4(x)))
x = F.max_pool2d(x, kernel_size=2, stride=2)
x = F.relu(self.bn5(self.conv5(x)))
x = F.relu(self.bn6(self.conv6(x)))
x = F.max_pool2d(x, kernel_size=2, stride=2)
x = F.relu(self.bn7(self.conv7(x)))
x = F.relu(self.bn8(self.conv8(x)))
x = F.max_pool2d(x, kernel_size=2, stride=2)
x = F.relu(self.bn9(self.conv9(x)))
x = F.relu(self.bn10(self.conv10(x)))
x = self.pool(x)
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
```
阅读全文