In short, nn.Sequential() packs a series of operations into , which could include Conv2d(), ReLU(), Maxpool2d(), etc., which could be packaged to be invoked at any point, but would be a black box, which would be invoked at forward().
extract part of the AlexNet code to understand sequential:
class AlexNet(nn.Module):
def __init__(self, num_classes=1000, init_weights=False):
super(AlexNet, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 48, kernel_size=11, stride=4, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(48, 128, kernel_size=5, padding=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
nn.Conv2d(128, 192, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(192, 192, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(192, 128, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2),
)
......
def forward(self, x):
x = self.features(x)
......
return x
init__, self. Features = nn.Sequential(…)
in forward() just use self.features(x) to
Read More:
- Implementation of multithread sequential alternate execution by using lock in Java
- torch.nn.BCELoss are unsafe to autocast [How to Solve]
- Java uses lock to realize multithread sequential alternate execution mode 2
- cannot assign module before Module.__init__() call
- PyTorch CUDA error: an illegal memory access was encountered
- Pytorch RuntimeError: Error(s) in loading state_ dict for Dat aParallel:.. function submit.py Solutions for reporting errors
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\
- (EE) Failed to load module “fbdev” (module does not exist, 0)
- Undefined symbol: cblas appears after installing pytorch1.0.0_ sgemm_ Alloc error
- Jupyter cannot use pytorch’s solution
- Python scapy module installation and dependency module
- cpickle.picklingerror can’t pickle type ‘module’ attribute lookup __builtin__.module failed
- Attributeerror: ‘module’ object has no attribute ‘handlers’ — Python sub module import problem
- PyTorch – AttributeError: ‘bool‘ object has no attribute ‘sum‘
- Module not founderror: no module named ‘nets.ssd‘
- Failed to import module __PyInstaller_hooks_0_IPython required by hook for module
- An error occurred when installing pytorch version 1.7 GPU
- Pytorch TypeError: __array__() takes 1 positional argument but 2 were given
- RuntimeError:cuda runtime error (11) : invalid argument at /pytorch/aten/src/THC/generic
- Pytorch torchvision.datasets.ImageFolder Found 0 files in subfolders error for