Traktor/source/NN/model.py

28 lines
1.0 KiB
Python
Raw Normal View History

import torch.nn as nn
2024-05-25 18:41:25 +02:00
import torch
import torch.nn.functional as F
class Conv_Neural_Network_Model(nn.Module):
def __init__(self, num_classes=5,hidden_layer1 = 512,hidden_layer2 = 256):
super(Conv_Neural_Network_Model, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, stride=1, padding=1)
self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0)
self.conv2 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1, padding=1)
2024-05-27 04:27:46 +02:00
self.fc1 = nn.Linear(64*25*25,hidden_layer1)
self.fc2 = nn.Linear(hidden_layer1,hidden_layer2)
self.out = nn.Linear(hidden_layer2,num_classes)
def forward(self, x):
x = self.pool1(F.relu(self.conv1(x)))
2024-05-27 04:27:46 +02:00
x = self.pool1(F.relu(self.conv2(x)))
x = x.view(-1, 64*25*25) #<----flattening the image
x = self.fc1(x)
x = torch.relu(x)
x = self.fc2(x)
x = torch.relu(x)
x = self.out(x)
2024-05-25 18:41:25 +02:00
return F.log_softmax(x, dim=-1)