当前位置:网站首页>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)
边栏推荐
- The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
- Setting function of Jerry's watch management device [chapter]
- Pyinstaller packaging py script warning:lib not found and other related issues
- Hbuilder link Xiaoyao simulator
- Should enterprises start building progressive web applications?
- Skku| autonomous handover decision of UAV Based on deep reinforcement learning
- Make drop-down menu
- How to use AHAS to ensure the stability of Web services?
- Huawei cloud micro certification Huawei cloud computing service practice has been stable
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
猜你喜欢
Technical practice online fault analysis and solutions (Part 1)
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
In the process of seeking human intelligent AI, meta bet on self supervised learning
Bacteriostatic circle scanning correction template
MySQL statement learning record
Douban scoring applet Part-3
How programmers find girlfriends through blind dates
How to use AHAS to ensure the stability of Web services?
Small program graduation project based on wechat reservation small program graduation project opening report reference
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
随机推荐
Summary of common tools and technical points of PMP examination
MySQL -- Introduction and use of single line functions
Infiltration learning diary day19
TP5 automatic registration hook mechanism hook extension, with a complete case
Bacteriostatic circle scanning correction template
2022 new examination questions for safety management personnel of hazardous chemical business units and certificate examination for safety management personnel of hazardous chemical business units
Setting function of Jerry's watch management device [chapter]
Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
Hash table, string hash (special KMP)
Future source code view -juc series
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
Pratique technique | analyse et solution des défaillances en ligne (Partie 1)
Experimental animal models - current market situation and future development trend
MySQL statement learning record
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
Flex flexible layout, box in the middle of the page
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Pyrethroid pesticide intermediates - market status and future development trend