[Python] How to load a dataset(.npz) locally in tensorflow?

Discussão em 'Python' iniciado por Stack, Agosto 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a handwritten didgits recognition project. I need to load the data from mnist dataset. My problem is that I can't use the load_data() function because when it starts downloading the dataset, it returns an error:

    URL fetch failure on https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz: No connection could be made because the target machine actively refused it

    Here is the piece of code that I use:

    mnist = tf.keras.datasets.mnist
    (x_train, y_train), (x_test, y_test) = mnist.load_data()


    I downloaded the mnist.npz file using device that has access to the directory. How can I use the file locally instead of loading it?

    This is what I tried: (x_train, y_train), (x_test, y_test) = tf.keras.utils.get_file(os.path.abspath('mnist.npz'), origin='', extract=True)

    It returned an error: too many values to unpack (expected 2)

    Continue reading...

Compartilhe esta Página