将图像转换为MNIST格式

时间:2018-07-18 12:25:34

标签: python

我在使用python脚本时遇到问题。我有一个无法解决的问题。 通常我在Git上找到它。它据说正在工作。下面是脚本的一部分。
可变文件夹是包含14个子文件夹的文件夹的路径。

def get_labels_and_files(folder, number=0):
    # Make a list of lists of files for each label
    filelists = []
    subdir = get_subdir(folder)
    for label in range(0, len(subdir)):
        filelist = []
        filelists.append(filelist)
        dirname = os.path.join(folder, subdir[label])
        for file in os.listdir(dirname):
            if (file.endswith('.png')):
                fullname = os.path.join(dirname, file)
                if (os.path.getsize(fullname) > 0):
                    filelist.append(fullname)
                else:
                    print('file ' + fullname + ' is empty')
        # sort each list of files so they start off in the same order
        # regardless of how the order the OS returns them in
        filelist.sort()

    # Take the specified number of items for each label and
    # build them into an array of (label, filename) pairs
    # Since we seeded the RNG, we should get the same sample each run
    labelsAndFiles = []
    for label in range(0, len(subdir)):
        count = number if number > 0 else len(filelists[label])
        filelist = random.sample(filelists[label], count)
        for filename in filelist:
            labelsAndFiles.append((label, filename))

    return labelsAndFiles


def make_arrays(labelsAndFiles, ratio):
    global height, width
    images = []
    labels = []
    imShape = imageio.imread(labelsAndFiles[0][1]).shape

错误消息:

C:\PROGRAMOWANIE\Python_OCR\Convert-own-data-to-MNIST-format-master\Convert-own-
data-to-MNIST-format-master>python convert_to_mnist_format.py C:\PROGRAMOWANIE\P
ython\OCR_Math\training_images 10
Traceback (most recent call last):
File "convert_to_mnist_format.py", line 215, in 
main(sys.argv)
File "convert_to_mnist_format.py", line 199, in main
labelsAndFiles, argv[2])
File "convert_to_mnist_format.py", line 115, in make_arrays
imShape = imageio.imread(labelsAndFiles[0][1]).shape
IndexError: list index out of range

有人可以让我更明智地看一下这个,然后说出什么问题吗。

0 个答案:

没有答案