Trey Balut
Trey Balut

Reputation: 1395

Convert Console app to UWP app error ML.NET

I'm trying to convert a ML.NET app from win console to a UWP and I'm not loading the files into my ML pipeline. I'm getting an File Not Found error.

here is my code:

 public static double ProcessDataBtn_Click(float tempOPS)
    {
        double rpg = 0;

        var dataset = GetDataPathByDatasetName("OPSData.csv");
        var testDataset = GetDataPathByDatasetName("OPSData-test.csv");

        var pipeline = new LearningPipeline
        {
            new TextLoader(dataset).CreateFrom<OPSData>(useHeader: true, separator: ','),
            new ColumnConcatenator("Features", "OPS"),
            new GeneralizedAdditiveModelRegressor()
        };

        var model = pipeline.Train<OPSData, OPSPrediction>();

        model.WriteAsync(GetModelFilePath("model.zip"));

Here is the get file code:

 public static string GetDataPathByDatasetName(string datasetName)
    {
        var appPath = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
        var parentDir = Directory.GetParent(appPath).Parent.Parent.Parent.Parent;
        var datasetPath = Path.Combine(parentDir.FullName, "datasets", datasetName);
        return datasetPath;
    }

    public static string GetModelFilePath(string fileName)
    {
        var appPath = Path.GetDirectoryName(Environment.GetCommandLineArgs().First());
        var parentDir = Directory.GetParent(appPath).Parent.Parent.Parent.Parent;
        var fileDir = Path.Combine(parentDir.FullName, "models");
        if (!Directory.Exists(fileDir))
        {
            Directory.CreateDirectory(fileDir);
        }
        var filePath = Path.Combine(parentDir.FullName, "models", fileName);
        return filePath;
    }

And here are my objects.

 public class OPSData
    {
        [Column("0")]
        public float OPS;

        [Column("1", name: "Label")]
        public float RunsPerGame;
    }

    public class OPSPrediction
    {
        [ColumnName("Score")]
        public float PredictedRPG;
    }

I'getting the error on the following line:

var model = pipeline.Train();

Upvotes: 0

Views: 178

Answers (1)

Stefan Wick  MSFT
Stefan Wick MSFT

Reputation: 13850

Not the answer you were hoping for, but this is a known bug with newer versions of ML.NET: https://github.com/dotnet/corefx/issues/33434

As a workaround for this bug, you'd have to stay with version 0.6.0 for now until this has been addressed.

Unfortunately, there is another bug you will likely hit if you try to release the app via Microsoft Store: https://github.com/dotnet/machinelearning/issues/1736 (you will see the bug in release builds, not in debug builds)

Upvotes: 1

Related Questions