Microsoft ML.Net will not save model to disk

RB 1 Reputation point
2021-07-26T10:58:11.153+00:00

I've written an application in C# that must be run as a library by another application. The parent application (to which I have an API but no source) is using marshaling I believe to transfer data back and forth between the running application into my library under it's AppDomain.

It must be run in this manner (no exception) in order for me to get the data I need to then pipe into ML.Net to do regressions, and pipe back into the application. In general I do not have an issue with this.

My resolution has been to use ILMerge, but that broke with ML.Net, way too many dependencies and the inability to merge them all. As an alternative, I have used Cody.Costura and specified specific native runtimes (in this case x64) and have been able to properly merge the gob of libraries required for ML.Net and get the DLL to run under the parent application.

ML.Net works, amazingly, and I'm able to do what I need. The problem now is that I need to save the trained model.

If I set the ML.Net CacheDirectoryName for ML.Net.Auto experiment settings, it will create the folder on run and populate it with all the saved models, but they are 0 bytes, and it throws an exception. If I do NOT specify this (set it to null, force memory storage), it runs fine, but I am still unable to save the model later on.

If I try using mlContext.Model.Save(model, schema, filename) it throws the following error:

System.ArgumentException: The path is not of a legal form. at System.IO.Path.NewNormalizePath...

Boils down to Microsoft.ML.RepositoryWriter.CreateNew(...

I've seen other threads indicating that it's being passed an empty string--however, as noted, it will create a 0 byte file on disk as specified. I believe something else is going on here related to this application being run as a DLL.

Any insight is appreciated, I've tried just about everything and cannot get it to budge.

Thanks

.NET Machine learning
.NET Machine learning
.NET: Microsoft Technologies based on the .NET software framework.Machine learning: A type of artificial intelligence focused on enabling computers to use observed data to evolve new behaviors that have not been explicitly programmed.
150 questions
{count} votes