# How to convert pb file to h5?

**URL:** <https://community.deeplearning.ai/t/how-to-convert-pb-file-to-h5/753968>\
**Category:** AI Discussions\
**Tags:** ai-discussions, data-centric\
**Created:** [January 18, 2025, 10:14am UTC](https://community.deeplearning.ai/t/how-to-convert-pb-file-to-h5/753968 "2025-01-18T10:14:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NothingON](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@NothingON](https://community.deeplearning.ai/u/NothingON)\
**Post date:** [January 18, 2025, 10:14am UTC](https://community.deeplearning.ai/t/how-to-convert-pb-file-to-h5/753968/1 "2025-01-18T10:14:57Z")

</div>

My tf version is 2.18 that doesn’t support pb file.  
So i searched on google and then wrote these code.

```auto
import os
import tensorflow as tf
from tensorflow.keras.preprocessing import image

pb_model_dir = "model_data/"
h5_model = "./saved_model.h5"

# Loading the Tensorflow Saved Model (PB)
model = tf.saved_model.load(pb_model_dir)

# Saving the Model in H5 Format
tf.keras.models.save_model(model, h5_model)

```

But there is a error

```auto
 AttributeError: '_UserObject' object has no attribute 'get_config'

```

I tried tf.keras.models.load\_model too but the there is also a error

```auto
File format not supported: filepath=model_data/. Keras 3 only supports V3 `.keras` files and legacy H5 format files (`.h5` extension). Note that the legacy SavedModel format is not supported by `load_model()` in Keras 3. In order to reload a TensorFlow SavedModel as an inference-only layer in Keras 3, use `keras.layers.TFSMLayer(model_data/, call_endpoint='serving_default')` (note that your `call_endpoint` might have a different name).

```

Many people seem to solve this problem by using one of above ways, but it didn’t work at my environment. How to convert pb file to h5??

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 18, 2025, 12:18pm UTC](https://community.deeplearning.ai/t/how-to-convert-pb-file-to-h5/753968/2 "2025-01-18T12:18:37Z")

</div>

see if this documentation helps you

> **[tfjs/tfjs-converter at master · tensorflow/tfjs](https://github.com/tensorflow/tfjs/tree/master/tfjs-converter#step-1-converting-a-tensorflow-savedmodel-tensorflow-hub-module-keras-hdf5-or-tfkeras-savedmodel-to-a-web-friendly-format)**
>
> A WebGL accelerated JavaScript library for training and deploying ML models. - tensorflow/tfjs

check the regular conversion script header section
