TypeError: cannot unpack non-iterable NoneType object

Neha Devi Shakya :

I know this question has been asked before but I can't seem to get mine to work. Can someone help me out with this?

import numpy as np


def load_dataset():
    def download(filename, source="http://yaan.lecun.com/exdb/mnist/"):
        print ("Downloading ",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]))

This is the error I am getting:

Traceback (most recent call last):
  File "C:\Users\nehad\Desktop\Neha\Non-School\Python\Handwritten Digits 
Recognition.py", line 38, in <module>
    X_train, y_train, X_test, y_test = load_dataset()
TypeError: cannot unpack non-iterable NoneType object

I am new to machine learning. Did I just miss something simple? I am trying a Handwritten Digit Recognition project for my school Science Exhibition.

Thanks in advance!

Amaras :

I think your X_train, y_train, X_test, y_test are defined inside your load_mnist_imagesfunction, and are thus not defined for your load_dataset function.

You should de-indent your 5 lines from X_train = ... to return X_train, ... and your code might work better then.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

-- TypeError: cannot unpack non-iterable NoneType object

PyAutoGui TypeError: cannot unpack non-iterable NoneType object

TypeError: cannot unpack non-iterable NoneType object Error

Calling local variable causes TypeError: cannot unpack non-iterable NoneType object

TypeError: cannot unpack non-iterable NoneType object when running a sorting function

Error occurs running code in terminal "TypeError: cannot unpack non-iterable NoneType object"

I am getting: TypeError: cannot unpack non-iterable NoneType object, but I am returning a tuple

Python 3.8.2| Why do I have a : TypeError: cannot unpack non-iterable NoneType object?

Python error- cannot unpack non-iterable NoneType object

Find smaller number from 2 provided - works, but throws an error. TypeError: cannot unpack non-iterable NoneType object

This error occurs when I'm running my code on terminal "TypeError: cannot unpack non-iterable NoneType object"

TypeError: cannot unpack non-iterable GetColorImage object

tensorflow TypeError: cannot unpack non-iterable float object

TypeError: cannot unpack non-iterable int object

Python Django: TypeError: cannot unpack non-iterable MatchAll object

TypeError at /cart/ cannot unpack non-iterable Cart object

TypeError: cannot unpack non-iterable bool object

Python: TypeError: cannot unpack non-iterable int object

Python TypeError: cannot unpack non-iterable bool object

Python / TypeError: cannot unpack non-iterable Jugador object

TypeError: cannot unpack non-iterable int object (Python)

TypeError: cannot unpack non-iterable Lexer object

"TypeError: cannot unpack non-iterable int object" with filter function

How to fix TypeError: cannot unpack non-iterable Button object

Cannot unpack non-iterable object

(TypeError: cannot unpack non-iterable int object) for inversion counter using merge sort

TypeError: cannot unpack non-iterable int object in Django views function

I am getting a "TypeError: cannot unpack non-iterable int object"

Error iterating over a list 'TypeError: cannot unpack non-iterable object'