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
b9d1a978
Commit
b9d1a978
authored
6 years ago
by
Olegs NIKISINS
Browse files
Options
Downloads
Patches
Plain Diff
Added an option to return a latent embedding to the ConvAutoencoder class + unit test for this case
parent
8bd13a75
No related branches found
No related tags found
1 merge request
!8
Added an option to return a latent embedding to the ConvAutoencoder class + unit test for this case
Pipeline
#26407
passed
6 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/pytorch/architectures/ConvAutoencoder.py
+18
-1
18 additions, 1 deletion
bob/learn/pytorch/architectures/ConvAutoencoder.py
bob/learn/pytorch/test/test.py
+7
-0
7 additions, 0 deletions
bob/learn/pytorch/test/test.py
with
25 additions
and
1 deletion
bob/learn/pytorch/architectures/ConvAutoencoder.py
+
18
−
1
View file @
b9d1a978
...
@@ -12,9 +12,22 @@ from torch import nn
...
@@ -12,9 +12,22 @@ from torch import nn
# Define the network:
# Define the network:
class
ConvAutoencoder
(
nn
.
Module
):
class
ConvAutoencoder
(
nn
.
Module
):
"""
A class defining a simple convolutional autoencoder.
def
__init__
(
self
):
Attributes
----------
return_latent_embedding : bool
If set to ``True`` forward() method returns a latent
emebedding (encoder output), otherwise a reconstructed
image is returned. Default: ``False``
"""
def
__init__
(
self
,
return_latent_embedding
=
False
):
super
(
ConvAutoencoder
,
self
).
__init__
()
super
(
ConvAutoencoder
,
self
).
__init__
()
self
.
return_latent_embedding
=
return_latent_embedding
self
.
encoder
=
nn
.
Sequential
(
nn
.
Conv2d
(
3
,
16
,
5
,
padding
=
2
),
self
.
encoder
=
nn
.
Sequential
(
nn
.
Conv2d
(
3
,
16
,
5
,
padding
=
2
),
nn
.
ReLU
(
True
),
nn
.
ReLU
(
True
),
nn
.
MaxPool2d
(
2
),
nn
.
MaxPool2d
(
2
),
...
@@ -45,5 +58,9 @@ class ConvAutoencoder(nn.Module):
...
@@ -45,5 +58,9 @@ class ConvAutoencoder(nn.Module):
"""
"""
x
=
self
.
encoder
(
x
)
x
=
self
.
encoder
(
x
)
x
=
self
.
decoder
(
x
)
x
=
self
.
decoder
(
x
)
if
self
.
return_latent_embedding
:
return
self
.
encoder
(
x
)
return
x
return
x
This diff is collapsed.
Click to expand it.
bob/learn/pytorch/test/test.py
+
7
−
0
View file @
b9d1a978
...
@@ -217,3 +217,10 @@ def test_conv_autoencoder():
...
@@ -217,3 +217,10 @@ def test_conv_autoencoder():
assert
batch
.
shape
==
output
.
shape
assert
batch
.
shape
==
output
.
shape
model_embeddings
=
ConvAutoencoder
(
return_latent_embedding
=
True
)
embedding
=
model_embeddings
(
batch
)
assert
list
(
embedding
.
shape
)
==
[
1
,
16
,
5
,
5
]
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