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
1117b138
Commit
1117b138
authored
6 years ago
by
Tony Metger
Browse files
Options
Downloads
Patches
Plain Diff
Add extra options for visualization and fix bug for viz_on False
parent
5d47d435
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+4
-0
4 additions, 0 deletions
main.py
solver.py
+26
-11
26 additions, 11 deletions
solver.py
with
30 additions
and
11 deletions
main.py
+
4
−
0
View file @
1117b138
...
...
@@ -57,6 +57,10 @@ if __name__ == "__main__":
parser
.
add_argument
(
'
--save_output
'
,
default
=
True
,
type
=
str2bool
,
help
=
'
save traverse images and gif
'
)
parser
.
add_argument
(
'
--output_dir
'
,
default
=
'
outputs
'
,
type
=
str
,
help
=
'
output directory
'
)
parser
.
add_argument
(
'
--gather_step
'
,
default
=
1000
,
type
=
int
,
help
=
'
numer of iterations after which data is gathered for visdom
'
)
parser
.
add_argument
(
'
--display_step
'
,
default
=
10000
,
type
=
int
,
help
=
'
number of iterations after which loss data is printed and visdom is updated
'
)
parser
.
add_argument
(
'
--save_step
'
,
default
=
10000
,
type
=
int
,
help
=
'
number of iterations after which a checkpoint is saved
'
)
parser
.
add_argument
(
'
--ckpt_dir
'
,
default
=
'
checkpoints
'
,
type
=
str
,
help
=
'
checkpoint directory
'
)
parser
.
add_argument
(
'
--ckpt_name
'
,
default
=
'
last
'
,
type
=
str
,
help
=
'
load previous checkpoint. insert checkpoint filename
'
)
...
...
This diff is collapsed.
Click to expand it.
solver.py
+
26
−
11
View file @
1117b138
...
...
@@ -130,6 +130,10 @@ class Solver(object):
if
not
self
.
output_dir
.
exists
():
self
.
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
self
.
gather_step
=
args
.
gather_step
self
.
display_step
=
args
.
display_step
self
.
save_step
=
args
.
save_step
self
.
dset_dir
=
args
.
dset_dir
self
.
dataset
=
args
.
dataset
self
.
batch_size
=
args
.
batch_size
...
...
@@ -164,19 +168,20 @@ class Solver(object):
beta_vae_loss
.
backward
()
self
.
optim
.
step
()
if
self
.
global_iter
%
1000
==
0
:
if
self
.
viz_on
and
self
.
global_iter
%
self
.
gather_step
==
0
:
self
.
gather
.
insert
(
iter
=
self
.
global_iter
,
mu
=
mu
.
mean
(
0
).
data
,
var
=
logvar
.
exp
().
mean
(
0
).
data
,
recon_loss
=
recon_loss
.
data
,
total_kld
=
total_kld
.
data
,
dim_wise_kld
=
dim_wise_kld
.
data
,
mean_kld
=
mean_kld
.
data
)
if
self
.
global_iter
%
10000
==
0
:
self
.
gather
.
insert
(
images
=
x
.
data
)
self
.
gather
.
insert
(
images
=
F
.
sigmoid
(
x_recon
).
data
)
self
.
viz_reconstruction
()
self
.
viz_lines
()
if
self
.
global_iter
%
self
.
display_step
==
0
:
if
self
.
viz_on
:
self
.
gather
.
insert
(
images
=
x
.
data
)
self
.
gather
.
insert
(
images
=
F
.
sigmoid
(
x_recon
).
data
)
self
.
viz_reconstruction
()
self
.
viz_lines
()
self
.
gather
.
flush
()
self
.
save_checkpoint
(
'
last
'
)
pbar
.
write
(
'
[{}] recon_loss:{:.3f} total_kld:{:.3f} mean_kld:{:.3f}
'
.
format
(
self
.
global_iter
,
recon_loss
.
data
[
0
],
total_kld
.
data
[
0
],
mean_kld
.
data
[
0
]))
...
...
@@ -188,6 +193,10 @@ class Solver(object):
if
self
.
objective
==
'
advanced
'
:
pbar
.
write
(
'
C:{:.3f}
'
.
format
(
C
.
data
[
0
]))
if
self
.
global_iter
%
self
.
save_step
==
0
:
self
.
save_checkpoint
(
'
last
'
)
pbar
.
write
(
'
Saved checkpoint
'
)
if
self
.
global_iter
%
20000
==
0
:
self
.
viz_traverse
()
...
...
@@ -421,10 +430,16 @@ class Solver(object):
def
save_checkpoint
(
self
,
filename
,
silent
=
True
):
model_states
=
{
'
net
'
:
self
.
net
.
state_dict
(),}
optim_states
=
{
'
optim
'
:
self
.
optim
.
state_dict
(),}
win_states
=
{
'
recon
'
:
self
.
win_recon
,
'
kld
'
:
self
.
win_kld
,
'
mu
'
:
self
.
win_mu
,
'
var
'
:
self
.
win_var
,}
if
self
.
viz_on
:
win_states
=
{
'
recon
'
:
self
.
win_recon
,
'
kld
'
:
self
.
win_kld
,
'
mu
'
:
self
.
win_mu
,
'
var
'
:
self
.
win_var
,}
else
:
win_states
=
{
'
recon
'
:
None
,
'
kld
'
:
None
,
'
mu
'
:
None
,
'
var
'
:
None
,}
states
=
{
'
iter
'
:
self
.
global_iter
,
'
win_states
'
:
win_states
,
'
model_states
'
:
model_states
,
...
...
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