Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dharmogata opened this issue Nov 25, 2020 · 1 comment
Open

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

Dharmogata opened this issue Nov 25, 2020 · 1 comment

Comments

@Dharmogata
Copy link

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'

@giglioq
Copy link

giglioq commented May 20, 2022

This can be fixed by removing the '/' before 'temp' when joining the path
i.e.
fp = os.path.join("tmp", hashlib.md5(url.encode('utf-8')).hexdigest())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants