在Windows上未找到根文件夹中现有文件的路径

我在D盘中解压了这4个文件:

train-images-idx3-ubytetrain-labels-idx1-ubyte t10k-images-idx3-ubytet10k-labels-idx1-ubyte

我遇到了以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'D:/train-labels-idx1-ubyte'

我的代码如下:

def load_mnist(path, kind='train'):    """Load MNIST data from `path`"""    path = "D:/"    labels_path = os.path.join(path,                               '%s-labels-idx1-ubyte' % kind)    images_path = os.path.join(path,                               '%s-images-idx3-ubyte' % kind)    with open(labels_path, 'rb') as lbpath:        magic, n = struct.unpack('>II',                                 lbpath.read(8))        labels = np.fromfile(lbpath,                             dtype=np.uint8)    with open(images_path, 'rb') as imgpath:        magic, num, rows, cols = struct.unpack(">IIII",                                               imgpath.read(16))        images = np.fromfile(imgpath,                             dtype=np.uint8).reshape(len(labels), 784)    return images, labels

完整的错误信息如下:

Traceback (most recent call last):  File "C:/Users/PycharmProjects/MachineLearning/NN2.py", line 28, in <module>    X_train, y_train = load_mnist('mnist/', kind='train')  File "C:/Users/PycharmProjects/MachineLearning/NN2.py", line 14, in load_mnist    with open(labels_path, 'rb') as lbpath:FileNotFoundError: [Errno 2] No such file or directory: 'D:/train-labels-idx1-ubyte'

这原本是教科书中的代码:https://github.com/rasbt/python-machine-learning-book/blob/master/code/ch12/ch12.ipynb


回答:

这可能是一个路径问题。你可以尝试通过命令行终端进入你的D:文件夹,然后在那里打开Python解释器,执行

以显示D:下的所有文件和文件夹。然后,你可以检查train-labels-idx1-ubyte文件是否确实存在以及它的拼写是否正确。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注