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
c541d653
Commit
c541d653
authored
Aug 18, 2017
by
Alan Yee
Committed by
GitHub
Aug 18, 2017
Browse files
Update AdditiveGaussianNoiseAutoencoderRunner.py
-Fixed print styling -Fixed code according to PEP 8
parent
d9b01e52
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
autoencoder/AdditiveGaussianNoiseAutoencoderRunner.py
autoencoder/AdditiveGaussianNoiseAutoencoderRunner.py
+15
-7
No files found.
autoencoder/AdditiveGaussianNoiseAutoencoderRunner.py
View file @
c541d653
import
numpy
as
np
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
numpy
as
np
import
sklearn.preprocessing
as
prep
import
sklearn.preprocessing
as
prep
import
tensorflow
as
tf
import
tensorflow
as
tf
from
tensorflow.examples.tutorials.mnist
import
input_data
from
tensorflow.examples.tutorials.mnist
import
input_data
...
@@ -8,16 +11,19 @@ from autoencoder_models.DenoisingAutoencoder import AdditiveGaussianNoiseAutoenc
...
@@ -8,16 +11,19 @@ from autoencoder_models.DenoisingAutoencoder import AdditiveGaussianNoiseAutoenc
mnist
=
input_data
.
read_data_sets
(
'MNIST_data'
,
one_hot
=
True
)
mnist
=
input_data
.
read_data_sets
(
'MNIST_data'
,
one_hot
=
True
)
def
standard_scale
(
X_train
,
X_test
):
def
standard_scale
(
X_train
,
X_test
):
preprocessor
=
prep
.
StandardScaler
().
fit
(
X_train
)
preprocessor
=
prep
.
StandardScaler
().
fit
(
X_train
)
X_train
=
preprocessor
.
transform
(
X_train
)
X_train
=
preprocessor
.
transform
(
X_train
)
X_test
=
preprocessor
.
transform
(
X_test
)
X_test
=
preprocessor
.
transform
(
X_test
)
return
X_train
,
X_test
return
X_train
,
X_test
def
get_random_block_from_data
(
data
,
batch_size
):
def
get_random_block_from_data
(
data
,
batch_size
):
start_index
=
np
.
random
.
randint
(
0
,
len
(
data
)
-
batch_size
)
start_index
=
np
.
random
.
randint
(
0
,
len
(
data
)
-
batch_size
)
return
data
[
start_index
:(
start_index
+
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
=
standard_scale
(
mnist
.
train
.
images
,
mnist
.
test
.
images
)
n_samples
=
int
(
mnist
.
train
.
num_examples
)
n_samples
=
int
(
mnist
.
train
.
num_examples
)
...
@@ -25,11 +31,12 @@ training_epochs = 20
...
@@ -25,11 +31,12 @@ training_epochs = 20
batch_size
=
128
batch_size
=
128
display_step
=
1
display_step
=
1
autoencoder
=
AdditiveGaussianNoiseAutoencoder
(
n_input
=
784
,
autoencoder
=
AdditiveGaussianNoiseAutoencoder
(
n_hidden
=
200
,
n_input
=
784
,
transfer_function
=
tf
.
nn
.
softplus
,
n_hidden
=
200
,
optimizer
=
tf
.
train
.
AdamOptimizer
(
learning_rate
=
0.001
),
transfer_function
=
tf
.
nn
.
softplus
,
scale
=
0.01
)
optimizer
=
tf
.
train
.
AdamOptimizer
(
learning_rate
=
0.001
),
scale
=
0.01
)
for
epoch
in
range
(
training_epochs
):
for
epoch
in
range
(
training_epochs
):
avg_cost
=
0.
avg_cost
=
0.
...
@@ -45,6 +52,7 @@ for epoch in range(training_epochs):
...
@@ -45,6 +52,7 @@ for epoch in range(training_epochs):
# Display logs per epoch step
# Display logs per epoch step
if
epoch
%
display_step
==
0
:
if
epoch
%
display_step
==
0
:
print
(
"Epoch:"
,
'%04d'
%
(
epoch
+
1
),
"cost="
,
"{:.9f}"
.
format
(
avg_cost
))
print
(
"Epoch: "
,
'%d,'
%
(
epoch
+
1
),
"Cost: "
,
"{:.9f}"
.
format
(
avg_cost
))
print
(
"Total cost: "
+
str
(
autoencoder
.
calc_total_cost
(
X_test
)))
print
(
"Total cost: "
+
str
(
autoencoder
.
calc_total_cost
(
X_test
)))
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