Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nicolas PERNOUD
gan_demo
Commits
33712b68
Commit
33712b68
authored
Feb 17, 2020
by
Nicolas PERNOUD
Browse files
chore: refactored gan_01.py
parent
58b55ea5
Changes
1
Hide whitespace changes
Inline
Side-by-side
gan_01.py
View file @
33712b68
...
...
@@ -7,12 +7,20 @@ from keras.models import Sequential
from
keras.datasets
import
fashion_mnist
from
keras.optimizers
import
Adam
z_dim
=
100
img_lines
=
28
img_columns
=
28
img_channels
=
1
img_shape
=
(
img_lines
,
img_columns
,
img_channels
)
def
build_generator
(
img_shape
,
z_dim
):
model
=
Sequential
()
model
.
add
(
Dense
(
128
,
input_dim
=
z_dim
))
model
.
add
(
LeakyReLU
(
alpha
=
0.01
))
model
.
add
(
Dense
(
28
*
28
*
1
,
activation
=
'tanh'
))
model
.
add
(
Dense
(
img_lines
*
img_columns
*
img_channels
,
activation
=
'tanh'
))
model
.
add
(
Reshape
(
img_shape
))
return
model
...
...
@@ -34,14 +42,6 @@ def build_gan(generator, discriminator):
return
model
z_dim
=
100
img_lines
=
28
img_columns
=
28
img_channels
=
1
img_shape
=
(
img_lines
,
img_columns
,
img_channels
)
discriminator
=
build_discriminator
(
img_shape
)
discriminator
.
compile
(
loss
=
'binary_crossentropy'
,
optimizer
=
Adam
(),
metrics
=
[
'accuracy'
])
...
...
@@ -91,7 +91,7 @@ def train(iterations, batch_size, sample_interval):
losses
.
append
((
d_loss
,
g_loss
))
accuracies
.
append
((
100
*
accuracy
))
iteration_checkpoints
.
append
(
iteration
+
1
)
status
=
'iteration: {:} [D loss:{:}, acc.:{:2.2%}] [G loss: {:}]'
.
format
(
status
=
'iteration: {:} [D loss:
{:}, acc.:
{:2.2%}] [G loss: {:}]'
.
format
(
iteration
+
1
,
d_loss
,
accuracy
,
g_loss
)
print
(
status
)
sample_images
(
generator
,
iteration
+
1
)
...
...
Write
Preview
Supports
Markdown
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