-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmodel.py
More file actions
20 lines (17 loc) · 701 Bytes
/
model.py
File metadata and controls
20 lines (17 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import torch
import torch.nn as nn
from torchvision import models
class MRNet(nn.Module):
def __init__(self):
super().__init__()
self.pretrained_model = models.alexnet(pretrained=True)
self.pooling_layer = nn.AdaptiveAvgPool2d(1)
self.classifer = nn.Linear(256, 2)
def forward(self, x):
x = torch.squeeze(x, dim=0)
features = self.pretrained_model.features(x)
pooled_features = self.pooling_layer(features)
pooled_features = pooled_features.view(pooled_features.size(0), -1)
flattened_features = torch.max(pooled_features, 0, keepdim=True)[0]
output = self.classifer(flattened_features)
return output