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
3352906d
There was a problem fetching the pipeline summary.
Commit
3352906d
authored
6 years ago
by
Guillaume HEUSCH
Browse files
Options
Downloads
Plain Diff
Merge branch '3-add-unit-tests' into 'master'
Resolve "Add unit tests" Closes
#3
See merge request
!3
parents
6294000c
b67e80f5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!3
Resolve "Add unit tests"
Pipeline
#
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+0
-1
0 additions, 1 deletion
.gitignore
bob/learn/pytorch/test/__init__.py
+3
-0
3 additions, 0 deletions
bob/learn/pytorch/test/__init__.py
bob/learn/pytorch/test/test.py
+102
-0
102 additions, 0 deletions
bob/learn/pytorch/test/test.py
with
105 additions
and
1 deletion
.gitignore
+
0
−
1
View file @
3352906d
...
@@ -10,7 +10,6 @@ parts
...
@@ -10,7 +10,6 @@ parts
src
src
develop-eggs
develop-eggs
sphinx
sphinx
test*
submit*
submit*
log*
log*
results*
results*
...
...
This diff is collapsed.
Click to expand it.
bob/learn/pytorch/test/__init__.py
0 → 100644
+
3
−
0
View file @
3352906d
# gets sphinx autodoc done right - don't remove it
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
'
_
'
)]
This diff is collapsed.
Click to expand it.
bob/learn/pytorch/test/test.py
0 → 100644
+
102
−
0
View file @
3352906d
#!/usr/bin/env python
# encoding: utf-8
"""
Unit tests
"""
import
numpy
import
torch
def
test_architectures
():
a
=
numpy
.
random
.
rand
(
1
,
3
,
128
,
128
).
astype
(
"
float32
"
)
t
=
torch
.
from_numpy
(
a
)
number_of_classes
=
20
output_dimension
=
number_of_classes
# CASIANet
from
..architectures
import
CASIANet
net
=
CASIANet
(
number_of_classes
)
embedding_dimension
=
320
output
,
emdedding
=
net
.
forward
(
t
)
assert
output
.
shape
==
torch
.
Size
([
1
,
20
])
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
320
])
# CNN8
from
..architectures
import
CNN8
net
=
CNN8
(
number_of_classes
)
embedding_dimension
=
512
output
,
emdedding
=
net
.
forward
(
t
)
assert
output
.
shape
==
torch
.
Size
([
1
,
20
])
assert
emdedding
.
shape
==
torch
.
Size
([
1
,
512
])
def
test_transforms
():
image
=
numpy
.
random
.
rand
(
3
,
128
,
128
).
astype
(
"
uint8
"
)
from
..datasets
import
RollChannels
sample
=
{
'
image
'
:
image
}
rc
=
RollChannels
()
rc
(
sample
)
assert
sample
[
'
image
'
].
shape
==
(
128
,
128
,
3
)
from
..datasets
import
ToTensor
tt
=
ToTensor
()
tt
(
sample
)
assert
isinstance
(
sample
[
'
image
'
],
torch
.
Tensor
)
from
..datasets
import
Normalize
image_copy
=
torch
.
Tensor
(
sample
[
'
image
'
])
norm
=
Normalize
((
0.5
,
0.5
,
0.5
),
(
0.5
,
0.5
,
0.5
))
norm
(
sample
)
for
c
in
range
(
3
):
for
h
in
range
(
sample
[
'
image
'
].
shape
[
0
]):
for
w
in
range
(
sample
[
'
image
'
].
shape
[
1
]):
assert
(
abs
(
sample
[
'
image
'
][
c
,
h
,
w
])
-
abs
((
image_copy
[
c
,
h
,
w
]
-
0.5
)
/
0.5
))
<
1e-10
def
test_map_labels
():
labels
=
[
'
1
'
,
'
4
'
,
'
7
'
]
from
..datasets
import
map_labels
new_labels
=
map_labels
(
labels
)
new_labels
=
sorted
(
new_labels
)
assert
new_labels
==
[
'
0
'
,
'
1
'
,
'
2
'
]
new_labels
=
map_labels
(
labels
,
start_index
=
5
)
new_labels
=
sorted
(
new_labels
)
assert
new_labels
==
[
'
5
'
,
'
6
'
,
'
7
'
]
from
torch.utils.data
import
Dataset
class
DummyDataSet
(
Dataset
):
def
__init__
(
self
):
pass
def
__len__
(
self
):
return
100
def
__getitem__
(
self
,
idx
):
data
=
numpy
.
random
.
rand
(
3
,
128
,
128
).
astype
(
"
float32
"
)
label
=
numpy
.
random
.
randint
(
20
)
sample
=
{
'
image
'
:
torch
.
from_numpy
(
data
),
'
label
'
:
label
}
return
sample
def
test_trainer
():
from
..architectures
import
CNN8
net
=
CNN8
(
20
)
dataloader
=
torch
.
utils
.
data
.
DataLoader
(
DummyDataSet
(),
batch_size
=
32
,
shuffle
=
True
)
from
..trainers
import
CNNTrainer
trainer
=
CNNTrainer
(
net
,
verbosity_level
=
3
)
trainer
.
train
(
dataloader
,
n_epochs
=
1
,
output_dir
=
'
.
'
)
import
os
assert
os
.
path
.
isfile
(
'
model_1_0.pth
'
)
os
.
remove
(
'
model_1_0.pth
'
)
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