1# !pip install transformers
2import torch.nn as nn
3import torch.nn.functional as F
4from huggingface_hub import PyTorchModelHubMixin
5
6class Net(nn.Module,PyTorchModelHubMixin):
7 def __init__(self):
8 super().__init__()
9 self.conv1 = nn.Conv2d(3, 6, 5)
10 self.pool = nn.MaxPool2d(2, 2)
11 self.conv2 = nn.Conv2d(6, 16, 5)
12 self.fc1 = nn.Linear(16 * 5 * 5, 120)
13 self.fc2 = nn.Linear(120, 84)
14 self.fc3 = nn.Linear(84, 10)
15
16 def forward(self, x):
17 x = self.pool(F.relu(self.conv1(x)))
18 x = self.pool(F.relu(self.conv2(x)))
19 x = torch.flatten(x, 1) # flatten all dimensions except batch
20 x = F.relu(self.fc1(x))
21 x = F.relu(self.fc2(x))
22 x = self.fc3(x)
23 return x
24
25net = Net.from_pretrained('Adapting/cifar10-image-classification')
26
example codes for testing the model:
link