FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Machine-Learning-with-Python/mnist-deep-learning.py at master · devAmoghS/Machine-Learning-with-Python · GitHub
devAmoghS
/
Machine-Learning-with-Python
Public
Notifications
You must be signed in to change notification settings
Fork
204
Star
1.3k
Code
Issues
0
Pull requests
8
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Machine-Learning-with-Python
/
mnist-deep-learning.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (19 loc) · 941 Bytes
Breadcrumbs
Machine-Learning-with-Python
/
mnist-deep-learning.py
Copy path
File metadata and controls
23 lines (19 loc) · 941 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from
keras
.
datasets
import
mnist
(
train_images
,
train_labels
), (
test_images
,
test_labels
)
=
mnist
.
load_data
()
# 1. Prepare the Data
from
keras
.
utils
import
to_categorical
train_images
=
train_images
.
reshape
((
60000
,
28
*
28
)).
astype
(
'float32'
)
/
255
test_images
=
test_images
.
reshape
((
10000
,
28
*
28
)).
astype
(
'float32'
)
/
255
train_labels
=
to_categorical
(
train_labels
)
test_labels
=
to_categorical
(
test_labels
)
# 2. Set up network architecture
from
keras
import
models
,
layers
network
=
models
.
Sequential
()
network
.
add
(
layers
.
Dense
(
512
,
activation
=
'relu'
,
input_shape
=
(
28
*
28
,)))
network
.
add
(
layers
.
Dense
(
10
,
activation
=
'softmax'
))
# 3/4. Pick Optimizer and Loss
network
.
compile
(
optimizer
=
'rmsprop'
,
loss
=
'categorical_crossentropy'
,
metrics
=
[
'accuracy'
])
network
.
fit
(
train_images
,
train_labels
,
epochs
=
5
,
batch_size
=
128
)
# 5. Measure on test
test_loss
,
test_acc
=
network
.
evaluate
(
test_images
,
test_labels
)
print
(
'test_acc:'
,
test_acc
)
Back
|
FazBrowse Home
|
New Git URL