[BUG Report]: Tensorflow.RuntimeError: Tensorflow.NET cannot find a backend despite having installed SciSharp.TensorFlow.Redist on macOS M1
mariuszmatusiak opened this issue ยท 5 comments
Description
I installed all the Tensorflow.NET components according to the documentation on my M1. I am working in Visual Studio Code.
Despite having installed all the required packages: SciSharp.TensorFlow.Redist, TensorFlow.Keras, TensorFlow.NET, and even Microsoft.ML.TensorFlow.Redist as mentioned in one of the similar threads (#252) I am still unable to get this work.
Part of my *.csproj file:
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
...
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.ML.TensorFlow.Redist" Version="0.14.0" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
<PackageReference Include="TensorFlow.Keras" Version="0.15.0" />
<PackageReference Include="TensorFlow.NET" Version="0.150.0" />
</ItemGroup>
Part of my *.xaml.cs file:
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Tensorflow;
using Tensorflow.NumPy;
...
var hello = tf.constant("yey!"); // <- AN EXCEPTION THROWN HERE
Console.WriteLine(hello);
Exception thrown: 'System.DllNotFoundException' in Tensorflow.Binding.dll
Exception thrown: 'Tensorflow.RuntimeError' in Tensorflow.Binding.dll
Reproduction Steps
- Create a new .NET MAUI project on macOS M1
- Install ML.NET:
dotnet tool install -g mlnet-osx-arm64 - Install TF.NET:
dotnet add package TensorFlow.NET - Install TF.Keras:
dotnet add package TensorFlow.Keras - Install SciSharp.TensorFlow.Redist:
dotnet add package SciSharp.TensorFlow.Redist - Install Microsoft.ML.TensorFlow.Redist:
dotnet add package Microsoft.ML.TensorFlow.Redist - Add
using static Tensorflow.Binding;and an example call in a project source file.
Known Workarounds
No response
Configuration and Other Information
TensorFlow.NET version=0.150.0
dotnet version=8.0.204
OS Name: Mac OS X
OS Version: 14.4
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.204/
.NET workloads installed:
[maui]
Installation Source: SDK 8.0.200
Manifest Version: 8.0.7/8.0.100
Manifest Path: /usr/local/share/dotnet/sdk-manifests/8.0.100/microsoft.net.sdk.maui/8.0.7/WorkloadManifest.json
Install Type: FileBased
.NET SDKs installed:
6.0.404 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
8.0.204 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
@Oceania2018 Does redist 2.16.0 include a MAC backend when publishing it?
The same issue with simple console app example:
class Program
{
static void Main(string[] args)
{
var hello = tf.constant("Hello, TensorFlow!");
Console.WriteLine(hello);
}
}
Installed packs:
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
<PackageReference Include="TensorFlow.NET" Version="0.150.0" />
Exception:
Tensorflow.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
MacOS, M2 Ultra.
I got the same problem as well
using System;
using static Tensorflow.Binding;
/// <summary>
/// Simple hello world using TensorFlow
/// </summary>
class Program
{
static void Main(string[] args)
{
var hello = tf.constant("Hello, TensorFlow!");
Console.WriteLine(hello);
}
}
Installed packs:
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.16.0" />
<PackageReference Include="TensorFlow.NET" Version="0.150.0" />
Exception:
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.
MacOS, M2 Ultra.
To resolve the issue in your macOS:
CPU version for MacOS
PM> Install-Package SciSharp.TensorFlow.Redist-OSX
This should resolve the issue.
@Lionberg @mariuszmatusiak @AsakusaRinne @agene0001 @henon
To resolve the issue in your macOS:
CPU version for MacOS
PM> Install-Package SciSharp.TensorFlow.Redist-OSX
This should resolve the issue. @Lionberg @mariuszmatusiak @AsakusaRinne @agene0001 @henon
@Folasayo-Samuel unfortunately it didn't helped me. I don't have PowerShell on Mac, so I ran
dotnet add package SciSharp.TensorFlow.Redist-OSX
inside my app folder. A package reference was added successfully in version 2.15.0, but when I debug the app it still throws the exception.
I checked the content of the package on https://nuget.info/packages/SciSharp.TensorFlow.Redist-OSX/2.15.0 and it contains binaries only inside the osx-x64 folder. There is no osx-arm64. I guess this might be the issue.