Skip to content

[BUG Report]: Loading weights exported from Python doesn't work #1150

Closed
@OliBomby

Description

@OliBomby

Description

I'm trying to run a model I trained in Python on TensorFlow.NET. I have the weights in HDF5 format and the model replicated in TensorFlow.NET, but when I use model.load_weights(path.h5) it fails to load the weights because it can't find the weights by name.

I did some debugging and found out that it expects dollar signs in the path for some reason, which are normally not there in the weight names.

https://github.com/SciSharp/TensorFlow.NET/blob/fa2d2dcfc894686846f475a98300b6f8af0bfa94/src/TensorFlowNET.Keras/Saving/hdf5_format.cs#L137C21-L141C61

This code seems to be recently added by #1137. The code looks awful, so please revert that change.

Reproduction Steps

In Python with TensorFlow, export some model weights using model.save_weights('my_checkpoint.h5')

Then in C# with TensorFlow.NET, load the weights using model.load_weights("my_checkpoint.h5");

Known Workarounds

Exporting weights using TensorFlow.NET inserts the dollar signs so loading works in that case.

It might be possible to workaround if you manually replace all weight names in the saved weights file.

Configuration and Other Information

  • TensorFlow.NET 0.110.2
  • TensorFlow.Keras 0.11.2
  • .NET 6
  • Windows 10

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions