Python- deep learning - learning Notes (10): For reading h5py file path to solve the problem
error code:
OSError: Unable to open file (unable to open file: name = ‘datasets/train_catvnoncat.h5’, errno = 2, error message = ‘No such file or directory’, flags = 0, o_flags = 0)
HDF5 Profile
HDF (Hierarchical Data Format) refers to a large capacity to store and process design scientific data file format and the corresponding library file.
h5py Profile
h5py container file is located two types of objects, datasets (DataSet) and group (group), dataset class data set similar to the array, and the array almost numpy. group is the same folder as the container, in which like python dictionary, there are key (key) and the value (value). dataset can be stored in the group or other group. HDF5 a file name from a "/" in the group beginning, and all the other dataset group are included in this group, when operating HDF5 file, if not explicitly specified in the dataset are the default group means "/" under dataset, similar additional relative file path names are relative to the group of "/".
h5py HDF5 file operation is used.
In the anaconda installation h5py
pip install h5py
During installation, be sure to know their packages you want to install h5py to which the virtual environment, if you install the wrong hair, then there will be call failed during execution.
Ado provide solutions under h5py open file failed below.
Read h5py resolve the file path failures
In the course of homework deeplearning.ai Andrew Ng, there is an analysis of the data set, which needs its own datasets and lr_utils.py are downloaded from the Internet, Download here for everyone: https://pan.baidu .com / S / 1Uui641jlRL9JD9WS-z3yRA , but we will put anaconda3 two files we installed, the following error occurs:
this error means that can not be read, or can not find such a file.
Solution:
I tried myself to create the file at the end of a .h5, and find its location and found it saved here.
This is the path: C: \ the Users \ 405 , I found that it did not save it to anaconda3.
So I will datasets (file .h5 file contains folders) is also saved to this root directory, I found the problem solved.
Conclusion: The directory my file is read h5pyC:\Users\405. Here only to provide you an idea, you can get your save path by creating a .h5 file, or you can try to save as I did at the root admin.
#创建.h5文件代码
import h5py
import numpy as np
#HDF5的写入:
imgData = np.zeros((2,4))
f = h5py.File('HDF5_FILE.h5','w') #创建一个h5文件,文件指针是f
f['data'] = imgData #将数据写入文件的主键data下面
f['labels'] = np.array([1,2,3,4,5]) #将数据写入文件的主键labels下面
f.close() #关闭文件
#HDF5的读取:
f = h5py.File('HDF5_FILE.h5','r') #打开h5文件
#可以查看所有的主键
for key in f.keys():
print(f[key].name)
print(f[key].shape)
print(f[key].value)
lr_utils.py file
This is a package of its own files, I save path is C: \ Users \ 405 \ Anaconda3 \ envs \ python36
Note: python36 is my virtual environment
We hope to be able to help you