-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_mnist.py
executable file
·33 lines (25 loc) · 1.17 KB
/
test_mnist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
import mxnet as mx
import numpy as np
from symbol import get_shufflenet
from fshufflenetv2 import get_shufflenet_v2
from fmobilefacenet import get_mobilefacenet
logging.getLogger().setLevel(logging.INFO)
mnist = mx.test_utils.get_mnist()
print mnist['train_data'].shape
batch_size = 256
train_data = np.concatenate((mnist['train_data'], mnist['train_data'], mnist['train_data']), axis=1)
val_data = np.concatenate((mnist['test_data'], mnist['test_data'], mnist['test_data']), axis=1)
train_iter = mx.io.NDArrayIter(train_data, mnist['train_label'], batch_size, shuffle=True)
val_iter = mx.io.NDArrayIter(val_data, mnist['test_label'], batch_size)
# shufflenet = get_shufflenet()
# shufflenet = get_shufflenet_v2()
shufflenet = get_mobilefacenet()
shufflenet_mod = mx.mod.Module(symbol=shufflenet, context=[mx.gpu(0)]) # [mx.gpu(0), mx.gpu(1)]
shufflenet_mod.fit(train_iter,
eval_data=val_iter,
optimizer='sgd',
optimizer_params={'learning_rate':0.01},
eval_metric='acc',
batch_end_callback = mx.callback.Speedometer(batch_size, 20),
num_epoch=10)