Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Install-python-tensorflow-gym
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christof Kaufmann
Install-python-tensorflow-gym
Commits
7f8fe5c5
Commit
7f8fe5c5
authored
8 months ago
by
Christof Kaufmann
Browse files
Options
Downloads
Patches
Plain Diff
Improve style in Keras3 test script
parent
58f02fed
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
attachments/mnistKeras3.py
+22
-19
22 additions, 19 deletions
attachments/mnistKeras3.py
with
22 additions
and
19 deletions
attachments/mnistKeras3.py
+
22
−
19
View file @
7f8fe5c5
import
tensorflow
as
tf
import
tensorflow
as
tf
import
keras
import
keras
from
keras.models
import
Sequential
from
keras.models
import
Sequential
from
keras.layers
import
Conv2D
,
MaxPooling2D
,
Flatten
,
Dense
from
keras.layers
import
Conv2D
,
MaxPooling2D
,
Flatten
,
Dense
,
Input
from
keras.utils
import
to_categorical
from
keras.utils
import
to_categorical
from
keras.datasets
import
mnist
from
keras.datasets
import
mnist
...
@@ -9,35 +9,38 @@ print('=========================')
...
@@ -9,35 +9,38 @@ print('=========================')
print
(
'
TensorFlow Version
'
,
tf
.
__version__
)
print
(
'
TensorFlow Version
'
,
tf
.
__version__
)
print
(
'
Keras Version
'
,
keras
.
__version__
)
print
(
'
Keras Version
'
,
keras
.
__version__
)
print
(
'
=========================
'
)
print
(
'
=========================
'
)
print
(
tf
.
config
.
list_physical_devices
())
print
(
'
=========================
'
)
(
X
T
rain
,
y
T
rain
),
(
X
T
est
,
y
T
est
)
=
mnist
.
load_data
()
(
X
_t
rain
,
y
_t
rain
),
(
X
_t
est
,
y
_t
est
)
=
mnist
.
load_data
()
X
T
rain
=
X
T
rain
.
reshape
(
60000
,
28
,
28
,
1
)
X
_t
rain
=
X
_t
rain
.
reshape
(
60000
,
28
,
28
,
1
)
X
T
est
=
X
T
est
.
reshape
(
10000
,
28
,
28
,
1
)
X
_t
est
=
X
_t
est
.
reshape
(
10000
,
28
,
28
,
1
)
X
T
rain
=
X
T
rain
/
255
X
_t
rain
=
X
_t
rain
/
255
X
T
est
=
X
T
est
/
255
X
_t
est
=
X
_t
est
/
255
YT
rain
=
to_categorical
(
y
T
rain
,
10
)
y_t
rain
=
to_categorical
(
y
_t
rain
,
10
)
YT
est
=
to_categorical
(
y
T
est
,
10
)
y_t
est
=
to_categorical
(
y
_t
est
,
10
)
myANN
=
Sequential
()
model
=
Sequential
()
myANN
.
add
(
Conv2D
(
9
,
kernel_size
=
(
3
,
3
),
activation
=
'
relu
'
,
kernel_initializer
=
'
he_uniform
'
,
input_shape
=
(
28
,
28
,
1
)))
myANN
.
add
(
Input
((
28
,
28
,
1
)))
myANN
.
add
(
MaxPooling2D
(
2
))
model
.
add
(
Conv2D
(
9
,
kernel_size
=
(
3
,
3
),
activation
=
'
relu
'
,
kernel_initializer
=
'
he_uniform
'
))
myANN
.
add
(
Flatten
())
model
.
add
(
MaxPooling2D
(
2
))
myANN
.
add
(
Dense
(
20
,
activation
=
'
tanh
'
))
model
.
add
(
Flatten
())
myANN
.
add
(
Dense
(
10
,
activation
=
'
softmax
'
))
model
.
add
(
Dense
(
20
,
activation
=
'
tanh
'
))
myANN
.
compile
(
loss
=
'
categorical_crossentropy
'
,
optimizer
=
'
nadam
'
,
metrics
=
[
'
accuracy
'
])
model
.
add
(
Dense
(
10
,
activation
=
'
softmax
'
))
myANN
.
fit
(
XTrain
,
YTrain
,
batch_size
=
500
,
epochs
=
5
,
verbose
=
True
)
model
.
compile
(
loss
=
'
categorical_crossentropy
'
,
optimizer
=
'
nadam
'
,
metrics
=
[
'
accuracy
'
])
model
.
fit
(
X_train
,
y_train
,
batch_size
=
500
,
epochs
=
5
,
verbose
=
True
)
mse
,
acc
=
m
yANN
.
evaluate
(
X
T
est
,
YT
est
,
verbose
=
False
)
mse
,
acc
=
m
odel
.
evaluate
(
X
_t
est
,
y_t
est
,
verbose
=
False
)
print
(
'
Test loss:
'
,
mse
,
'
Test accuracy:
'
,
acc
)
print
(
'
Test loss:
'
,
mse
,
'
Test accuracy:
'
,
acc
)
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
fig
=
plt
.
figure
()
fig
=
plt
.
figure
()
for
i
in
range
(
9
):
for
i
in
range
(
9
):
ax
=
fig
.
add_subplot
(
3
,
3
,
i
+
1
)
ax
=
fig
.
add_subplot
(
3
,
3
,
i
+
1
)
ax
.
imshow
(
X
T
rain
[
i
].
squeeze
(),
cmap
=
'
gray
'
,
interpolation
=
'
none
'
)
ax
.
imshow
(
X
_t
rain
[
i
].
squeeze
(),
cmap
=
'
gray
'
,
interpolation
=
'
none
'
)
ax
.
set_title
(
y
T
rain
[
i
])
ax
.
set_title
(
y
_t
rain
[
i
])
plt
.
tight_layout
()
plt
.
tight_layout
()
plt
.
show
()
plt
.
show
()
...
...
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