in tensorflow_model_remediation/min_diff/keras/models/min_diff_model.py [0:0]
def get_config(self):
"""Creates a config dictionary for the `MinDiffModel` instance.
Note: This will ignore anything resulting from the kwargs passed in at
initialization time or changes made to new attributes added afterwards. If
this is problematic you will need to subclass MinDiffModel and override this
method to account for these.
Any subclass with additional attributes will need to override this method.
When doing so, users will mostly likely want to first call `super`.
Returns:
A config dictionary for the `MinDiffModel` isinstance.
Raises:
Exception: If calling `original_model.get_config()` raises an error. The
type raised will be the same as that of the original error.
"""
# Check that original_model.get_config is implemented and raise a helpful
# error message if not.
try:
_ = self._original_model.get_config()
except Exception as e:
raise type(e)(
"MinDiffModel cannot create a config because `original_model` has "
"not implemented get_config() or has an error in its implementation."
"\nError raised: {}".format(e))
# Try super.get_config if implemented. In most cases it will not be.
try:
config = super(MinDiffModel, self).get_config()
except NotImplementedError:
config = {}
config.update({
"original_model": self._original_model,
"loss": self._loss,
"loss_weight": self._loss_weight,
"name": self.name,
})
if self._predictions_transform is not None:
config["predictions_transform"] = dill.dumps(self._predictions_transform)
return {k: v for k, v in config.items() if v is not None}