Skip to content

Instantly share code, notes, and snippets.

@InnovArul
Last active October 25, 2022 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InnovArul/7af1684ccc50fa245954da2cb4a5eca1 to your computer and use it in GitHub Desktop.
Save InnovArul/7af1684ccc50fa245954da2cb4a5eca1 to your computer and use it in GitHub Desktop.
from turtle import forward
import torch
import torch.nn as nn, torch.nn.functional as F
class CNN(nn.Module):
def __init__(self) -> None:
super().__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=8, kernel_size=6, stride=1, padding=2)
self.RL1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(2)
self.conv2 = nn.Conv2d(in_channels=8, out_channels=16, kernel_size=5, stride=1, padding=2)
self.RL2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2)
self.conv3 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=4, stride=1, padding=2)
self.RL3 = nn.ReLU()
self.pool3 = nn.MaxPool2d(2)
self.conv4 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1, padding=2)
self.RL4 = nn.ReLU()
self.pool4 = nn.MaxPool2d(2)
self.flatten = nn.Flatten()
self.fc1 = nn.Linear(64*5*2, 8)
def forward(self, x):
x = self.conv1(x)
x = self.RL1(x)
x = self.pool1(x)
x = self.conv2(x)
x = self.RL2(x)
x = self.pool2(x)
x = self.conv3(x)
x = self.RL3(x)
x = self.pool3(x)
x = self.conv4(x)
x = self.RL4(x)
x = self.pool4(x)
x = self.flatten(x)
x = self.fc1(x)
x = x.log_softmax(dim=1)
x = x.unsqueeze(1)
return x
if __name__ == '__main__':
d = torch.randn(256, 1, 64, 16)
m = CNN()
o = m(d)
print(o.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment