将控制台应用程序转换为UWP应用程序错误ML.NET

时间:2018-12-28 18:44:07

标签: c# .net uwp ml.net

我正在尝试将ML.NET应用程序从Win控制台转换为UWP,并且没有将文件加载到ML管道中。我收到“找不到文件”错误。

这是我的代码:

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

这是获取文件代码:

 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;
    }

这是我的物品。

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

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

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

我在以下行得到错误:

  

var model = pipe.Train();

1 个答案:

答案 0 :(得分:1)

不是您希望的答案,但这是ML.NET较新版本的一个已知错误: https://github.com/dotnet/corefx/issues/33434

作为解决此错误的方法,您必须暂时使用0.6.0版,直到解决该问题为止。

不幸的是,如果您尝试通过Microsoft Store发行应用,可能还会遇到另一个错误:https://github.com/dotnet/machinelearning/issues/1736(您会在发行版本中看到该错误,而不是在调试版本中看到该错误)