You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create a model and save it, but when loading it I get an error.
System.NullReferenceException: "Object reference not set to an instance of an object."
` public Sequential CreateModelLSTMWithBatchNormalization()
{
Sequential model = KerasApi.keras.Sequential();
model.add(KerasApi.keras.layers.Input(shape: new Shape(51, 3)));
model.add(KerasApi.keras.layers.LSTM(256, return_sequences: true));
model.add(KerasApi.keras.layers.BatchNormalization());
model.add(KerasApi.keras.layers.Dropout(0.3f));
model.add(KerasApi.keras.layers.LSTM(128, return_sequences: true));
model.add(KerasApi.keras.layers.BatchNormalization());
model.add(KerasApi.keras.layers.Dropout(0.3f));
model.add(KerasApi.keras.layers.LSTM(64));
model.add(KerasApi.keras.layers.BatchNormalization());
model.add(KerasApi.keras.layers.Dropout(0.3f));
model.add(KerasApi.keras.layers.Dense(128, activation: "relu"));
model.add(KerasApi.keras.layers.BatchNormalization());
model.add(KerasApi.keras.layers.Dense(52, activation: "softmax"));
var optimizer = new Adam(learning_rate: 0.001f);
model.compile(optimizer: optimizer, loss: new Tensorflow.Keras.Losses.CategoricalCrossentropy(), metrics: new string[] { "accuracy" });
model.summary();
return model;
}
if (Directory.Exists(modelPath))
{
model = (Sequential)KerasApi.keras.models.load_model(modelPath);
}
else
{
model = CreateModelLSTMWithBatchNormalization();
}
public void TrainModelLSTM(NDArray X, NDArray Y, int epochs = 50, int batchSize = 52)
{
try
{
model.fit(X, Y, epochs: epochs, batch_size: batchSize);
model.save(modelPath, save_format: "tf");
}
catch (Exception ex)
{
Console.WriteLine($"Exception: {ex.Message}");
Console.WriteLine(ex.StackTrace);
}
}
`
The text was updated successfully, but these errors were encountered:
Description
I create a model and save it, but when loading it I get an error.
System.NullReferenceException: "Object reference not set to an instance of an object."
` public Sequential CreateModelLSTMWithBatchNormalization()
{
Sequential model = KerasApi.keras.Sequential();
`
The text was updated successfully, but these errors were encountered: