Skip to content

[BUG Report]: Unable to load multiple models at once #1174

Closed
@clarson15

Description

@clarson15

Description

I am unable to create multiple networks at the same time. I have a file containing the weights of my network, but only 1 model.load_weights succeeds. I thought maybe it was unable to load the same file multiple times, so I tried loading different files and still only the first model succeeds. I am getting the error message:

Exception thrown: 'Tensorflow.ValueError' in Tensorflow.Keras.dll: 'You are trying to load a weight file containing System.String[] layers into a model with 5 layers.'
   at Tensorflow.Keras.Saving.hdf5_format.load_weights_from_hdf5_group(Int64 f, List`1 layers)
   at Tensorflow.Keras.Engine.Model.load_weights(String filepath, Boolean by_name, Boolean skip_mismatch, Object options)

Reproduction Steps

public class Network {
    private IModel model;
    public Network()
    {
        var layers = keras.layers;
        var input = keras.Input(shape: 301, name: "game-parameters");
        var dense = layers.Dense(256, activation: keras.activations.Relu).Apply(input);


        var output = layers.Dense(1, activation: keras.activations.Linear).Apply(dense);

        model = keras.Model(input, output, name: "example");
        model.compile(optimizer: keras.optimizers.Adam(learning_rate: 0.001f), loss: keras.losses.MeanSquaredError(), metrics: new[] { keras.metrics.Accuracy() });
    }

    public void Save()
    {
        model.save_weights("./model.h5, save_format: "h5");
    }

    public void Load()
    {
        model.load_weights("./model.h5");
    }
}

public class Program
{
    public static void Main()
    {
        var model1 = new Network();
        var model2 = new Network();
        model1.Save();
        model2.Load();

        // or if model.h5 already exists
       model1.Load();
       model2.Load();
    }
}

Known Workarounds

No response

Configuration and Other Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions