尝试加载load_mnist(...)函数时,TypeError .....有多个参数值

时间:2019-10-12 22:50:50

标签: python function typeerror

请协助解决以下错误

def load_mnist(path, kind='train'):
    """Load MNIST data from `path`"""
    labels_path = os.path.join(path, 
                               '%s-labels-idx1-ubyte' % kind)
    images_path = os.path.join(path, 
                               '%s-images-idx3-ubyte' % kind)

    with open(labels_path, 'rb') as lbpath:
        magic, n = struct.unpack('>II', 
                                 lbpath.read(8))
        labels = np.fromfile(lbpath, 
                             dtype=np.uint8)

    with open(images_path, 'rb') as imgpath:
        magic, num, rows, cols = struct.unpack(">IIII", 
                                               imgpath.read(16))
        images = np.fromfile(imgpath, 
                             dtype=np.uint8).reshape(len(labels), 784)
        images = ((images / 255.) - .5) * 2

    return images, labels

然后:

X_train, y_train = load_mnist('.\\Chapter 12\\MNIST', 'labels-idx1-ubyte', kind='train')

错误消息是:

  

TypeError:load_mnist()为参数“种类”获得了多个值

目录内容为:

t10k-images.idx3-ubyte

t10k-labels.idx1-ubyte

train-images.idx3-ubyte

train-labels.idx1-ubyte

1 个答案:

答案 0 :(得分:0)

错误是load_mnist接受了两个参数,但您确实给load_mnist提供了三个参数(如@uneven_mark所说的那样)

让我更正您的代码

X_train, Y_train = load_mnist('.\\Chapter 12\\MNIST', kind='train')

load_mnist函数中没有错误,该错误在变量赋值中