【发布时间】:2018-12-28 18:44:06
【问题描述】:
我正在尝试将 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 = pipeline.Train();
【问题讨论】:
-
如果您检查堆栈跟踪,它抱怨的文件是什么?
-
你有没有检查get file path code的返回值是否是现有的路径?您可以使用 Path.Exists() 在此处添加检查。这个 .parent.parent.parent.xxx 导航对我来说似乎很脆弱的代码
-
无法加载文件或程序集“System.ComponentModel.Composition, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”。系统找不到指定的文件。
-
Peter,文件位于数据集和 testDataset 的路径中。因为它是 UWP,我应该将这些移动到 StorageFolder 位置并删除文件路径吗?
-
艾米,这是来自 Stack Trace 的正确数据吗?调用堆栈?