-
Notifications
You must be signed in to change notification settings - Fork 0
/
deep_networks.py
41 lines (36 loc) · 1.46 KB
/
deep_networks.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 12 16:36:05 2019
@author: moulouel
"""
import torch.nn as nn
import NN
class Plain_deep(nn.Module):
def __init__(self,input_shape,output_shape,nb_layers,hidden_shape):
super(Plain_deep,self).__init__()
self.couches=nn.ModuleList([NN.Plain_Net(input_shape,hidden_shape)])
for i in range(1,nb_layers):#le premier a deja été créé
self.couches.append(NN.Plain_Net(hidden_shape,hidden_shape))
self.couches.append(nn.Linear(hidden_shape,output_shape))
def forward(self,x):
for couche in self.couches:
x=couche(x)
y=nn.functional.softmax(x)
return y
class Highway_deep(nn.Module):
def __init__(self,input_shape,output_shape,nb_layers,hidden_shape):
super(Highway_deep,self).__init__()
self.first=nn.Linear(input_shape,hidden_shape)
nn.init.xavier_normal(self.first.weight)
self.active_first=nn.ReLU()
self.couches=nn.ModuleList([NN.Highway_Net(hidden_shape,hidden_shape)])
for i in range(1,nb_layers):#le premier a deja été créé
self.couches.append(NN.Highway_Net(hidden_shape,hidden_shape))
self.couches.append(nn.Linear(hidden_shape,output_shape))
def forward(self,x):
x=self.active_first(self.first(x))
for couche in self.couches:
x=couche(x)
y=nn.functional.softmax(x)
return y