当前位置:网站首页>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)
边栏推荐
- Long article review: entropy, free energy, symmetry and dynamics in the brain
- MySQL deadly serial question 2 -- are you familiar with MySQL index?
- Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
- Portable two-way radio equipment - current market situation and future development trend
- Remember a lazy query error
- Small program graduation project based on wechat e-book small program graduation project opening report function reference
- A little understanding of GSLB (global server load balance) technology
- Three layer switching ①
- Use classname to modify style properties
- How to view the computing power of GPU?
猜你喜欢

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

MySQL deadly serial question 2 -- are you familiar with MySQL index?

Openbionics exoskeleton project introduction | bciduino community finishing

Who moved my code!

Magical usage of edge browser (highly recommended by program ape and student party)

Since the "epidemic", we have adhered to the "no closing" of data middle office services

How to use AHAS to ensure the stability of Web services?

HackTheBox-baby breaking grad

MySQL - use of aggregate functions and group by groups

Force buckle day32
随机推荐
How programmers find girlfriends through blind dates
What are the advantages and disadvantages of data center agents?
Related configuration commands of Huawei rip
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
Huawei rip and BFD linkage
51 single chip microcomputer timer 2 is used as serial port
LeetCode 168. Detailed explanation of Excel list name
求esp32C3板子連接mssql方法
Jerry's update contact [article]
SQL statement
All in one 1412: binary classification
C import Xls data method summary I (upload files and create Workbooks)
Conditional statements of shell programming
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
1189. Maximum number of "balloons"
Functions and arrays of shell scripts
技術實踐|線上故障分析及解决方法(上)
Introduction to Tianchi news recommendation: 4 Characteristic Engineering
In the process of seeking human intelligent AI, meta bet on self supervised learning
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client