尝试打开 h5 文件时出现 filenotfound 错误

发布于 2025-01-11 15:12:10 字数 1405 浏览 0 评论 0原文

我有一个包含“catvnoncat”数据集的 h5 文件。当我尝试运行以下代码时,出现错误,我将其包含在底部。我尝试从三个不同的来源获取数据集,以排除文件损坏的可能性。

我想知道是什么原因导致了这个问题?

# My Code
import h5py
train_dataset = h5py.File('train_catvnoncat.h5', "r")
# The Error
Traceback (most recent call last):
  File "f:\Downloads\Compressed\coursera-deep-learning-specialization-master_2\coursera-deep-learning-specialization-master\C1 - Neural Networks and Deep Learning\Week 2\Logistic Regression as a Neural Network\lr_utils.py", line 4, in <module>
    train_dataset = h5py.File('train_catvnoncat.h5', "r")
  File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 507, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
  File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 220, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 106, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'train_catvnoncat.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

I have a h5 file that contains the "catvnoncat" dataset. when I try to run the following code, I get an error which I will include at the bottom. I have tried getting the dataset from three different sources to exclude to possibility of a corrupted file.

What I would like to know is what is causing the problem?

# My Code
import h5py
train_dataset = h5py.File('train_catvnoncat.h5', "r")
# The Error
Traceback (most recent call last):
  File "f:\Downloads\Compressed\coursera-deep-learning-specialization-master_2\coursera-deep-learning-specialization-master\C1 - Neural Networks and Deep Learning\Week 2\Logistic Regression as a Neural Network\lr_utils.py", line 4, in <module>
    train_dataset = h5py.File('train_catvnoncat.h5', "r")
  File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 507, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
  File "C:\Users\Mohsen\AppData\Local\Programs\Python\Python39\lib\site-packages\h5py\_hl\files.py", line 220, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 106, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = 'train_catvnoncat.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很糊涂小朋友 2025-01-18 15:12:10

您的代码正在查找当前目录,而不是文件所在的目录。

根据错误消息,您似乎在 Windows 上。文件“train_catvnoncat.h5”是否位于您的下载文件夹中?在您的系统上找到该文件并复制完整路径。然后您可以将其更新

train_dataset = h5py.File('train_catvnoncat.h5', "r")

为包含完整路径的内容。与此类似:

train_dataset = h5py.File('C:/Users/Moshen/Downloads/train_catvnoncat.h5', "r")

注意斜杠并确保将文件路径更新为实际值。

Your code is looking in the current directory which is not where the file is.

Based on the error message, it looks like you are on windows. Is the file 'train_catvnoncat.h5' in your Downloads folder? Find that file on your system and copy the full path. You can then update this:

train_dataset = h5py.File('train_catvnoncat.h5', "r")

to something that contains the full path. Similar to this:

train_dataset = h5py.File('C:/Users/Moshen/Downloads/train_catvnoncat.h5', "r")

Pay attention to the slashes and make sure you update the file path to the actual value.

零崎曲识 2025-01-18 15:12:10

我遇到了同样的问题,可能 datasets.h5 已损坏

打开此链接并从建议的存储库下载数据集

https ://morioh.com/p/ce76c6e2f7f6

train_dataset 应约为 2MB,test_dataset 603KB

https://rpaudel42.github.io/datasets/NN.zip

这对我有用!

I had the same issue, probably the datasets.h5 were corrupted

Open this link and download the datasets, from the suggested repository

https://morioh.com/p/ce76c6e2f7f6

The train_dataset should be about 2MB and test_dataset 603KB

https://rpaudel42.github.io/datasets/NN.zip

This worked for me !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文