用mnis的basic程序进行Python深度学习

2024-09-26 22:54:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个深入学习的新手,我只是在做我的第一步。我有一个MacBook Pro 2017模型,我正在尝试使用逻辑回归来运行MNIST dataset。当我运行官方深度学习网站上提到的示例代码时,我收到以下错误。。在

<i>Downloading data from http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz
Traceback (most recent call last):
File "/Users/abi/PycharmProjects/LogisticRgr_test/logist_test.py", line 475, in <module>
sgd_optimization_mnist()
File "/Users/abi/PycharmProjects/LogisticRgr_test/logist_test.py", line 277, in sgd_optimization_mnist
datasets = load_data(dataset)
File "/Users/abi/PycharmProjects/LogisticRgr_test/logist_test.py", line 205, in load_data
urllib.request.urlretrieve(origin, dataset)
File "/Users/abi/miniconda2/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "/Users/abi/miniconda2/lib/python2.7/urllib.py", line 249, in retrieve
tfp = open(filename, 'wb')
IOError: [Errno 2] No such file or directory: '/Users/abi/PycharmProjects/LogisticRgr_test/../data/mnist.pkl.gz'

Process finished with exit code 1</i>

Tags: inpytestdatalineurllibusersdataset
1条回答
网友
1楼 · 发布于 2024-09-26 22:54:21

如文件物流所述_新加坡元http://deeplearning.net/tutorial/code/logistic_sgd.py

首先,您可以在http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz上手动下载此文件 添加文件'mnist.pkl.gz版'到当前目录,因为函数首先检查mnist文件是否在data目录中。如果你这样做,那么检查是否安装了numpy和一切正常。在

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.
  1. 这条线 urllib.request.urlretrieve(origin, dataset)对我也不起作用,但是你只要下载文件,我就做了一些修改

^{pr2}$

然后调用下载函数

^{3}$

在这些更改之后,load_data函数对我很好



我又做了些调查:

替换此语句:

urllib.request.urlretrieve(origin, dataset)

声明如下:

dataset, header = urllib.request.urlretrieve(origin, 'mnist.pkl.gz')

从urlretrieve中获取一个元组,并从必须在gzip.open声明!在

相关问题 更多 >

    热门问题