问题描述
它是ml.net自动生成的代码,我只实现了按钮1上的打开文件对话框代码。这里是windows窗体应用程序中的图像检测代码。这里有两个按钮和一个图片框。按钮 1 用于浏览图像,按钮 2 用于检测图像。
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender,EventArgs e)
{
var ofd = new OpenFileDialog();
ofd.Filter = "Image Files|*.jpg;*.png";
if (ofd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(ofd.FileName);
}
}
private void button2_Click(object sender,EventArgs e)
{
// Add input data
var input = new Modelinput();
// Load model and predict output of sample data
ModelOutput result = ConsumeModel.Predict(input);
MessageBox.Show(result.Prediction);
}
}
}
当我点击按钮 2 来检测图像时,它给了我这个异常 System.TypeInitializationException: 'The type initializer for 'WindowsFormsApp3ML.Model.ConsumeModel' threw an exception. FileNotFoundException: Could not load file or assembly 'microsoft.ml.Data,Version=1.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.' I have tried to train my model 2 times but gives me same exception.
解决方法
尝试从 NuGet 安装 Microsoft.Ml.Data
并以 x64 为目标;但是,如果它不起作用,您可能会考虑转向 .NET Core——Bill 和他的孩子们正在强迫每个人转向 .NET Core。