Sam____

CNN Model

Oct 17th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import torch.nn.functional as F
  2. import torch
  3. from torch import nn
  4.  
  5.  
  6. device = ("cuda" if torch.cuda.is_available() else "cpu")
  7. # print(device)
  8. class CNN_model(nn.Module):
  9.     def __init__(self):
  10.         super(CNN_model, self).__init__()
  11.  
  12.         self.convolutional_layer = nn.Sequential(
  13.             nn.Conv3d(in_channels=8, out_channels=48, kernel_size=(8, 8, 8), dilation=(3, 3, 3), stride=(2, 2, 2),
  14.                       padding=(0, 0, 0)),
  15.             nn.ReLU(),
  16.             nn.Conv3d(in_channels=48, out_channels=86, kernel_size=(8, 8, 8), dilation=(2, 2, 2), stride=(2, 2, 2),
  17.                       padding=(0, 0, 0)),
  18.             nn.ReLU(),
  19.             nn.Conv3d(in_channels=86, out_channels=120, kernel_size=(3, 6, 3), dilation=(1, 1, 1), stride=(1, 1, 1),
  20.                       padding=(0, 0, 0)),
  21.             nn.ReLU()
  22.         )
  23.  
  24.         self.linear_layer = nn.Sequential(
  25.             nn.Linear(in_features=120, out_features=80),
  26.             nn.BatchNorm1d(80),
  27.             nn.Dropout(0.5),
  28.             nn.ReLU(),
  29.             nn.Linear(in_features=80, out_features=24),
  30.             nn.Dropout(0.2),
  31.             nn.ReLU(),
  32.             nn.Linear(in_features=24, out_features=1)
  33.         )
  34.  
  35.     def forward(self, x):
  36.         x = self.convolutional_layer(x)
  37.         x = torch.flatten(x, 1)
  38.         x = self.linear_layer(x)
  39.  
  40.         x = F.softmax(x, dim=1)
  41.         return
Advertisement
Add Comment
Please, Sign In to add comment