Wie in Datei logistic_sgd.py erwähnt http://deeplearning.net/tutorial/code/logistic_sgd.py
erste können Sie diese Datei manuell herunterladen Geben Sie unter http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz eine Datei 'mnist.pkl.gz' in Ihr aktuelles Verzeichnis ein, da die Funktion zuerst prüft, ob sich die mnist-Datei im Datenverzeichnis befindet. Wenn Sie dies tun, überprüfen Sie, ob es installiert ist und alles funktioniert.
def load_data(dataset):
''' Loads the dataset
:type dataset: string
:param dataset: the path to the dataset (here MNIST)
'''
#############
# LOAD DATA #
#############
# Download the MNIST dataset if it is not present
data_dir, data_file = os.path.split(dataset)
if data_dir == "" and not os.path.isfile(dataset):
# Check if dataset is in the data directory.
new_path = os.path.join(
os.path.split(__file__)[0],
"..",
"data",
dataset
)
if os.path.isfile(new_path) or data_file == 'mnist.pkl.gz':
dataset = new_path
if (not os.path.isfile(dataset)) and data_file == 'mnist.pkl.gz':
from six.moves import urllib
origin = (
'http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz'
)
print('Downloading data from %s' % origin)
urllib.request.urlretrieve(origin, dataset)
print('... loading data')
# Load the dataset
with gzip.open(dataset, 'rb') as f:
try:
train_set, valid_set, test_set = pickle.load(f, encoding='latin1')
except:
train_set, valid_set, test_set = pickle.load(f)
# train_set, valid_set, test_set format: tuple(input, target)
# input is a numpy.ndarray of 2 dimensions (a matrix)
# where each row corresponds to an example. target is a
# numpy.ndarray of 1 dimension (vector) that has the same length as
# the number of rows in the input. It should give the target
# to the example with the same index in the input.
- die Linie mit
urllib.request.urlretrieve(origin, dataset)
hat für mich auch nicht, aber Sie einfach die Datei herunterladen, um so habe ich einige Änderungen
from urllib import request
def get(url):
with request.urlopen(url) as r:
return r.read()
def download(url, file=None):
if not file:
file = url.split('/')[-1]
with open(file, 'wb') as f:
f.write(get(url))
und rufen Sie die Download-Funktion
url = "http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz"
download(url)
Nach diesen Änderungen wird die Funktion load_data für mich
Ich habe einige mehr Investigation gut funktioniert:
Ersetzen Sie diese Aussage:
urllib.request.urlretrieve(origin, dataset)
mit dem folgenden Statement :
dataset, header = urllib.request.urlretrieve(origin, 'mnist.pkl.gz')
Sie erhalten ein Tupel zurück von urlretrieve und mit Datensatz aus dem Tupel, mit dem Sie in der gzip.open-Anweisung arbeiten müssen!
Bei einer Schätzung (weiß nicht ganz, was Sie versuchen), versucht es, eine lokale Datei zu öffnen, die es nicht finden kann - versuchen Sie herauszufinden, warum das ist. – Yoda