#Importing MLAgents models at runtime from disk, and applying them to an Agent

1 messages · Page 1 of 1 (latest)

midnight bramble
#

Hi,

I am currently trying to read all .onnx files from a folder which I specify and wish to load them at runtime, applying different models to the agent.

I am able to load the .onnx files using the ONNXModelConverter class (which I have made public) as a *Model *type.

However, if I want to apply them to an agent at runtime, they need to be of type ModelAsset, as I would need to set the current model in the Behaviour Parameter script.

Any help would be appreciated, I'm currently using Unity 6, with the latest MLAgents package!


        foreach (FileInfo file in nnList)
        {
            byte[] modelData = File.ReadAllBytes(file.FullName.ToString());
            ONNXModelConverter converter = new ONNXModelConverter(file.FullName.ToString());
            Model sentisModel = converter.Convert();
            folderPathHolder._modelAssets.Add(sentisModel);
            Debug.Log($"Model {sentisModel.ProducerName} loaded from disk.");
        }
    }```