Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mira Arabi Haddad
DL Mini Projects Group M
Commits
603051ba
Commit
603051ba
authored
Dec 17, 2021
by
Mirza Cutuk
Browse files
GROUPWORK_added comments
parent
f5b83afd
Changes
1
Hide whitespace changes
Inline
Side-by-side
p1/net.py
View file @
603051ba
...
...
@@ -10,7 +10,7 @@ from torch.nn.modules.dropout import Dropout
from
torch.nn.modules.pooling
import
MaxPool2d
# import matplotlib.pyplot as plt
## Basic M
odel
## Basic M
LP Network with 2 hidden layers
class
NN
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -30,6 +30,7 @@ class NN(nn.Module):
x
=
self
.
classifier
(
x
)
return
x
## VGG Convolutional Network with 2 hidden layers
class
CNN_VGG
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -67,6 +68,7 @@ class CNN_VGG(nn.Module):
#Problem 1 Part 2:
## 2 Networks: Classifier + Comparer (Weight Sharing)
## MLP Network with 2 hidden layers for classification only
class
NN_Classification
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -86,6 +88,7 @@ class NN_Classification(nn.Module):
x2
=
self
.
classifier
(
x2
.
view
(
-
1
,
196
))
return
torch
.
cat
((
x1
,
x2
),
1
)
## Convolutional Network with 2 hidden layers for classification only
class
CNN_Classification
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -126,7 +129,7 @@ class CNN_Classification(nn.Module):
x2
=
self
.
classifier
(
x2
)
return
torch
.
cat
((
x1
,
x2
),
1
)
## MLP Network with 2 hidden layers for comparison only
class
MLP_Comparer
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -145,11 +148,10 @@ class MLP_Comparer(nn.Module):
)
def
forward
(
self
,
x
):
# x = self.classifier(torch.cat((x1, x2), 1))
x
=
self
.
classifier
(
x
)
# return torch.cat((x1, x2), 1)
return
x
## MLP Siamese Network with classification and comparison combined
class
NN_WS
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -160,6 +162,7 @@ class NN_WS(nn.Module):
x
=
self
.
comparer
(
self
.
classifier
(
x
[:,
0
],
x
[:,
1
]))
return
x
## Convolutional Siamese Network with classification and comparison combined
class
CNN_WS
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -167,12 +170,10 @@ class CNN_WS(nn.Module):
self
.
comparer
=
MLP_Comparer
(
nb_hidden
)
def
forward
(
self
,
x
):
# x = self.classifier(torch.cat((x1, x2), 1))
x
=
self
.
comparer
(
self
.
classifier
(
x
[:,
0
],
x
[:,
1
]))
# return torch.cat((x1, x2), 1)
return
x
##
NN WS+AL
##
MLP Siamese Network with classification and comparison combined + Auxiliary Loss
class
NN_WS_AL
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
@@ -187,7 +188,7 @@ class NN_WS_AL(nn.Module):
# keep both, for Auxiliary Loss
return
out
,
res
## C
NN WS + AL
## C
onvolutional Siamese Network with classification and comparison combined + Auxiliary Loss
class
CNN_WS_AL
(
nn
.
Module
):
def
__init__
(
self
,
nb_hidden
):
super
().
__init__
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment