# Read HDF5 (H5) File

### TensorFlow

```python
import tensorflow as tf

model = tf.keras.models.load_model("example.h5")
model.summary()
```

\\

### h5py

**h5py** is the Python library to read and write HDF5 files.

#### Installation

```bash
pip3 install h5py
```

#### Read HDF5 (H5)

Then run the following script.

```python
import h5py

with h5py.File('example.hdf5', 'r') as f:
	# Get all keys
	print("All keys: %s" % f.keys())
	# Get an object
	print("Object: " % f["key_name"])
	print("Object keys: " % f["key_name"].keys())
	print("Sub object: " % f["key_name"]["sub_key_name"])
```

#### Write HDF5 (H5)

```python
import h5py
import numpy as np

data_matrix = np.random.uniform(-1, 1, size=(10, 3))

with h5py.File('example.hdf5', 'w') as f:
	f.create_dataset("dataset_name", data=data_matrix)
```
