大神地址:https://github.com/gskielian/JPG-PNG-to-MNIST-NN-Format
一般在`Traceback (most recent call last):
File “convert-images-to-mnist-format.py”, line 47, in
header.append(int(‘0x’+hexval[2:][2:],16))
OverflowError: unsigned byte integer is greater than maximum
如果出现以上错误:
(1)查看‘’batches.meta.txt‘’ 序号标签是否匹配
(2)修改代码
import os
from PIL import Image
from array import *
from random import shuffle
# Load from and save to
Names = [['./training-images', 'train'], ['./test-images', 'test']]
for name in Names:
data_image = array('B')
data_label = array('B')
FileList = []
for dirname in os.listdir(name[0]): # [1:] Excludes .DS_Store from Mac OS
path = os.path.join(name[0], dirname)
for filename in os.listdir(path):
if filename.endswith(".png"):
FileList.append(os.path.join(name[0], dirname, filename))
shuffle(FileList