This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNeural_Network_Class.py
70 lines (58 loc) · 2.25 KB
/
Neural_Network_Class.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
import torch
import torch.nn as nn
from torch.autograd import Variable
class conv_deconv(nn.Module):
def __init__(self):
super(conv_deconv,self).__init__()
#Convolution 1
self.conv1=nn.Conv2d(in_channels=3,out_channels=16, kernel_size=4,stride=1, padding=0)
nn.init.xavier_uniform(self.conv1.weight) #Xaviers Initialisation
self.swish1= nn.ReLU()
#Max Pool 1
self.maxpool1= nn.MaxPool2d(kernel_size=2,return_indices=True)
#Convolution 2
self.conv2 = nn.Conv2d(in_channels=16, out_channels=32, kernel_size=5)
nn.init.xavier_uniform(self.conv2.weight)
self.swish2 = nn.ReLU()
#Max Pool 2
self.maxpool2 = nn.MaxPool2d(kernel_size=2,return_indices=True)
#Convolution 3
self.conv3 = nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3)
nn.init.xavier_uniform(self.conv3.weight)
self.swish3 = nn.ReLU()
#De Convolution 1
self.deconv1=nn.ConvTranspose2d(in_channels=64,out_channels=32,kernel_size=3)
nn.init.xavier_uniform(self.deconv1.weight)
self.swish4=nn.ReLU()
#Max UnPool 1
self.maxunpool1=nn.MaxUnpool2d(kernel_size=2)
#De Convolution 2
self.deconv2=nn.ConvTranspose2d(in_channels=32,out_channels=16,kernel_size=5)
nn.init.xavier_uniform(self.deconv2.weight)
self.swish5=nn.ReLU()
#Max UnPool 2
self.maxunpool2=nn.MaxUnpool2d(kernel_size=2)
#DeConvolution 3
self.deconv3=nn.ConvTranspose2d(in_channels=16,out_channels=3,kernel_size=4)
nn.init.xavier_uniform(self.deconv3.weight)
self.swish6=nn.ReLU()
def forward(self,x):
out=self.conv1(x)
out=self.swish1(out)
size1 = out.size()
out,indices1=self.maxpool1(out)
out=self.conv2(out)
out=self.swish2(out)
size2 = out.size()
out,indices2=self.maxpool2(out)
out=self.conv3(out)
out=self.swish3(out)
out=self.deconv1(out)
out=self.swish4(out)
out=self.maxunpool1(out,indices2,size2)
out=self.deconv2(out)
out=self.swish5(out)
out=self.maxunpool2(out,indices1,size1)
out=self.deconv3(out)
out=self.swish6(out)
return(out)