-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel.py
85 lines (80 loc) · 2.78 KB
/
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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import torch
import torch.nn as nn
from torch.nn.init import kaiming_normal_
class SolarClassifier(nn.Module):
def __init__(self):
super().__init__()
self.max_pool = nn.MaxPool2d(kernel_size=2,stride=2)
self.layer1 = nn.Sequential(
nn.Conv2d(1,64,kernel_size=3,padding=1),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True)
)
self.layer2 = nn.Sequential(
nn.Conv2d(64,64,kernel_size=3,padding=1),
nn.BatchNorm2d(64),
nn.ReLU(inplace=True)
)
self.layer3 = nn.Sequential(
nn.Conv2d(64,128,kernel_size=3,padding=1),
nn.BatchNorm2d(128),
nn.ReLU(inplace=True)
)
self.layer4 = nn.Sequential(
nn.Conv2d(128,128,kernel_size=3,padding=1),
nn.BatchNorm2d(128),
nn.ReLU(inplace=True)
)
self.layer5 = nn.Sequential(
nn.Conv2d(128,256,kernel_size=3,padding=1),
nn.BatchNorm2d(256),
nn.ReLU(inplace=True)
)
self.layer6 = nn.Sequential(
nn.Conv2d(256,256,kernel_size=3,padding=1),
nn.BatchNorm2d(256),
nn.ReLU(inplace=True)
)
self.layer7 = nn.Sequential(
nn.Conv2d(256,512,kernel_size=3,padding=1),
nn.BatchNorm2d(512),
nn.ReLU(inplace=True)
)
self.layer8 = nn.Sequential(
nn.Conv2d(512,512,kernel_size=3,padding=1),
nn.BatchNorm2d(512),
nn.ReLU(inplace=True)
)
self.classifier = nn.Sequential(
nn.Linear(512*8*8,4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(4096,4096),
nn.ReLU(inplace=True),
nn.Dropout(),
nn.Linear(4096,5)
)
for m in self.modules():
if not Solar_Classifier:
kaiming_normal_(m.weight,nonlinearity="relu")
def forward(self,x):
out = self.layer1(x)
out = self.layer2(out)
out = self.max_pool(out)
out = self.layer3(out)
out = self.layer4(out)
out = self.max_pool(out)
out = self.layer5(out)
out = self.layer6(out)
out = self.max_pool(out)
out = self.layer7(out)
out = self.layer8(out)
out = self.max_pool(out)
out = self.layer8(out)
out = self.layer8(out)
out = self.max_pool(out)
out = out.view(out.size(0),-1)
out = self.classifier(out)
return out
def graph(self):
return nn.Sequential(self.layer1,self.layer2,self.maxPool,self.layer3,self.layer4,self.maxPool,self.layer5,self.layer6,self.maxPool,self.layer7,self.layer8, self.maxPool,self.layer8,self.layer8,self.maxPool,self.classifier)