Skip to content

Metrics in bf.metrics are not serializable #496

@vpratz

Description

@vpratz

Keras tries to handle the serilization and fails, I think we have to manually specify from/get_config methods.

Below the error message for RootMeanSquaredError.

File "/home/valentin/Programming/IWR/bf2/bayesflow/approximators/continuous_approximator.py", line 238, in get_compile_config
    return base_config | serialize(config)
                         ^^^^^^^^^^^^^^^^^
  File "/home/valentin/Programming/IWR/bf2/bayesflow/utils/serialization.py", line 172, in serialize
    return keras.tree.map_structure(serialize, obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valentin/Programming/.mamba/envs/bf2/lib/python3.11/site-packages/optree/ops.py", line 752, in tree_map
    return treespec.unflatten(map(func, *flat_args))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/valentin/Programming/IWR/bf2/bayesflow/utils/serialization.py", line 176, in serialize
    return keras.saving.serialize_keras_object(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Cannot serialize object functools.partial(<function root_mean_squared_error at 0x7f1b7def7240>) of type <class 'functools.partial'>. To be serializable, a class must implement the `get_config()` method.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions