fix: Implemented support for loading models with Concatenate layers#1192
Merged
Oceania2018 merged 2 commits intoSciSharp:masterfrom Oct 11, 2023
Merged
fix: Implemented support for loading models with Concatenate layers#1192Oceania2018 merged 2 commits intoSciSharp:masterfrom
Oceania2018 merged 2 commits intoSciSharp:masterfrom
Conversation
model.load_model now supports loading of concatenate layers. python tensorflow exports concatenate layers in an extra nested array in the manifest so added a check for that in generic_utils.cs. Concatenate was missing the build=true, this fix prevents the layer being build multiple times. Concatenate has 2 or more input nodes so List<NodeConfig> was required instead of just NodeConfig in Functional.FromConfig.cs. Added missing axis JsonProperty attribute for MergeArgs (used by Concatenate)
The loading and saving of a simple model with a Concatenate layer is tested to check if the model is the same after reloading. Implemented missing axis parameter for np.stack (added some handy tuple calls too like the np.concatenate example).
Contributor
|
Thank you very much for your contribution! |
Contributor
|
Looks good to me! @Oceania2018 |
Contributor
Author
|
Do i have to do anything regarding the semantic check that failed? But to fix that I need to rename the commit title? |
Contributor
The reason for semantic checking error is the incorrect format of your commit title. The ci in TensorFlow.NET obey the angular style, You can change it to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is my first serious pullrequest so please be gentle :)
The
tf.keras.models.load_model()is now able to load models with this layer type.There was a lot missing but I have a Unet model running in the field that now fully works.
I had some weird troubles with python tensorflow (im using 2.11.1) that savemodel would put the inbound nodes for concatenate layers in an extra nested array. My call in python looks like:
This would create the following output in the manifest (notice the extra
[and]:{ "class_name": "Concatenate", "config": { "name": "EXP_1_concat1", "trainable": true, "dtype": "float32", "axis": 3 }, "name": "EXP_1_concat1", "inbound_nodes": [ [ [ "CNT_4_conv_2", 0, 0, {} ], [ "EXP_1_conv_0", 0, 0, {} ] ] ] },so thats why i added an extra check in generic_utils.cs for this extra nest. I would love some feedback on the implementation of this check and if it's the correct way to do.
And lastly, since concatenate layers have more than 1 input node we need a List when processing nodes in Functional.FromConfig.cs.
I also added a few tests to make sure that saving and loading a model with concatenate layers is the same (this was not the case before my changes).