emnist训练数据集中的字母是旋转的,并且是小迷走神经

2024-06-16 10:33:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是emnist-letters-train-images-idx3-ubyte.gz公司和emnist-letters-train-labels-idx1-ubyte.gz公司来自http://biometrics.nist.gov/cs_links/EMNIST/gzip.zip
我写这个小剧本是为了看图像

import os
import struct
import numpy as np
import scipy.misc
np.set_printoptions(threshold='nan')
path = './'
fname_img = os.path.join(path, 'emnist-letters-train-images-idx3-ubyte')
fname_lbl = os.path.join(path, 'emnist-letters-train-labels-idx1-ubyte')
with open(fname_lbl, 'rb') as flbl:
        magic, num = struct.unpack(">II", flbl.read(8))
        lbl = np.fromfile(flbl, dtype=np.int8)
with open(fname_img, 'rb') as fimg:
    magic, num, rows, cols = struct.unpack(">IIII", fimg.read(16))
    img = np.fromfile(fimg, dtype=np.uint8).reshape(len(lbl), rows, cols)
print 'image',img.shape
print 'label',lbl.shape
labels, indices = np.unique(lbl,return_index=True)
print 'unique labels',labels
print 'unique indices',indices
    for i in indices:
        image = img[i]
        for y in image:
            row = ""
            for x in y:
                row += '{0: <4}'.format(x)
            print row
        print 'label',lbl[i],'\n'
        newfilename = str(lbl[i]) + '.jpg'
        scipy.misc.imsave(newfilename, image)

这是输出图像montage of letters a to z
我的问题是-i和l是不可区分的,r是不可识别的,许多字母是颠倒的。为什么?在

谢谢。在


Tags: pathimageimportimglabelsosnptrain
3条回答

这里的问题很可能是您读取数据集数组的方式。如果转置正在读取的数组(例如,对于numpy数组,your_array.T),EMNIST字符的方向应该正确。在

正如安基特·蒂瓦里所说。 水平翻转和旋转后,它看起来没问题。 谢谢。 见looks ok a to z

水平翻转图像,然后逆时针旋转90度。在

相关问题 更多 >