0

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();

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51
Trey Balut
  • 1,355
  • 3
  • 19
  • 39
  • If you inspect the stack trace, what is the file it is complaining about? – amy8374 Dec 28 '18 at 18:49
  • Did you check the returned values of the get file path code to see if it are existing paths? You could add a check there using Path.Exists(). It seems very fragile code to me with this .parent.parent.parent.xxx navigation – Peter Bons Dec 28 '18 at 19:11
  • Could not load file or assembly 'System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified. – Trey Balut Dec 28 '18 at 19:32
  • Peter, The files are in the Path for dataset and testDataset. Because it is UWP should I move these to StorageFolder locations and remove file paths? – Trey Balut Dec 28 '18 at 19:35
  • Amy, is that the correct data from Stack Trace? Call Stack? – Trey Balut Dec 28 '18 at 19:35
  • It's not that you can just read any file with UWP app. So user should allow access to a directory or as you said, you should move these files so they're in the app's directory where it has access without asking a user for it. – Michal Kania Dec 28 '18 at 20:19
  • You're going to have big problems with all that broad file system access. UWP apps cannot even access **My Documents** by default. You'll need to use `FileOpenPicker`, `StorageFolder.GetFolderFromPathAsync`, `StorageFile.CopyAsync` for `ApplicationData.Current.LocalCacheFolder`. https://learn.microsoft.com/en-us/windows/uwp/get-started/fileio-learning-track –  Dec 30 '18 at 05:41

1 Answers1

1

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)

Stefan Wick MSFT
  • 13,600
  • 1
  • 32
  • 51