SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.17k stars 506 forks source link

[BUG Report]: RuntimeError: Tensorflow.NET cannot find a backend. #1183

Open nikescar1 opened 9 months ago

nikescar1 commented 9 months ago

Description

I make a fresh project, install the packages, run the example code, and get the following error.

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Tensorflow.Binding' threw an exception. Source=Tensorflow.Binding StackTrace: at Tensorflow.Binding.get_tf() at Tensorflow.NumPy.AutoNumPyAttribute.OnEntry(MethodExecutionArgs args) at Tensorflow.NumPy.np.array[T](T[] data) at TensorFlowTesting.Program.Main(String[] args) in C:\Users\nikes\Documents\source\repos\TensorFlowTesting\Program.cs:line 23

This exception was originally thrown at this call stack: Tensorflow.tensorflow.tensorflow() Tensorflow.Binding.Binding()

Inner Exception 1: RuntimeError: Tensorflow.NET cannot find a backend. Please install one of the following packages for your program: SciSharp.TensorFlow.Redist, SciSharp.TensorFlow.Redist-Linux-GPU, SciSharp.TensorFlow.Redist-Windows-GPU. For more details, please visit https://github.com/SciSharp/TensorFlow.NET. If it still not work after installing the backend, please submit an issue to https://github.com/SciSharp/TensorFlow.NET/issues

If any other info is needed I'd be glad to provide it.

Reproduction Steps

I installed packages like so: Install-Package TensorFlow.NET Install-Package TensorFlow.Keras Install-Package SciSharp.TensorFlow.Redist

When I run the example code I get the above error.

Known Workarounds

No response

Configuration and Other Information

AsakusaRinne commented 8 months ago

Many apologizes for seeing this late. I'm too busy these days to watch all the issues. This is a known problem that .NET Framework does not have good support for backend package. There're generally two ways to solve it:

  1. Upgrade your runtime version (net core is recommended).
  2. Find the nuget package under the folder C:\users\xxx\.nuget\packages and then extract the tensorflow.dll from it. Finally put the dll in the output directory of your project (or add an reference).
OwenSSH commented 6 months ago

This can also be caused by missing visual c++ redist https://aka.ms/vs/17/release/vc_redist.x64.exe

jaroslav-hook commented 6 months ago

none of the proposed works in my case

Folasayo-Samuel commented 1 month ago

Facing same issude right now. @AsakusaRinne

nihao-git commented 1 month ago

Hello, the dll file cannot be referenced, VS pop-up error 1716818981238 @ @AsakusaRinne

Folasayo-Samuel commented 1 week ago

To resolve the issue with macOS:

CPU version for MacOS

PM> Install-Package SciSharp.TensorFlow.Redist-OSX

CPU version for Windows and Linux

PM> Install-Package SciSharp.TensorFlow.Redist

GPU version for Windows (CUDA and cuDNN are required)

PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU

GPU version for Linux (CUDA and cuDNN are required)

PM> Install-Package SciSharp.TensorFlow.Redist-Linux-GPU