Skip to content
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

[Question]: Error when using keras.models.load_model() #1163

Open
kojack14 opened this issue Aug 7, 2023 · 4 comments
Open

[Question]: Error when using keras.models.load_model() #1163

kojack14 opened this issue Aug 7, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@kojack14
Copy link

kojack14 commented Aug 7, 2023

Description

i am geting this error when trying to load the model :

Tensorflow.ValueError: 'The tensor conv1d/Relu:0 at layer l_s_t_m is part of a cycle.'

the model :

public static IModel MultivariateImprovedRNNModel(List inputShape)
{
var layer = keras.layers;
var model = new Sequential(new SequentialArgs() { Name = "MultivariateImprovedRNN_Model" });

        var inputs = keras.Input(shape: new Shape(inputShape[1], inputShape[0]));
        model.add(inputs);

        model.add(layer.Conv1D(256, kernel_size: 1, padding: "same", activation: "relu", strides: 1));

        model.add(layer.LSTM(256, return_sequences: true));
        model.add(layer.LSTM(256));
        model.add(layer.Dense(6));

        model.summary();

        model.compile(optimizer: keras.optimizers.Adam(learning_rate: 0.001f),
                      loss: keras.losses.MeanSquaredError(),
                      metrics: new[] { "mean_absolute_error" });

        return model;
    }

Alternatives

No response

@clarson15
Copy link

I can't call this method at all. I created a very basic model with the layers api, saved it, then tried to load it next iteration and I'm getting this error:

System.ArgumentNullException: Value cannot be null.
   at System.ArgumentNullException.Throw(String paramName)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at Tensorflow.Keras.Utils.generic_utils.deserialize_layer_args(String class_name, JToken config)
   at Tensorflow.Keras.Utils.generic_utils.deserialize_model_config(JToken json)
   at Tensorflow.Keras.Saving.KerasObjectLoader._reconstruct_model(Int32 model_id, Model model, List`1 layers)
   at Tensorflow.Keras.Saving.KerasObjectLoader._reconstruct_all_models()
   at Tensorflow.Keras.Saving.KerasObjectLoader.finalize_objects()
   at Tensorflow.Keras.Saving.SavedModel.KerasLoadModelUtils.load(String path, Boolean compile, LoadOptions options)
   at Tensorflow.Keras.Saving.SavedModel.KerasLoadModelUtils.load_model(String filepath, IDictionary`2 custom_objects, Boolean compile, LoadOptions options)
   at Tensorflow.Keras.Models.ModelsApi.load_model(String filepath, Boolean compile, LoadOptions options)

@Wanglongzhi2001
Copy link
Collaborator

I'm very sorry, because the developer responsible for this api is busy recently, so it may not be so fast to solve this problem, I will let you know once it is completed.

@Wanglongzhi2001 Wanglongzhi2001 added the bug Something isn't working label Aug 25, 2023
@Wanglongzhi2001
Copy link
Collaborator

I can't call this method at all. I created a very basic model with the layers api, saved it, then tried to load it next iteration and I'm getting this error:

System.ArgumentNullException: Value cannot be null.
   at System.ArgumentNullException.Throw(String paramName)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at Tensorflow.Keras.Utils.generic_utils.deserialize_layer_args(String class_name, JToken config)
   at Tensorflow.Keras.Utils.generic_utils.deserialize_model_config(JToken json)
   at Tensorflow.Keras.Saving.KerasObjectLoader._reconstruct_model(Int32 model_id, Model model, List`1 layers)
   at Tensorflow.Keras.Saving.KerasObjectLoader._reconstruct_all_models()
   at Tensorflow.Keras.Saving.KerasObjectLoader.finalize_objects()
   at Tensorflow.Keras.Saving.SavedModel.KerasLoadModelUtils.load(String path, Boolean compile, LoadOptions options)
   at Tensorflow.Keras.Saving.SavedModel.KerasLoadModelUtils.load_model(String filepath, IDictionary`2 custom_objects, Boolean compile, LoadOptions options)
   at Tensorflow.Keras.Models.ModelsApi.load_model(String filepath, Boolean compile, LoadOptions options)

Hello, I have located the error, could you mind provide a simple code to show your model? I will test my idea. Thank you very much.

@Wanglongzhi2001
Copy link
Collaborator

Hello, dose this bug still exist? If so, could you please provide a minimul example for reproduction?

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

No branches or pull requests

3 participants