tensorflow / tensorflow/probability
Tensorflow Probability: saving and loading model
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to fit a model with TensorFlow probability, for example:
input = Input(shape=(32,32,32,3))
x = tfp.layers.Convolution3DReparameterization(
64, kernel_size=5, padding='SAME', activation=tf.nn.relu,
data_format = 'channels_first')(input)
x = tf.keras.layers.MaxPooling3D(pool_size=(2, 2, 2),
strides=(2, 2, 2),
padding='SAME')(x)
x = tf.keras.layers.Flatten()(x)
output = tfp.layers.DenseFlipout(10)(x)
model3 = Model(input, output)
model3.save('tf_test_model3.h5')
When I load the model as model3 = load_model('tf_test_model3.h5'), I get the following error:
ValueError: Unknown layer: Conv3DReparameterization. Please ensure this object is passed to the `custom_objects` argument.
When I pass it to custom_objects as:
custom_objects= {'Conv3DReparameterization': tfp.layers.Convolution3DReparameterization}
model3 = load_model('tf_test_model3.h5', custom_objects=custom_objects)
I get the following error:
TypeError: 'str' object is not callable
How can I fix this? Please note that I want to save the whole architecture. Not just the weights.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the model.save and load_model example using Convolution3DReparameterization and DenseFlipout. Start by tracing how these TensorFlow Probability layers are serialized and how Keras handles custom_objects during loading. Done means the complete architecture can be saved and loaded without the reported Unknown layer or TypeError errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100