我有一個包含“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)
uj5u.com熱心網友回復:
您的代碼正在查找不是檔案所在的當前目錄。
根據錯誤訊息,您似乎在 Windows 上。您的下載檔案夾中是否有檔案“train_catvnoncat.h5”?在您的系統上找到該檔案并復制完整路徑。然后你可以更新這個:
train_dataset = h5py.File('train_catvnoncat.h5', "r")
到包含完整路徑的東西。與此類似:
train_dataset = h5py.File('C:/Users/Moshen/Downloads/train_catvnoncat.h5', "r")
注意斜線并確保將檔案路徑更新為實際值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/440047.html
下一篇:如何在子目錄中編輯.py組態檔?
