博文

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...

ResNet框架

Welcome file ResNet框架 from msilib import make_id import torch import torch . nn as nn from sqlalchemy . testing . plugin . plugin_base import config from torch import Tensor from mcmicm . rSLDS模型 . model2_with_penalty import weights , gamma class BasicBlock ( nn . Module ) : expansion : int = 1 # 通道扩展系数 def __init__ ( self , in_channels : int , out_channels : int , stride : int = 1 , downsample : nn . Module = None ) : super ( ) . __init__ ( ) self . conv1 = nn . Conv2d ( in_channels , out_channels , kernel_size = 3 , stride = stride , padding = 1 , bias = False ) self . bn1 = nn . BatchNorm2d ( out_channels ) self . relu = nn . ReLU ( inplace = True ) self . conv2 = nn . Conv2d ( out_channels , out_channels , kernel_size = 3 , padding = 1 , bias = False ) self . bn2 = nn . BatchNorm2d ( out_channels ) self . downsample = downsample def forward ( self , x : Tensor ) - > ...

GoogLeNet框架

Welcome file import torch import torch . nn as nn import torch . nn . functional as F from torch . nn . modules . module import T from torch . utils . hooks import RemovableHandle class InceptionModule ( nn . Module ) : def __init__ ( self , in_channels , ch1x1 , ch3x3red , ch3x3 , ch5x5red , ch5x5 , pool_proj ) : super ( ) . __init__ ( ) # 分支1:1x1卷积 self . branch1 = nn . Conv2d ( in_channels , ch1x1 , kernel_size = 1 ) # 分支2:1x1 -> 3x3卷积 self . branch2 = nn . Sequential ( nn . Conv2d ( in_channels , ch3x3red , kernel_size = 1 ) , nn . Conv2d ( ch3x3red , ch3x3 , kernel_size = 3 , padding = 1 ) ) # 分支3:1x1 -> 5x5 卷积 self . branch3 = nn . Sequential ( nn . Conv2d ( in_channels , ch5x5red , kernel_size = 1 ) , nn . Conv2d ( ch5x5red , ch5x5 , kernel_size = 5 , padding = 2 ) ) # 分支4:3x3 池化 -> 1x1 卷积 self . branch4 = nn . Sequential ( nn . MaxPool2d ( kernel_size = 3 , stride = 1...