Nabeel Ali
Nabeel Ali

Reputation: 74

Exception in Ml.net in image classification

It is autogenerated code from ml.net, I have only implement the open file dialog code which is on button 1. Here is the code of image detection in windows form application. two buttons and one picture box here. button 1 for browsing image and button 2 for detecting image.

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

when I am clicking on button 2 to detect the image it gives me this exception 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.

Upvotes: 0

Views: 468

Answers (1)

Dylan Karimagoko
Dylan Karimagoko

Reputation: 121

Try installing Microsoft.Ml.Data from NuGet and target x64; but, if it doesn't work, you might consider moving to .NET Core – Bill and his boys are forcing everyone to .NET Core.

Upvotes: 1

Related Questions