Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bias in VAE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ayan Majumdar
Bias in VAE
Commits
7d4d80e2
Commit
7d4d80e2
authored
6 years ago
by
1Konny
Browse files
Options
Downloads
Patches
Plain Diff
add traverse
parent
fb38b092
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
solver.py
+45
-0
45 additions, 0 deletions
solver.py
with
45 additions
and
0 deletions
solver.py
+
45
−
0
View file @
7d4d80e2
...
...
@@ -163,6 +163,51 @@ class Solver(object):
xlabel
=
'
iteration
'
,
ylabel
=
'
kl divergence
'
,))
def
traverse
(
self
):
import
random
decoder
=
self
.
net
.
decode
encoder
=
self
.
net
.
encode
interpolation
=
torch
.
arange
(
-
6
,
6.1
,
2
)
viz
=
visdom
.
Visdom
(
env
=
self
.
viz_name
+
'
/traverse
'
,
port
=
self
.
viz_port
)
n_dsets
=
self
.
data_loader
.
dataset
.
__len__
()
fixed_idx
=
0
rand_idx
=
random
.
randint
(
1
,
n_dsets
-
1
)
fixed_img
=
self
.
data_loader
.
dataset
.
__getitem__
(
fixed_idx
)
random_img
=
self
.
data_loader
.
dataset
.
__getitem__
(
rand_idx
)
fixed_img
=
Variable
(
cuda
(
fixed_img
,
self
.
use_cuda
),
volatile
=
True
).
unsqueeze
(
0
)
random_img
=
Variable
(
cuda
(
random_img
,
self
.
use_cuda
),
volatile
=
True
).
unsqueeze
(
0
)
zero_z
=
Variable
(
cuda
(
torch
.
zeros
(
1
,
self
.
z_dim
,
1
,
1
),
self
.
use_cuda
),
volatile
=
True
)
random_z
=
Variable
(
cuda
(
torch
.
rand
(
1
,
self
.
z_dim
,
1
,
1
),
self
.
use_cuda
),
volatile
=
True
)
src
=
[
fixed_img
,
random_img
,
zero_z
,
random_z
]
for
i
,
vector
in
enumerate
(
src
):
if
i
<
2
:
z_ori
=
encoder
(
vector
)[:,
:
self
.
z_dim
]
else
:
z_ori
=
vector
samples
=
[]
for
row
in
range
(
self
.
z_dim
):
z
=
z_ori
.
clone
()
for
val
in
interpolation
:
z
[:,
row
]
=
val
sample
=
F
.
sigmoid
(
decoder
(
z
))
samples
.
append
(
sample
)
samples
=
torch
.
cat
(
samples
,
dim
=
0
).
data
.
cpu
()
if
i
==
0
:
title
=
'
traverse representation from fixed image
'
elif
i
==
1
:
title
=
'
traverse representation random image
'
elif
i
==
2
:
title
=
'
traverse zero representation vector
'
elif
i
==
3
:
title
=
'
traverse random gaussian representation vector
'
title
+=
'
(iter:{})
'
.
format
(
self
.
global_iter
)
viz
.
images
(
samples
,
opts
=
dict
(
title
=
title
),
nrow
=
len
(
interpolation
))
def
net_mode
(
self
,
train
):
if
not
isinstance
(
train
,
bool
):
raise
(
'
Only bool type is supported. True or False
'
)
...
...
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