Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.pytorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.pytorch
Commits
2649d27e
Commit
2649d27e
authored
6 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Patches
Plain Diff
[tests] removed MLP tests, moved Autoencoder architecture test
parent
2f0a5f43
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!27
cleaning
Pipeline
#28459
passed
6 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/pytorch/test/test.py
+10
-49
10 additions, 49 deletions
bob/learn/pytorch/test/test.py
with
10 additions
and
49 deletions
bob/learn/pytorch/test/test.py
+
10
−
49
View file @
2649d27e
...
@@ -43,8 +43,6 @@ def test_architectures():
...
@@ -43,8 +43,6 @@ def test_architectures():
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
256
])
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
256
])
# LightCNN29
# LightCNN29
a
=
numpy
.
random
.
rand
(
1
,
1
,
128
,
128
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
a
)
from
..architectures
import
LightCNN29
from
..architectures
import
LightCNN29
net
=
LightCNN29
()
net
=
LightCNN29
()
output
,
emdedding
=
net
.
forward
(
t
)
output
,
emdedding
=
net
.
forward
(
t
)
...
@@ -52,8 +50,6 @@ def test_architectures():
...
@@ -52,8 +50,6 @@ def test_architectures():
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
256
])
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
256
])
# LightCNN29v2
# LightCNN29v2
a
=
numpy
.
random
.
rand
(
1
,
1
,
128
,
128
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
a
)
from
..architectures
import
LightCNN29v2
from
..architectures
import
LightCNN29v2
net
=
LightCNN29v2
()
net
=
LightCNN29v2
()
output
,
emdedding
=
net
.
forward
(
t
)
output
,
emdedding
=
net
.
forward
(
t
)
...
@@ -69,8 +65,6 @@ def test_architectures():
...
@@ -69,8 +65,6 @@ def test_architectures():
assert
output
.
shape
==
torch
.
Size
([
1
,
1
])
assert
output
.
shape
==
torch
.
Size
([
1
,
1
])
# MCCNNv2
# MCCNNv2
a
=
numpy
.
random
.
rand
(
1
,
4
,
128
,
128
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
a
)
from
..architectures
import
MCCNNv2
from
..architectures
import
MCCNNv2
net
=
MCCNNv2
(
num_channels
=
4
)
net
=
MCCNNv2
(
num_channels
=
4
)
output
=
net
.
forward
(
t
)
output
=
net
.
forward
(
t
)
...
@@ -117,7 +111,6 @@ def test_architectures():
...
@@ -117,7 +111,6 @@ def test_architectures():
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
# Conditional GAN
# Conditional GAN
d
=
numpy
.
random
.
rand
(
1
,
3
,
64
,
64
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
d
)
t
=
torch
.
from_numpy
(
d
)
cfm
=
numpy
.
zeros
((
1
,
13
,
64
,
64
),
dtype
=
"
float32
"
)
cfm
=
numpy
.
zeros
((
1
,
13
,
64
,
64
),
dtype
=
"
float32
"
)
cfm
[:,
0
,
:,
:]
=
1
cfm
[:,
0
,
:,
:]
=
1
...
@@ -127,7 +120,6 @@ def test_architectures():
...
@@ -127,7 +120,6 @@ def test_architectures():
output
=
discriminator
.
forward
(
t
,
cfmt
)
output
=
discriminator
.
forward
(
t
,
cfmt
)
assert
output
.
shape
==
torch
.
Size
([
1
])
assert
output
.
shape
==
torch
.
Size
([
1
])
g
=
numpy
.
random
.
rand
(
1
,
100
,
1
,
1
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
g
)
t
=
torch
.
from_numpy
(
g
)
oh
=
numpy
.
zeros
((
1
,
13
,
1
,
1
),
dtype
=
"
float32
"
)
oh
=
numpy
.
zeros
((
1
,
13
,
1
,
1
),
dtype
=
"
float32
"
)
oh
[
0
]
=
1
oh
[
0
]
=
1
...
@@ -136,6 +128,16 @@ def test_architectures():
...
@@ -136,6 +128,16 @@ def test_architectures():
discriminator
=
ConditionalGAN_generator
(
100
,
13
)
discriminator
=
ConditionalGAN_generator
(
100
,
13
)
output
=
discriminator
.
forward
(
t
,
oht
)
output
=
discriminator
.
forward
(
t
,
oht
)
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
assert
output
.
shape
==
torch
.
Size
([
1
,
3
,
64
,
64
])
# Convolutional Autoencoder
from
bob.learn.pytorch.architectures
import
ConvAutoencoder
batch
=
torch
.
randn
(
1
,
3
,
64
,
64
)
model
=
ConvAutoencoder
()
output
=
model
(
batch
)
assert
batch
.
shape
==
output
.
shape
model_embeddings
=
ConvAutoencoder
(
return_latent_embedding
=
True
)
embedding
=
model_embeddings
(
batch
)
assert
list
(
embedding
.
shape
)
==
[
1
,
16
,
5
,
5
]
def
test_transforms
():
def
test_transforms
():
...
@@ -186,15 +188,11 @@ def test_map_labels():
...
@@ -186,15 +188,11 @@ def test_map_labels():
assert
'
0
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
0
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
1
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
1
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
2
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
2
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
#new_labels = sorted(new_labels)
#assert new_labels == ['0', '1', '2']
new_labels
=
map_labels
(
labels
,
start_index
=
5
)
new_labels
=
map_labels
(
labels
,
start_index
=
5
)
#new_labels = sorted(new_labels)
assert
'
5
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
5
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
6
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
6
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
7
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
assert
'
7
'
in
new_labels
,
"
new_labels = {}
"
.
format
(
new_labels
)
#assert new_labels == ['5', '6', '7']
from
torch.utils.data
import
Dataset
from
torch.utils.data
import
Dataset
...
@@ -390,22 +388,6 @@ def test_ConditionalGANTrainer():
...
@@ -390,22 +388,6 @@ def test_ConditionalGANTrainer():
os
.
remove
(
'
netG_epoch_0.pth
'
)
os
.
remove
(
'
netG_epoch_0.pth
'
)
def
test_conv_autoencoder
():
"""
Test the ConvAutoencoder class.
"""
from
bob.learn.pytorch.architectures
import
ConvAutoencoder
batch
=
torch
.
randn
(
1
,
3
,
64
,
64
)
model
=
ConvAutoencoder
()
output
=
model
(
batch
)
assert
batch
.
shape
==
output
.
shape
model_embeddings
=
ConvAutoencoder
(
return_latent_embedding
=
True
)
embedding
=
model_embeddings
(
batch
)
assert
list
(
embedding
.
shape
)
==
[
1
,
16
,
5
,
5
]
def
test_extractors
():
def
test_extractors
():
# lightCNN9
# lightCNN9
...
@@ -455,24 +437,3 @@ def test_extractors():
...
@@ -455,24 +437,3 @@ def test_extractors():
data
=
numpy
.
random
.
rand
(
3
,
224
,
224
).
astype
(
"
uint8
"
)
data
=
numpy
.
random
.
rand
(
3
,
224
,
224
).
astype
(
"
uint8
"
)
output
=
extractor
(
data
)
output
=
extractor
(
data
)
assert
output
.
shape
[
0
]
==
1
assert
output
.
shape
[
0
]
==
1
def
test_two_layer_mlp
():
"""
Test the TwoLayerMLP class.
"""
from
bob.learn.pytorch.architectures
import
TwoLayerMLP
batch
=
torch
.
randn
(
10
,
1
,
100
)
model
=
TwoLayerMLP
(
in_features
=
100
,
n_hidden_relu
=
10
,
apply_sigmoid
=
True
)
output
=
model
(
batch
)
assert
list
(
output
.
shape
)
==
[
10
,
1
]
model
.
apply_sigmoid
=
False
output
=
model
(
batch
)
assert
list
(
output
.
shape
)
==
[
10
,
1
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment