Unable to load DLL 'tensorflow' or one of its dependencies (ML.NET)

5

I have a .NET Core 3 app for image classification, using Microsoft's ML.NET framework.

On my development machine, I can run the code and it all works fine.

However, when I deploy it to my staging server, I get this error at runtime:

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)
...

I've tried copying tensorflow.dll into the bin folder during deployment; I've tried building as x64, x86, or AnyCPU. I've verified that the SciSharp.TensorFlow.Redist and Microsoft.ML.Tensorflow.Redist NuGet packages are included. Nothing so far has worked.

Any idea why it can't find the DLL file, or how I can get it to work?

c#
tensorflow
dll
asp.net-core-3.0
ml.net
asked on Stack Overflow Oct 24, 2019 by Kevin Owens

6 Answers

10

Installed "SciSharp.TensorFlow.Redist" version 1.14.0 and this issue is gone now.

My package references are exactly as follows:

<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" />
answered on Stack Overflow Jan 7, 2020 by VeteranLK
4

I've figured out the root cause.

Reason 1: Microsoft.ML works on x64 only

Reason 2: Latest stable version (1.4.0) of below packages is throwing error. Below v1.3.1 packages are working fine.

  • Microsoft.ML v1.3.1
  • Microsoft.ML.ImageAnalytics v1.3.1
  • Microsoft.ML.TensorFlow v1.3.1

Reason 3: ML.NET and Tensor flow works fine only in .NET CORE not in .NET framework.

Hope this works for you too ! Happy Coding !

answered on Stack Overflow Nov 10, 2019 by Vignesh Raja
4

Faced the same problem with a tensorflow neural network in a C# desktop application running ok in developement environment but failing in other machines. It was solved installing Microsoft Visual C++ redistributable in client machines

answered on Stack Overflow May 3, 2020 by Marcelo Esteves
2

I have experienced a number of problems with the ML libraries:

The particular one mentioned in the OQ. The error: Unable to load DLL 'tensorflow' or one of its dependencies: The specified module could not be found. (0x8007007E), was indeed resolved by updating to the latest VC++ x64 Redistributable. For me that link was here

When getting the error: Unable to find an entry point named 'TF_StringEncodedSize' in DLL 'tensorflow' I needed to downgrade the SciSharp.TensorFlow.Redist library from 2.4.x to 2.3.x.

When getting the Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary error, I noticed that installing the Microsoft.ML.TensorFlow.Redist was a mistake and needed to be removed.

answered on Stack Overflow Feb 16, 2021 by Carlo Bos
1

Install the LATEST VC_redist then it works!

answered on Stack Overflow Jul 31, 2020 by Zhang
1

Installing vc_redist.x64.exe helped me

answered on Stack Overflow Feb 8, 2021 by Ruslan Zagidullin

User contributions licensed under CC BY-SA 3.0