ML.Net情感分析预测的注释在ASP.NET MVC Web应用程序中不起作用 [英] ML.Net sentimental analysis prediction of comments not working in ASP.NET MVC web application

查看:43
本文介绍了ML.Net情感分析预测的注释在ASP.NET MVC Web应用程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在.NET框架中制作控制器代码如下的项目:

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

当我尝试运行该文件时,尽管在解决方案资源管理器中看到了dll,但仍显示如下错误:

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

抛出异常:Microsoft.ML.CpuMath.dll中的'System.DllNotFoundException'

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

Microsoft.ML.CpuMath.dll中发生了'System.DllNotFoundException'类型的异常,但未在用户代码中处理

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

无法加载DLL'CpuMathNative':找不到指定的模块.(来自HRESULT的异常:0x8007007E)

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

推荐答案

ML.NET的 v1.4.0 版本存在一个错误,该错误使用 packages.config破坏了项目.参见:

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

要解决此问题,请尝试以下可能的解决方法之一:

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

  1. 使用 PackageReference 代替packages.config.
  2. 回退到ML.NET的 v1.3.1 ,直到该修复程序发布新版本为止.
  3. 或者,您可以将 CpuMathNative.dll 从nuget包复制到输出文件夹中.您可以手动执行此操作,也可以对.csproj进行如下更改:
  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>

(注意:如果您的packages文件夹位于.. \ packages之外的其他位置,则需要调整上面的路径.)

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

还要注意一件事:在.NET Framework上,不能将 AnyCPU 与ML.NET一起使用.由于ML.NET使用本机程序集,因此您需要显式选择 x86 x64 .

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.

这篇关于ML.Net情感分析预测的注释在ASP.NET MVC Web应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆