Spaces:
Build error
Build error
| # AUTOGENERATED! DO NOT EDIT! File to edit: simple_network.ipynb. | |
| # %% auto 0 | |
| __all__ = ['LeNet5'] | |
| # %% simple_network.ipynb 1 | |
| #%matplotlib inline | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| import torch.optim as optim | |
| import torchvision | |
| import torchvision.transforms as transforms | |
| import matplotlib | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| # %% simple_network.ipynb 4 | |
| class LeNet5(nn.Module): | |
| def __init__(self, num_classes): | |
| super().__init__() | |
| self.l1 = nn.Sequential( | |
| nn.Conv2d(in_channels=1, out_channels=6, kernel_size=5, stride=1, padding=2), # 28*28-->32*32-->28*28 | |
| nn.BatchNorm2d(6), | |
| nn.ReLU(), | |
| nn.MaxPool2d(kernel_size = 2, stride = 2)) | |
| self.l2 = nn.Sequential( | |
| nn.Conv2d(in_channels=6, out_channels=16, kernel_size=5, stride=1, padding=0), # 10*10 | |
| nn.BatchNorm2d(16), | |
| nn.ReLU(), | |
| nn.MaxPool2d(kernel_size = 2, stride = 2)) | |
| self.classifier = nn.Sequential( | |
| nn.Flatten(), | |
| nn.Linear(in_features=16*5*5, out_features=120), | |
| nn.ReLU(), | |
| nn.Linear(in_features=120, out_features=84), | |
| nn.ReLU(), | |
| nn.Linear(in_features=84, out_features=num_classes), | |
| ) | |
| def forward(self, x): | |
| out = self.l1(x) | |
| out = self.l2(out) | |
| out = self.classifier(out) | |
| return out | |