根据Resnet论文复现 Resnet50 Restnet101 Resnet152
Resnet的构成
代码
import torch
import torch.nn as nn
from torch.nn import (
Module,
Conv2d,
MaxPool2d,
AvgPool2d,
Linear,
Softmax,
ReLU,
BatchNorm2d,
Sequential
)
def Conv1(in_channel=3, out_channel=64, kernel_size=(7, 7), stride=2, padding=3):
return Sequential(
Conv2d(in_channels=in_channel, out_channels=out_channel, kernel_size=kernel_size, stride=stride, padding=padding),
MaxPool2d(kernel_size=(3, 3), stride=2, padding=1)
)
class BottleNeck(Module):
def __init__(self, in_channel, out_channel, stride=1, downsampling=False, expansion=4):
super(BottleNeck, self).__init__()
self