Skip to content

Results in file not found error GZIP HASH-LIB #7

@Dharmogata

Description

@Dharmogata

can anyone help me understand why this is resulting in a file not found error, trying to fetch the datasets from the mnist dataset to follow along with someone else doing the same thing, on their end this exact code works fine.

def fetch(url):
import requests, gzip, os, hashlib, numpy
fp = os.path.join("/tmp", hashlib.md5(url.encode('utf-8')).hexdigest())
if not os.path.isfile(fp):
with open(fp, "rb") as f:
dat = f.read()
else:
with open(fp, "wb") as f:
dat = requests.get(url).content
f.write(dat)
return numpy.frombuffer(gzip.decompress(dat), dtype=np.uint8).copy()
X_train = fetch("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz")[0x10:].reshape((-1, 28, 28))
Y_train = fetch("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz")[8:]
X_test = fetch("http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz")[0x10:].reshape((-1, 28, 28))
Y_test = fetch("http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz")[8:]

in fetch(url)
6 print(fp)
7 if not os.path.isfile(fp):
----> 8 with open(fp, "rb") as f:
9 dat = f.read()
10 else:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/23278f029ff68f1e993776e500ce06b9'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions