由于计算资源有限,这里使用的尺度增强的训练方法。也就是采取的预上采样的方式。
- import torch
- import torch.nn as nn
- from math import sqrt
-
- def conv_block(in_channel, out_channel):
- layer = nn.Sequential(
- nn.ReLU(),
- nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1, bias=False)
- )
- return layer
-
- class dense_block(nn.Module):
- def __init__(self, in_channel, growth_rate,out_channel, num_layers):
- super(dense_block, self).__init__()
- block = []
- channel = in_channel
- for i in range(num_layers):
- block.append(conv_block(channel, growth_rate))
- channel += growth_rate
- self.net = nn.Sequential(*block)
- self.conv1=nn.Sequential(
- nn.ReLU(),
- nn.Conv2d(in_channels=(num_layers)*growth_rate+in_channel,out_channels=out_channel,kernel_size=1,bias=False)
- )
-
- def forward(self, x):
- for layer in