Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this a bug, or is Microsoft ML incompatible with Windows Forms #733

Open
FranzBl opened this issue Oct 31, 2019 · 11 comments
Open

Is this a bug, or is Microsoft ML incompatible with Windows Forms #733

FranzBl opened this issue Oct 31, 2019 · 11 comments

Comments

@FranzBl
Copy link

@FranzBl FranzBl commented Oct 31, 2019

Hello,

trying to integrate machine learnig into a Windows Forms app (even a very simple one that may only predict next value) is not successful. As soon as the ML modules are invoked, an error is thrown:

image

Details of the error message:

System.DllNotFoundException
HResult=0x80131524
Nachricht = Die DLL "CpuMathNative": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
Quelle =
Stapelüberwachung:
<Die Ausnahmestapelüberwachung kann nicht ausgewertet werden.>

Obviously, a DLL named CpuMathNative is missing. Does it belong to original Windows code or to .NET Framework (Version???)
Error message 0x8007007E of course has a little strong flavour :-( - Windows Update Error or damaged component store etc.
Therefore I did the usual process:

  1. Windows Update Error Processing - Windows can't identify the error
  2. All known updates for the moment are successfully installed
  3. sfc /scannow and the well known DISM procedure without errors...

Can anybody help? Is there an incompatibility between Microsoft ML and .NET framework (GUI)? For first test, I implemented ML using the model generator within VS.
The test program only tries to predict a new value for the trained model. Here's the code of the ConsumeModel class:

// This file was auto-generated by ML.NET Model Builder.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ML;
using ModelTrainerML.Model;

namespace ModelTrainerML.Model
{
public class ConsumeModel
{
// For more info on consuming ML.NET models, visit https://aka.ms/model-builder-consume
// Method for consuming model in your app
public static ModelOutput Predict(ModelInput input)
{

        // Create new MLContext
        MLContext mlContext = new MLContext();

        // Load model & create prediction engine
        string modelPath = AppDomain.CurrentDomain.BaseDirectory + "MLModel.zip";
        ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema);
        var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);

        // Use model to make prediction on input data
        ModelOutput result = predEngine.Predict(input);
        return result;
    }
}

}

If I call the predict method from the ConsoleApp, everything works fine...

@FranzBl
Copy link
Author

@FranzBl FranzBl commented Oct 31, 2019

Update: Debugging more deeply: The error occurs in the line within ConsumeModel class:

        ModelOutput result = predEngine.Predict(input);
@FranzBl
Copy link
Author

@FranzBl FranzBl commented Oct 31, 2019

I found a similar issue in Microsoft.ML NuGet package doesn't work with packages.config #93. Following this thread, I had a look at the packaging.config file. There I found that all included packages use .NET Framework 4.6.1 as target. On my computer version 4.8.3752.0 is installed. Could this be the reason? Should I change the target framework to the actual version?

@CESARDELATORRE
Copy link
Contributor

@CESARDELATORRE CESARDELATORRE commented Nov 1, 2019

It is compatible, you just need to select/run on x64.
Error when running the explainability WinForms app from Visual Studio F5
If you get the following exception:
DllNotFoundException: Unable to load DLL 'CpuMathNative': The specified module could not be found.
Cause: ML.NET for this particular math operation only supports x64, and VS is attempting to use AnyCPU.
Solution: Make sure you are running the app as x64 in VS, as shown in the following screenshot:

image

If you migrate the WinForms app to .NET Core 3.0, you won't have this issue. :)

@CESARDELATORRE
Copy link
Contributor

@CESARDELATORRE CESARDELATORRE commented Nov 1, 2019

Feel free to close this issue if working for you, ok? 👍

@FranzBl
Copy link
Author

@FranzBl FranzBl commented Nov 1, 2019

Sorry, but solution is not that simple. Please have a look at the screenshot I sent yesterday... :-(

image

Be sure I wouldn't bother you with such newbie's errors!

@CESARDELATORRE
Copy link
Contributor

@CESARDELATORRE CESARDELATORRE commented Nov 1, 2019

Aren’t the WinForms samples I mentioned above not working for you?

@FranzBl
Copy link
Author

@FranzBl FranzBl commented Nov 2, 2019

I will try, but it is unlikely that it is a programming error of mine. The error occurs in code produced automatically by Microsoft Visual Studio! In fact, I opened a minimal Forms window and added "Machine learning" from the VS menu. But I will try the examples. I think it depends upon the fact which ML Trainer is used etc.

@FranzBl
Copy link
Author

@FranzBl FranzBl commented Nov 3, 2019

The Taxi Fare example I tried out long ago, since it is part of the basic tutorials from Microsoft. Of course, it works. But it is a console application, not windows forms.
The Spike Detection example seems to be damaged in the GitHub repository because it is impossible to compile within Visual Studio. First of all this project doesn't allow to install nuget packages, for there is an "invalid version number" whose value is "". Additionally this project seems to be incompatible with .NET version 2.2 and higher since it forces to downgrade to .NET 2.1
I will not invest much work in this. Even if this sample compiles and works, that doesn't prove anything. Machine Learning is such a wide field with so many objects, methods, parameters, pre-trained models etc., i. e. so many boundary conditions that the fact that one program is running doesn't tell us anything about another program.

Summarizing once more my problem:

  1. I opened a new VS project with a windows forms app.
  2. I used ML.NET model builder tool to implement machine learning to the project (in fact I could implement the model builder myself, but it is a nice feature that the ML.NET model builder pre-trains given data and tries to detect which trainer would be the best). In my case the model builder selected Ols as a favourite. But I tried other trainers too, resulting in the same errors.
  3. Usually ML.NET model builder adds two new projects to the project folder: a console app (containing the model builder for additional training) and a second project that contains the class definitions for the dataview and a ConsumeModel method for predictions.
  4. If I enter the using directive to the Model project in the forms windows app, first of all the project can't compile without an explicit using Microsoft.ML directive in the Forms class. This is strange because this class doesn't call any methods from Microsoft.ML but only the ConsumeModel method where all necessary packages are referenced correctly.
  5. After adding Microsoft.ML to the package list of the forms app, the program builds without errors. But if I want to predict a new value using the ConsumeModel method, further packages are demanded during runtime. First the program dies because Microsoft.ML.Mkl.Components package is missing. If I install this, next run of the program dies because "CpuMathNative.dll" is missing, and this dll can't be found anywhere.
  6. If I call the ConsumeModel method via the console app instead of the windows forms, everything works fine,
  7. On the web there are suggestions that to resolve this one should install Microsoft Visual C++ Redistributable 2017. On my computer version 2015-2019 is installed, including 2017.
  8. My test program doesn't contain any handwritten code of mine but was completely built by Microsoft VS. So, even if the user program would be erraneous (I don't think it is), it would be a bug.
@IveJ
Copy link

@IveJ IveJ commented Nov 3, 2019

@CESARDELATORRE
Copy link
Contributor

@CESARDELATORRE CESARDELATORRE commented Nov 4, 2019

The Winforms samples using ML.NET at this repo work properly. You can see some screenshots below:

https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/end-to-end-apps/Model-Explainability

image

https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/end-to-end-apps/AnomalyDetection-Sales

image

If this issue is not related to the samples here but related to MODEL BUILDER, please, open an issue here:

https://github.com/dotnet/machinelearning-modelbuilder/issues

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.