无法加载DLL“tensorflow”或它的某一个依赖项(ML.NET)

qoefvg9y  于 2023-01-02  发布在  .NET
关注(0)|答案(9)|浏览(328)

我有一个.NET核心3应用程序的图像分类,使用微软的ML.NET框架。
在我的开发机器上,我可以运行代码,并且一切正常。
但是,当我将其部署到临时服务器时,在运行时收到以下错误:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
     System.DllNotFoundException: Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (0x8007007E)
     at Tensorflow.c_api.TF_NewGraph()
     at Tensorflow.Graph..ctor()
     at Microsoft.ML.Transforms.Dnn.DnnUtils.LoadTFSession(IExceptionContext ectx, Byte[] modelBytes, String modelFile)
...

我尝试过在部署期间将tensorflow.dll复制到bin文件夹;我试过构建为x64、x86或AnyCPU。我已经验证了SciSharp.TensorFlow.Redist和Microsoft.ML.Tensorflow.Redist NuGet包都包含在内。到目前为止没有任何效果。
你知道为什么它找不到DLL文件,或者我怎么才能让它工作吗?

fhg3lkii

fhg3lkii1#

已安装“SciSharp.TensorFlow.Redist”版本1.14.0,此问题现已解决。
我的软件包引用如下所示:

<PackageReference Include="Microsoft.ML" Version="1.4.0" />
<PackageReference Include="Microsoft.ML.ImageAnalytics" Version="1.4.0" />
<PackageReference Include="Microsoft.ML.Vision" Version="1.4.0" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="1.14.0" />
jv4diomz

jv4diomz2#

C#桌面应用程序中的tensorflow 神经网络在开发环境中运行正常,但在其他机器上运行失败。在客户端机器上安装Microsoft Visual C++ redistributable解决了这个问题

l7mqbcuq

l7mqbcuq3#

我已经找到了根本原因。

原因1:Microsoft.ML仅适用于x64
原因2:以下软件包的最新稳定版本(1.4.0)抛出错误。以下v1.3.1软件包工作正常。

  • 微软.ML版本1.3.1
  • 微软ML图像分析v1.3.1
  • 微软.ML.tensorflow v1.3.1
    原因3:ML.NET和tensorflow 仅在.NET CORE中工作正常,而在.NET Framework中不工作。

希望这对你也有效!编码快乐!

pkln4tw6

pkln4tw64#

我在ML库方面遇到了许多问题:
OQ中提到的特定错误。错误:Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (0x8007007E),确实是通过更新到最新的VC++ x64 Redistributable解决的。对我来说,链接是here
收到错误时:Unable to find an entry point named 'TF_StringEncodedSize' in DLL 'tensorflow'我需要将SciSharp.TensorFlow.Redist库从2.4.x降级到2.3.x。
当得到Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary错误时,我注意到安装Microsoft.ML.TensorFlow.Redist是一个错误,需要删除。

vsikbqxv

vsikbqxv5#

安装最新的VC_redist,然后它的工作!

a64a0gku

a64a0gku6#

安装vc_redist.x64.exe帮助我

5kgi1eie

5kgi1eie7#

如果你添加一个引用到Microsoft.ML.TensorFlow.Redist,这可能会有帮助。它为我解决了这个问题。

zxlwwiss

zxlwwiss8#

1.首先,确保你的硬件能够处理最新的软件技术,如CPU架构或主板兼容性。我遇到这个问题是因为我使用的是10多年的旧系统。
1.安装最新的兼容vc_redist_64x发行版。
1.安装用于安装x64系统的框架兼容性程序包的Windows更新。
当我做了以下所有的事情时,它对我很有效。

mum43rcc

mum43rcc9#

以防万一有人碰到这个问题。对我来说,绊脚石是一个旧的服务器,它不支持TensorFlow库工作所需的AVX/AVX 2 CPU功能。
下面是一个类似的问题:https://stackoverflow.com/a/62186328/2729784

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheckForAVXSupport
{
    internal class Program
    {
        public static bool HasAvxSupport()
        {
            try
            {
                return (GetEnabledXStateFeatures() & 4) != 0;
            }
            catch
            {
                return false;
            }
        }

        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern long GetEnabledXStateFeatures();

        static void Main(string[] args)
        {
            Console.WriteLine("AVX/AVX2 support: " + HasAvxSupport().ToString());
            Console.WriteLine("\nPress any key...");
            Console.ReadKey();
        }
    }
}

来源:https://stackoverflow.com/a/35096938/2729784

相关问题