Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
55a34ae5
Commit
55a34ae5
authored
Mar 19, 2016
by
daviddao
Browse files
fixing issues #23 and #25
parent
38079f01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
12 deletions
+6
-12
autoencoder/VariationalAutoencoderRunner.py
autoencoder/VariationalAutoencoderRunner.py
+4
-5
autoencoder/autoencoder_models/VariationalAutoencoder.py
autoencoder/autoencoder_models/VariationalAutoencoder.py
+2
-7
No files found.
autoencoder/VariationalAutoencoderRunner.py
View file @
55a34ae5
...
...
@@ -9,8 +9,8 @@ from autoencoder.autoencoder_models.VariationalAutoencoder import VariationalAut
mnist
=
input_data
.
read_data_sets
(
'MNIST_data'
,
one_hot
=
True
)
def
standard
_scale
(
X_train
,
X_test
):
preprocessor
=
prep
.
StandardScaler
(
).
fit
(
X_train
)
def
minmax
_scale
(
X_train
,
X_test
):
preprocessor
=
prep
.
MinMaxScaler
(
feature_range
=
(
0
,
1
)
).
fit
(
X_train
)
X_train
=
preprocessor
.
transform
(
X_train
)
X_test
=
preprocessor
.
transform
(
X_test
)
return
X_train
,
X_test
...
...
@@ -21,7 +21,7 @@ def get_random_block_from_data(data, batch_size):
return
data
[
start_index
:(
start_index
+
batch_size
)]
X_train
,
X_test
=
standard
_scale
(
mnist
.
train
.
images
,
mnist
.
test
.
images
)
X_train
,
X_test
=
minmax
_scale
(
mnist
.
train
.
images
,
mnist
.
test
.
images
)
n_samples
=
int
(
mnist
.
train
.
num_examples
)
training_epochs
=
20
...
...
@@ -30,8 +30,7 @@ display_step = 1
autoencoder
=
VariationalAutoencoder
(
n_input
=
784
,
n_hidden
=
200
,
optimizer
=
tf
.
train
.
AdamOptimizer
(
learning_rate
=
0.001
),
gaussian_sample_size
=
128
)
optimizer
=
tf
.
train
.
AdamOptimizer
(
learning_rate
=
0.001
))
for
epoch
in
range
(
training_epochs
):
avg_cost
=
0.
...
...
autoencoder/autoencoder_models/VariationalAutoencoder.py
View file @
55a34ae5
...
...
@@ -4,11 +4,9 @@ import autoencoder.Utils
class
VariationalAutoencoder
(
object
):
def
__init__
(
self
,
n_input
,
n_hidden
,
optimizer
=
tf
.
train
.
AdamOptimizer
(),
gaussian_sample_size
=
128
):
def
__init__
(
self
,
n_input
,
n_hidden
,
optimizer
=
tf
.
train
.
AdamOptimizer
()):
self
.
n_input
=
n_input
self
.
n_hidden
=
n_hidden
self
.
gaussian_sample_size
=
gaussian_sample_size
network_weights
=
self
.
_initialize_weights
()
self
.
weights
=
network_weights
...
...
@@ -18,14 +16,12 @@ class VariationalAutoencoder(object):
self
.
z_mean
=
tf
.
add
(
tf
.
matmul
(
self
.
x
,
self
.
weights
[
'w1'
]),
self
.
weights
[
'b1'
])
self
.
z_log_sigma_sq
=
tf
.
add
(
tf
.
matmul
(
self
.
x
,
self
.
weights
[
'log_sigma_w1'
]),
self
.
weights
[
'log_sigma_b1'
])
# sample from gaussian distribution
eps
=
tf
.
random_normal
(
(
self
.
gaussian_sample_size
,
n_hidden
),
0
,
1
,
dtype
=
tf
.
float32
)
eps
=
tf
.
random_normal
(
tf
.
pack
([
tf
.
shape
(
self
.
x
)[
0
],
self
.
n_hidden
]
),
0
,
1
,
dtype
=
tf
.
float32
)
self
.
z
=
tf
.
add
(
self
.
z_mean
,
tf
.
mul
(
tf
.
sqrt
(
tf
.
exp
(
self
.
z_log_sigma_sq
)),
eps
))
self
.
reconstruction
=
tf
.
add
(
tf
.
matmul
(
self
.
z
,
self
.
weights
[
'w2'
]),
self
.
weights
[
'b2'
])
# cost
reconstr_loss
=
0.5
*
tf
.
reduce_sum
(
tf
.
pow
(
tf
.
sub
(
self
.
reconstruction
,
self
.
x
),
2.0
))
latent_loss
=
-
0.5
*
tf
.
reduce_sum
(
1
+
self
.
z_log_sigma_sq
...
...
@@ -38,7 +34,6 @@ class VariationalAutoencoder(object):
self
.
sess
=
tf
.
Session
()
self
.
sess
.
run
(
init
)
def
_initialize_weights
(
self
):
all_weights
=
dict
()
all_weights
[
'w1'
]
=
tf
.
Variable
(
autoencoder
.
Utils
.
xavier_init
(
self
.
n_input
,
self
.
n_hidden
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment