ML.Net sentimental analysis prediction of comments not working in ASP.NET MVC web application

我怕爱的太早我们不能终老 提交于 2021-01-29 02:43:34

问题


I am trying to make project in .NET framework in which the controller code is as below:

[HttpGet]
public ActionResult Analysis()
{
    return View();
}

[HttpPost]
public ActionResult Analysis(ModelInput input)
{
    // Load the model  
    MLContext mlContext = new MLContext();
    ITransformer mlModel = mlContext.Model.Load(@"C:\Users\samya\source\repos\riya123\riya123ML.Model\MLModel.zip", out var modelInputSchema);

    // Create prediction engine related to the loaded train model
    var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);

    // Input  
    input.Year = DateTime.Now.Year;

    // Try model on sample data and find the score
    ModelOutput result = predEngine.Predict(input);

    // Store result into ViewBag
    ViewBag.Result = result;

    return View();
}

And when I try to run it shows error as below although the dll is seen in the solution explorer:

Exception thrown: 'System.DllNotFoundException' in Microsoft.ML.CpuMath.dll

An exception of type 'System.DllNotFoundException' occurred in Microsoft.ML.CpuMath.dll but was not handled in user code

Unable to load DLL 'CpuMathNative': The specified module could not be found. (Exception from HRESULT: 0x8007007E)


回答1:


There is a bug with the v1.4.0 version of ML.NET that breaks projects using packages.config. See:

  • https://github.com/dotnet/machinelearning/pull/4465
  • https://github.com/dotnet/machinelearning/issues/93#issuecomment-552486679
  • https://github.com/dotnet/machinelearning/issues/4483

To workaround this, try one of the following possible workarounds:

  1. Use PackageReference instead of packages.config.
  2. Fallback to v1.3.1 of ML.NET until a new version comes out with the fix.
  3. Alternatively, you can copy the CpuMathNative.dll from the nuget package into your output folder. You can do this manually, or with a change to your .csproj like the following:
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x64\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x64'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
    <Content Include="..\packages\Microsoft.ML.CpuMath.1.4.0\runtimes\win-x86\nativeassets\netstandard2.0\*.dll" Condition="'$(PlatformTarget)' == 'x86'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <Visible>false</Visible>
      <Link>%(Filename)%(Extension)</Link>
    </Content>
  </ItemGroup>

(NOTE: if your packages folder is somewhere other than ..\packages, you will need to adjust the path above.)

Also note one more thing: You can't use AnyCPU with ML.NET on .NET Framework. Since ML.NET uses native assemblies, you need to pick either x86 or x64 explicitly.



来源:https://stackoverflow.com/questions/58890426/ml-net-sentimental-analysis-prediction-of-comments-not-working-in-asp-net-mvc-we

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!