I'm trying to run the following code from a tutorial, but get an error. Based on other posts, it seems like this is a permissions problem (?). I've read about a chmod 777 solution, but I'm not sure how exactly to implement it. I am working on a Mac and running the following code in the Rodeo Python IDE.
def load_dataset():
url = 'http://deeplearning.net/data/mnist/mnist.pkl.gz'
filename = 'mnist.pkl.gz'
if not os.path.exists(filename):
print("Downloading MNIST dataset...")
urlretrieve(url, filename)
with gzip.open(filename, 'rb') as f:
data = pickle.load(f)
X_train, y_train = data[0]
X_val, y_val = data[1]
X_test, y_test = data[2]
X_train = X_train.reshape((-1, 1, 28, 28))
X_val = X_val.reshape((-1, 1, 28, 28))
X_test = X_test.reshape((-1, 1, 28, 28))
y_train = y_train.astype(np.uint8)
y_val = y_val.astype(np.uint8)
y_test = y_test.astype(np.uint8)
return X_train, y_train, X_val, y_val, X_test, y_test
X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()
>>> X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()
Downloading MNIST dataset...
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
<ipython-input-55-b5dfc0ed9477> in <module>()
----> 1 X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()
<ipython-input-51-554e12c9ff6c> in load_dataset()
4 if not os.path.exists(filename):
5 print("Downloading MNIST dataset...")
----> 6 urlretrieve(url, filename)
7 with gzip.open(filename, 'rb') as f:
8 data = pickle.load(f)
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.pyc in urlretrieve(url, filename, reporthook, data, context)
96 else:
97 opener = _urlopener
---> 98 return opener.retrieve(url, filename, reporthook, data)
99 def urlcleanup():
100 if _urlopener:
/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.pyc in retrieve(self, url, filename, reporthook, data)
247 headers = fp.info()
248 if filename:
--> 249 tfp = open(filename, 'wb')
250 else:
251 import tempfile
IOError: [Errno 13] Permission denied: 'mnist.pkl.gz'
## I'm guessing this means I'm in the root directory.
>>> print os.getcwd()
/
It looks like you're trying to save the file into your root (/
) directory and you probably won't have permission there. Save it to some other place.