-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
25 lines (22 loc) · 821 Bytes
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
from torchsummary import summary
from glob import glob
from tqdm.notebook import tqdm
class black_box_model(nn.Module):
def __init__(self, num_classes, pretrained=True):
super().__init__()
# Use a pretrained mode
self.resnet34 = models.resnet34(True)
self.features = nn.Sequential(*list(self.resnet34.children())[:-1])
# Replace last layer
self.classifier = nn.Sequential(nn.Flatten(),
nn.Linear(self.resnet34.fc.in_features, num_classes))
def forward(self, x):
x = self.features(x)
y = self.classifier(x)
return y
def summary(self, input_size):
return summary(self, input_size)