MNIST数据集解压的正确方式:ValueError: cannot reshape array of size 9912406 into shape (60000,28,28,1)

  • Post author:
  • Post category:其他




win7 环境报错

  1. File

    “C:/DCGAN/main.py”

    , line

    63

    ,

    in

    main

  2. sample_dir=FLAGS.sample_dir)

  3. File

    “C:\DCGAN\model.py”

    , line

    74

    ,

    in

    __init__

  4. self.data_X, self.data_y = self.load_mnist()

  5. File

    “C:\DCGAN\model.py”

    , line

    461

    ,

    in

    load_mnist

  6. trX = loaded[

    16

    :].reshape((

    60000

    ,

    28

    ,

    28

    ,

    1

    )).astype(np.float)

  7. ValueError: cannot reshape array of size

    9912406

    into shape (

    60000

    ,

    28

    ,

    28

    ,

    1

    )


linux(Ubuntu)环境报错


  1. File

    “main.py”

    , line

    63

    ,

    in

    main

  2. sample_dir=FLAGS.sample_dir)

  3. File

    “/root/DCGAN-tensorflow-master/model.py”

    , line

    74

    ,

    in

    __init__

  4. self.data_X, self.data_y = self.load_mnist()

  5. File

    “/root/DCGAN-tensorflow-master/model.py”

    , line

    459

    ,

    in

    load_mnist

  6. trX = loaded[

    16

    :].reshape((

    60000

    ,

    28

    ,

    28

    ,

    1

    )).astype(np.float)

  7. ValueError: cannot reshape array of size

    9912406

    into shape (

    60000

    ,

    28

    ,

    28

    ,

    1

    )


原因

数据集解压方式错误,MNIST文件下载后是.gz格式,需要在linux环境下解压(win7环境用rar解压,报同样错误)

t10k-images-idx3-ubyte.gz

t10k-labels-idx1-ubyte.gz

train-images-idx3-ubyte.gz

train-labels-idx1-ubyte.gz

解压后的文件列表:

t10k-images-idx3-ubyte

t10k-labels-idx1-ubyte

train-images-idx3-ubyte

train-labels-idx1-ubyte


linux(Ubuntu)环境gz解压指令:


gunzip –c train-labels-idx1-ubyte.gz > train-labels-idx1-ubyte

gunzip –c train-images-idx3-ubyte.gz   > train-images-idx3-ubyte

gunzip –c t10k-images-idx3-ubyte.gz  > t10k-images-idx3-ubyte


gunzip –c t10k-labels-idx1-ubyte.gz   > t10k-labels-idx1-ubyte





版权声明:本文为u012885320原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。