DenseNet框架
Welcome file DenseNet框架 import torch import torch . nn as nn import torchvision from torch import Tensor from torch . utils . data import DataLoader import torch . nn . functional as F class Bottleneck ( nn . Module ) : def __init__ ( self , in_channels , growth_rate , bn_size = 4 ) : super ( ) . __init__ ( ) inner_channels = bn_size * growth_rate self . bn1 = nn . BatchNorm2d ( in_channels ) self . conv1 = nn . Conv2d ( in_channels , inner_channels , 1 , bias = False ) self . bn2 = nn . BatchNorm2d ( inner_channels ) self . conv2 = nn . Conv2d ( inner_channels , growth_rate , 3 , padding = 1 , bias = False ) def forward ( self , x ) : out = self . conv1 ( F . relu ( self . bn1 ( x ) ) ) out = self . conv2 ( F . relu ( self . bn2 ( x ) ) ) return torch . cat ( [ x , out ] , 1 ) class Transition ( nn . Module ) : def __init__ ( self , in_channels , compression = 0.5 ) : super ( ) . __init...