def test_Cifar10Rec(): # skip-this test for saving time return get_data.GetCifar10() dataiter = mx.io.ImageRecordIter( path_imgrec="data/cifar/train.rec", mean_img="data/cifar/cifar10_mean.bin", rand_crop=False, and_mirror=False, shuffle=False, data_shape=(3,28,28), batch_size=100, preprocess_threads=4, prefetch_buffer=1) labelcount = [0 for i in range(10)] batchcount = 0 for batch in dataiter: npdata = batch.data[0].asnumpy().flatten().sum() sys.stdout.flush() batchcount += 1 nplabel = batch.label[0].asnumpy() for i in range(nplabel.shape[0]): labelcount[int(nplabel[i])] += 1 for i in range(10): assert(labelcount[i] == 5000)
# small mlp network def get_net(): data = mx.symbol.Variable('data') float_data = mx.symbol.Cast(data=data, dtype="float32") fc1 = mx.symbol.FullyConnected(float_data, name='fc1', num_hidden=128) act1 = mx.symbol.Activation(fc1, name='relu1', act_type="relu") fc2 = mx.symbol.FullyConnected(act1, name='fc2', num_hidden=64) act2 = mx.symbol.Activation(fc2, name='relu2', act_type="relu") fc3 = mx.symbol.FullyConnected(act2, name='fc3', num_hidden=10) softmax = mx.symbol.SoftmaxOutput(fc3, name="softmax") return softmax # check data get_data.GetCifar10() def get_iterator_uint8(kv): data_shape = (3, 28, 28) train = mx.io.ImageRecordUInt8Iter(path_imgrec="data/cifar/train.rec", data_shape=data_shape, batch_size=batch_size, rand_crop=True, rand_mirror=True, num_parts=kv.num_workers, part_index=kv.rank) train = mx.io.PrefetchingIter(train) val = mx.io.ImageRecordUInt8Iter(path_imgrec="data/cifar/test.rec",