-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayers.py
More file actions
92 lines (69 loc) · 2.77 KB
/
Copy pathlayers.py
File metadata and controls
92 lines (69 loc) · 2.77 KB
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
86
87
88
89
90
91
92
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
class Convolutional_Block(nn.Module):
def __init__(self, in_channels, out_channels):
super(Convolutional_Block, self).__init__()
#on ne fait pas de rétro action pour l' instant!
self.conv1 = nn.Conv2d(in_channels, out_channels,
kernel_size = (3,3), padding = "same")
self.batch_norm1 = nn.BatchNorm2d(out_channels)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(out_channels, out_channels,
kernel_size = (3,3), padding = "same")
self.batch_norm2 = nn.BatchNorm2d(out_channels)
self.relu2 = nn.ReLU()
def forward(self,x):
conv_1 = self.conv1(x)
batch_norm_1 = self.batch_norm1(conv_1)
relu_1 = self.relu1(batch_norm_1)
conv_2 = self.conv2(relu_1)
batch_norm_2 = self.batch_norm2(conv_2)
output = self.relu2(batch_norm_2)
return output
class DeConvolutional_Block(nn.Module):
def __init__(self, in_channels, out_channels):
super(DeConvolutional_Block, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels,
kernel_size = (3,3), padding = "same")
self.batch_norm1 = nn.BatchNorm2d(out_channels)
self.relu1 = nn.ReLU()
self.conv2 = nn.Conv2d(out_channels, out_channels,
kernel_size = (3,3), padding = "same")
self.batch_norm2 = nn.BatchNorm2d(out_channels)
self.relu2 = nn.ReLU()
def forward(self,x):
conv_1 = self.conv1(x)
batch_norm_1 = self.batch_norm1(conv_1)
relu_1 = self.relu1(batch_norm_1)
conv_2 = self.conv2(relu_1)
batch_norm_2 = self.batch_norm2(conv_2)
output = self.relu2(batch_norm_2)
return output
class Conv(nn.Module):
def __init__(self, in_cn, out_cn):
super().__init__()
self.conv = nn.Conv2d(in_cn, out_cn, kernel_size=3, padding=1)
self.bn = nn.BatchNorm2d(out_cn)
self.relu = nn.ReLU()
self.dropout = nn.Dropout2d(p=0.2)
def forward(self, x):
x = self.conv(x)
x = self.bn(x)
x = self.relu(x)
x = self.dropout(x)
return x
class DeConv(nn.Module):
def __init__(self, in_cn, out_cn):
super().__init__()
self.deconv = nn.ConvTranspose2d(in_cn, out_cn, kernel_size=2, stride=2)
self.bn = nn.BatchNorm2d(out_cn)
self.relu = nn.ReLU()
self.dropout = nn.Dropout2d(p=0.2)
def forward(self, x):
x = self.deconv(x)
x = self.bn(x)
x = self.relu(x)
x = self.dropout(x)
return x