keras-io icon indicating copy to clipboard operation
keras-io copied to clipboard

Imposible to save model for : bayesian_neural_networks.py

Open Martinc4321 opened this issue 3 years ago • 0 comments

When i simply do: prob_bnn_model.save('model') after the run_experiment was called on prob_bnn_model.

This file

Then I am getting error message: Traceback (most recent call last): File "gitCopy.py", line 403, in prob_bnn_model.save("asdasd") File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/lib/python3.8/contextlib.py", line 120, in exit next(self.gen) File "/home/conto/.local/lib/python3.8/site-packages/tensorflow_probability/python/layers/distribution_layer.py", line 220, in call distribution, _ = super(DistributionLambda, self).call( tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: iterating over tf.Tensor is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.

When i try to save it in H5 format then message is: Traceback (most recent call last): File "gitCopy.py", line 403, in prob_bnn_model.save("asdasd.h5") File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/local/lib/python3.8/dist-packages/keras/engine/base_layer.py", line 746, in get_config raise NotImplementedError(textwrap.dedent(f""" NotImplementedError: Layer DenseVariational has arguments ['self', 'units', 'make_posterior_fn', 'make_prior_fn', 'kl_weight', 'kl_use_exact', 'activation', 'use_bias', 'activity_regularizer'] in __init__ and therefore must override get_config(). Example: class CustomLayer(keras.layers.Layer): def init(self, arg1, arg2): super().init() self.arg1 = arg1 self.arg2 = arg2

def get_config(self):
    config = super().get_config()
    config.update({
        "arg1": self.arg1,
        "arg2": self.arg2,
    })
    return config
    

@fchollet Any advice how to save my model based on this code ?

Martinc4321 avatar Dec 31 '21 10:12 Martinc4321