当前位置:网站首页>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)
边栏推荐
- Make drop-down menu
- [turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration
- Audio resource settings for U3D resource management
- 51 single chip microcomputer timer 2 is used as serial port
- Special copy UML notes
- Summary of JWT related knowledge
- Will the memory of ParticleSystem be affected by maxparticles
- String hash, find the string hash value after deleting any character, double hash
- Related configuration commands of Huawei rip
- How programmers find girlfriends through blind dates
猜你喜欢

In the process of seeking human intelligent AI, meta bet on self supervised learning
![Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]](/img/8b/ff062f34d36e1caa9909c8ab431daf.jpg)
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]

【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client

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

Hash table, string hash (special KMP)

Small program graduation project based on wechat e-book small program graduation project opening report function reference

Solution of cursor thickening

How can enterprises optimize the best cost of cloud computing?

Feign implements dynamic URL

A fan summed up so many interview questions for you. There is always one you need!
随机推荐
Force deduction solution summary 1189- maximum number of "balloons"
求esp32C3板子連接mssql方法
Make drop-down menu
Remember a lazy query error
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
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
MySQL deadly serial question 2 -- are you familiar with MySQL index?
C import Xls data method summary III (processing data in datatable)
What are the advantages and disadvantages of data center agents?
All metal crowns - current market situation and future development trend
Small program graduation project based on wechat reservation small program graduation project opening report reference
AI helps make new breakthroughs in art design plagiarism retrieval! Professor Liu Fang's team paper was employed by ACM mm, a multimedia top-level conference
File contains vulnerability summary
Functions and arrays of shell scripts
I don't know why it can't run in the project and how to change it
C library function int fprintf (file *stream, const char *format,...) Send formatted output to stream
MySQL statement learning record
How to delete MySQL components using xshell7?
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
Summary of common tools and technical points of PMP examination