当前位置:网站首页>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)
边栏推荐
- SQL statement
- C import Xls data method summary V (complete code)
- MySQL -- Introduction and use of single line functions
- MPLS③
- How can enterprises optimize the best cost of cloud computing?
- Create template profile
- C library function int fprintf (file *stream, const char *format,...) Send formatted output to stream
- A little understanding of GSLB (global server load balance) technology
- Use classname to modify style properties
- Human resource management online assignment
猜你喜欢

Maximum entropy model

Conditional statements of shell programming
![After listening to the system clear message notification, Jerry informed the device side to delete the message [article]](/img/0c/52816b75eb702c7c63966578ab4969.jpg)
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
![[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

ES6 deletes an attribute in all array objects through map, deconstruction and extension operators

Use classname to modify style properties

Applet graduation project based on wechat selection voting applet graduation project opening report function reference

Huawei cloud micro certification Huawei cloud computing service practice has been stable
![[leetcode daily question] a single element in an ordered array](/img/3a/2b465589b70cd6aeec08e79fcf40d4.jpg)
[leetcode daily question] a single element in an ordered array
![When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]](/img/fb/7d4a026260f8817460cc67f06e49ae.jpg)
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
随机推荐
Difference between value and placeholder
Create template profile
Jerry's synchronous weather information to equipment [chapter]
Mobile phone battery - current market situation and future development trend
Flex flexible layout, box in the middle of the page
What are the advantages and disadvantages of data center agents?
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Some other configurations on Huawei's spanning tree
Special copy UML notes
Pyrethroid pesticide intermediates - market status and future development trend
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
LeetCode226. Flip binary tree
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
MPLS③
Is Shengang securities company as safe as other securities companies
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Jerry's modification setting status [chapter]
Long article review: entropy, free energy, symmetry and dynamics in the brain
Day05 branch and loop (II)
Hash table, string hash (special KMP)