Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG Report]: An item with the same key has already been added. Key: keras_api #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
astronomicalphenomena opened this issue Apr 18, 2023 · 6 comments
Assignees
Labels
bug Something isn't working model save/load

Comments

@astronomicalphenomena
Copy link

Description

When saving model, this error happened.
By reading Linq code, it seems like happening in TensorFlowNET.Keras.Engine.Layer.Serialize._trackable_children when concatenating model trackable with another trackable while they both have Key: keras_api

model trackable keys:
layer-0
layer-1
layer_with_weights-0
layer-2
keras_api

children keys:
non_trainable_variables
layers
variables
trainable_variables
keras_api

Reproduction Steps

load a keras pb model saved by python and save it immediately:

var model = keras.models.load_model(@"path");
model.summary();
model.save(@"path");

Known Workarounds

saveweght is fine

Configuration and Other Information

python tensorflow version: 2.10.0-GPU
TensorFlow.Redist version:2.10.0-CPU
Tensorflow.NET: 0.100.4
Tensorflow.Keras :0.10.4
.NET: 7.0

@AsakusaRinne
Copy link
Collaborator

Hi, thank you for reporting us this BUG. I'll fix it soon. :)

@AsakusaRinne AsakusaRinne self-assigned this Apr 18, 2023
@AsakusaRinne AsakusaRinne added bug Something isn't working model save/load labels Apr 18, 2023
@astronomicalphenomena
Copy link
Author

What's more, UWP will break down in clrcore while using V1 LoadSession function under new version, but not very sure, need more test. I will abandon UWP.

@GadgetNutt
Copy link

I have also experienced this error setting up a Conv1D layer:
Dim denseLayer5 = layers.Conv1D(64, kernel_size:=3, activation:="relu")
Dim denseOutput5 = denseLayer3.Apply(denseOutput4)

@AsakusaRinne
Copy link
Collaborator

Here is a possible work around #976 (comment). I'll fix this BUG this weekend. Recently a little busy and forgot it🤣Sorry for that

@AsakusaRinne
Copy link
Collaborator

#1049 partially fixed this problem. Note that tf.net support loading models with functions/concrete functions now but hasn't supported saving models with functions/concrete functions. The complete support for model saving would be added in 2 weeks. It's recommended to use model saving after loading (from model saved in python) after that.

@romanmanasipov
Copy link

Here is a possible work around #976 (comment). I'll fix this BUG this weekend. Recently a little busy and forgot it🤣Sorry for that

Can the mentioned workaround be added any time soon? The issue still persists when loading and saving keras model for the 2nd time, it throws:
System.ArgumentException: An item with the same key has already been added. Key: non_trainable_variables

can be reproduced e.g. using avaliable unit tests:

// build and save model
AlexnetFromSequential();
// load and save again
var model = tf.keras.models.load_model(@"./alexnet_from_sequential");

model.summary();


model.save("./saved_alexnet_from_sequential_after_loading"); // <- the ERROR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working model save/load
Projects
None yet
Development

No branches or pull requests

4 participants