Differences in results between saving in .h5 format and weights only

I create a model based on efficientNet_b0, when I tried to save it in the default keras format it gave the following error:

KeyError: “Failed to add concrete function ‘b’__inference_EfficientNet_layer_call_fn_1379410’’ to object-based SavedModel as it captures tensor <tf.Tensor: shape=(), dtype=resource, value=> which is unsupported or not reachable One reason could be that a stateful object or a variable that the function depends on is not assigned to an attribute of the serialized trackable object (see SaveTest.test_captures_unreachable_variable).”

So, I saved it to .h5, but the result was not the same as the one obtained before (this on the same dataset).
Previously obtained result:

  • Confusion Matrix
    231 0
    0 97

Result obtained with the load in .h5 format:

  • Confusion Matrix
    231 62
    0 35

So, I try this problem, I just saved the weights, and I recreated the architecture, and the result is back to normal.

Any tips where I might be going wrong? And how to fix the error of saving by keras default mode?

@Staub,

Can you take a look at this github issue which discusses about similar KeyError. Also can you take a look at this guide. Thanks!