TypeError: 无法解包非可迭代的 NoneType 对象

8 浏览
0 Comments

TypeError: 无法解包非可迭代的 NoneType 对象

我知道这个问题之前已经被问过了,但是我似乎无法让我的代码工作。

import numpy as np
def load_dataset():
    def download(filename, source="http://yaan.lecun.com/exdb/mnist/"):
        print ("下载中 ",filename)
        import urllib
        urllib.urlretrieve(source+filename,filename)
        
    import gzip
    def load_mnist_images(filename):
        if not os.path.exists(filename):
            download(filename)
        with gzip.open(filename,"rb") as f:
            data=np.frombuffer(f.read(), np.uint8, offset=16)
            data = data.reshape(-1,1,28,28)
            return data/np.float32(256)
        
    def load_mnist_labels(filename):
        if not os.path.exists(filename):
            download(filename)
        with gzip.open(filename,"rb") as f:
            data = np.frombuffer(f.read(), np.uint8, offset=8)
        return data
    
    X_train = load_mnist_images("train-images-idx3-ubyte.gz")
    y_train = load_mnist_labels("train-labels-idx1-ubyte.gz")
    X_test = load_mnist_images("t10k-images-idx3-ubyte.gz")
    y_test = load_mnist_labels("t10k-labels-idx1-ubyte.gz")
    
    return X_train, y_train, X_test, y_test
X_train, y_train, X_test, y_test = load_dataset()
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
plt.show(plt.imshow(X_train[3][0]))

这是我得到的错误信息:

Traceback (most recent call last):
  File "C:\Users\nehad\Desktop\Neha\Non-School\Python\Handwritten Digits 
Recognition.py", line 38, in 
    X_train, y_train, X_test, y_test = load_dataset()
TypeError: 无法解包非可迭代的 NoneType 对象

我是机器学习的新手。我错过了什么简单的东西吗?我正在尝试一个手写数字识别项目,用于我的学校科学展览。

0