-
Notifications
You must be signed in to change notification settings - Fork 94
/
DensenetModels.py
63 lines (36 loc) · 1.72 KB
/
DensenetModels.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import numpy as np
import torch
import torch.nn as nn
import torch.backends.cudnn as cudnn
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
from sklearn.metrics import roc_auc_score
import torchvision
class DenseNet121(nn.Module):
def __init__(self, classCount, isTrained):
super(DenseNet121, self).__init__()
self.densenet121 = torchvision.models.densenet121(pretrained=isTrained)
kernelCount = self.densenet121.classifier.in_features
self.densenet121.classifier = nn.Sequential(nn.Linear(kernelCount, classCount), nn.Sigmoid())
def forward(self, x):
x = self.densenet121(x)
return x
class DenseNet169(nn.Module):
def __init__(self, classCount, isTrained):
super(DenseNet169, self).__init__()
self.densenet169 = torchvision.models.densenet169(pretrained=isTrained)
kernelCount = self.densenet169.classifier.in_features
self.densenet169.classifier = nn.Sequential(nn.Linear(kernelCount, classCount), nn.Sigmoid())
def forward (self, x):
x = self.densenet169(x)
return x
class DenseNet201(nn.Module):
def __init__ (self, classCount, isTrained):
super(DenseNet201, self).__init__()
self.densenet201 = torchvision.models.densenet201(pretrained=isTrained)
kernelCount = self.densenet201.classifier.in_features
self.densenet201.classifier = nn.Sequential(nn.Linear(kernelCount, classCount), nn.Sigmoid())
def forward (self, x):
x = self.densenet201(x)
return x