当前位置:网站首页>Pytoch residual network RESNET
Pytoch residual network RESNET
2022-07-04 01:45:00 【Jokic_ Rn】
Pytorch Residual network ResNet
See for complete training code >>Github link
ResNet structure

class Residual(nn.Module):
def __init__(self,input_channels,num_channels,use_1x1conv=False,strides=1):
super().__init__()
self.conv1 = nn.Conv2d(input_channels,num_channels,
kernel_size=3,padding=1,stride=strides)
self.conv2 = nn.Conv2d(num_channels,num_channels,
kernel_size=3,padding=1)
if use_1x1conv:
self.conv3 = nn.Conv2d(input_channels,num_channels,
kernel_size=1,stride = strides)
else:
self.conv3 = None
self.bn1 = nn.BatchNorm2d(num_channels)
self.bn2 = nn.BatchNorm2d(num_channels)
self.relu = nn.ReLU()
def forward(self,x):
Y = self.relu(self.bn1(self.conv1(x)))
Y = self.bn2(self.conv2(Y))
if self.conv3:
x = self.conv3(x)
Y = Y + x
return self.relu(Y)
def resnet_block(input_channels,num_channels,num_residuals,first_block=False):
blk = []
for i in range(num_residuals):
if i==0 and not first_block:
blk.append(Residual(input_channels,num_channels,use_1x1conv=True,strides=2))
else:
blk.append(Residual(num_channels,num_channels))
return blk
class ResNet(nn.Module):
def __init__(self):
super().__init__()
self.b1 = nn.Sequential(nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3),
nn.BatchNorm2d(64), nn.ReLU(),
nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
self.b2 = nn.Sequential(*resnet_block(64,64,2,first_block=True))
self.b3 = nn.Sequential(*resnet_block(64,128,2))
self.b4 = nn.Sequential(*resnet_block(128,256,2))
self.b5 = nn.Sequential(*resnet_block(256,512,2))
self.net = nn.Sequential(self.b1,self.b2,self.b3,self.b4,self.b5,
nn.AdaptiveAvgPool2d((1,1)),
nn.Flatten(), nn.Linear(512, 10))
def forward(self,x):
return self.net(x)
边栏推荐
- Basic editing specifications and variables of shell script
- Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
- Sequence sorting of basic exercises of test questions
- Customize redistemplate tool class
- I don't know why it can't run in the project and how to change it
- Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
- Lightweight Pyramid Networks for Image Deraining
- SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
- Openbionics exoskeleton project introduction | bciduino community finishing
- Ceramic metal crowns - current market situation and future development trend
猜你喜欢

Pratique technique | analyse et solution des défaillances en ligne (Partie 1)

JVM performance tuning and practical basic theory - medium

Do you know the eight signs of a team becoming agile?

Gee: create a new feature and set corresponding attributes

Technical practice online fault analysis and solutions (Part 1)
![[turn] solve the problem of](/img/c2/368582a8ed26254409fe391899ba41.jpg)
[turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration

How can enterprises optimize the best cost of cloud computing?

Feign implements dynamic URL

Pyinstaller packaging py script warning:lib not found and other related issues

Basic editing specifications and variables of shell script
随机推荐
MySQL -- Introduction and use of single line functions
Sequence sorting of basic exercises of test questions
All ceramic crowns - current market situation and future development trend
Three layer switching ②
QML add gradient animation during state transition
A malware detection method for checking PLC system using satisfiability modulus theoretical model
SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Infiltration learning diary day19
Do you know the eight signs of a team becoming agile?
Make drop-down menu
All metal crowns - current market situation and future development trend
Bacteriostatic circle scanning correction template
Install the pit that the electron has stepped on
1189. Maximum number of "balloons"
Openbionics exoskeleton project introduction | bciduino community finishing
Huawei cloud micro certification Huawei cloud computing service practice has been stable