当前位置:网站首页>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)
边栏推荐
- Meta metauniverse female safety problems occur frequently. How to solve the related problems in the metauniverse?
- Feign implements dynamic URL
- ThinkPHP uses redis to update database tables
- Special copy UML notes
- From the 18th line to the first line, the new story of the network security industry
- A malware detection method for checking PLC system using satisfiability modulus theoretical model
- Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
- Stringutils and collectionutils
- Since the "epidemic", we have adhered to the "no closing" of data middle office services
- When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
猜你喜欢

Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page

How programmers find girlfriends through blind dates

What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended

Small program graduation design is based on wechat order takeout small program graduation design opening report function reference

Introduction to superresolution

Technical practice online fault analysis and solutions (Part 1)

Will the memory of ParticleSystem be affected by maxparticles

Use classname to modify style properties

How can enterprises optimize the best cost of cloud computing?

Basic editing specifications and variables of shell script
随机推荐
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Solution of cursor thickening
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
Jerry's modification setting status [chapter]
MySQL -- Introduction and use of single line functions
Ceramic metal crowns - current market situation and future development trend
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
Conditional statements of shell programming
7.1 learning content
Containerization technology stack
Logical operator, displacement operator
It's corrected. There's one missing < /script >, why doesn't the following template come out?
Development of user-defined navigation bar in uniapp
Openbionics exoskeleton project introduction | bciduino community finishing
Do you know the eight signs of a team becoming agile?
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Hash table, string hash (special KMP)
Introduction to Tianchi news recommendation: 4 Characteristic Engineering
1189. Maximum number of "balloons"
Is Shengang securities company as safe as other securities companies