TensorFlow.NET icon indicating copy to clipboard operation
TensorFlow.NET copied to clipboard

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

Open kojack14 opened this issue 1 year ago • 4 comments

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

kojack14 avatar Aug 07 '23 23:08 kojack14

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)

clarson15 avatar Aug 25 '23 05:08 clarson15

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 avatar Aug 25 '23 09:08 Wanglongzhi2001

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 avatar Aug 25 '23 11:08 Wanglongzhi2001

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

Wanglongzhi2001 avatar Nov 09 '23 14:11 Wanglongzhi2001