SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.17k stars 506 forks source link

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

Open kojack14 opened 11 months ago

kojack14 commented 11 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 8 months ago

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