mxnet解决AttributeError: module 'mxnet.test_utils' has no attribute 'get_mnist'这个报错

  出现 AttributeError: module 'mxnet.test_utils' has no attribute 'get_mnist' 这个报错,主要是因为mxnet版本过低,有两个解决办法。
1,升级mxnet版本。

2,不升级版本,利用mxnet.io.MNISTIter来加载数据。步骤如下:
  (1)先去http://yann.lecun.com/exdb/mnist/下载mnist数据集。
  (2)下载好之后,解压,得到4个以-ubyte结尾的文件。
   (3)先看看mxnet.io.MNISTIter的参数:

Parameters: 
    image (string, optional, default='./train-images-idx3-ubyte') – Dataset Param: Mnist image path.
    label (string, optional, default='./train-labels-idx1-ubyte') – Dataset Param: Mnist label path.
    batch_size (int, optional, default='128') – Batch Param: Batch Size.
    shuffle (boolean, optional, default=1) – Augmentation Param: Whether to shuffle data.
    flat (boolean, optional, default=0) – Augmentation Param: Whether to flat the data into 1D.
    seed (int, optional, default='0') – Augmentation Param: Random Seed.
    silent (boolean, optional, default=0) – Auxiliary Param: Whether to print out data info.
    num_parts (int, optional, default='1') – partition the data into multiple parts
    part_index (int, optional, default='0') – the index of the part will read
    prefetch_buffer (long (non-negative), optional, default=4) – Maximum number of batches to prefetch.
    dtype ({None, 'float16', 'float32', 'float64', 'int32', 'uint8'},optional, default='None') – Output data type. None means no change.

  (4)重要的参数主要是image,label,batch_size,shuffle。于是利用下面的代码构建数据:

path = 'E:\python file\data_set\mnist/' # 数据所在的位置
train_iter = mx.io.MNISTIter(image=path+'train-images.idx3-ubyte',
                             label=path+'train-labels.idx1-ubyte',
                             batch_size=100, shuffle=True)
val_iter = mx.io.MNISTIter(image=path+'t10k-images.idx3-ubyte',
                           label=path+'t10k-labels.idx1-ubyte',
                           batch_size=100)

  注意,这里的E:\python file\data_set\mnist是数据存放的绝对位置,你需要根据你自己数据存放的位置改动。
  至此,就可以使用train_iter 和 val_iter去训练你的模型了。

你可能感兴趣的:(mxnet,mxnet,mnist,get-mnist)