Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image classification fails on M1 chip Macs #9

Open
justinphamnz opened this issue Jul 28, 2022 · 9 comments
Open

Image classification fails on M1 chip Macs #9

justinphamnz opened this issue Jul 28, 2022 · 9 comments

Comments

@justinphamnz
Copy link

Thanks for a great work. I just tried to add this package to my test C# API and failed to run it on MacOS Monterey.

After successfully adding to our project, when the code hit NSFW Spy, it exits immediately without any error. Any tips would be appreciated.

  • Installed SciSharp.TensorFlow.Redist
  • Injected dependency
  • Environment:
    .NET SDK
    Version: 6.0.105
    Commit: 1c35735293

Runtime Environment:
OS Name: Mac OS X
OS Version: 12.4
OS Platform: Darwin
RID: osx.12-x64
Base Path: /usr/local/share/dotnet/x64/sdk/6.0.105/

Host (useful for support):
Version: 6.0.5
Commit: 70ae3df4a6

.NET SDKs installed:
3.1.419 [/usr/local/share/dotnet/x64/sdk]
5.0.408 [/usr/local/share/dotnet/x64/sdk]
6.0.105 [/usr/local/share/dotnet/x64/sdk]

@d00ML0rDz
Copy link
Collaborator

Hi @justinphamnz,

Thanks for the issue report.

Is it possible for you to post the code extract of how you're using NsfwSpy please? I've just tried using NsfwSpy on a Mac as part of a console application just now and it worked OK classifying a web image.

Can you also confirm you are using version 2.3.1 of SciSharp.TensorFlow.Redist?

Cheers 😊

@justinphamnz
Copy link
Author

Hi @d00ML0rDz,

Thanks for looking into the issue. Here is the basic Console App that I tried to implement https://github.com/justinphamnz/Console-NSFW

I think the issue could be with Apple M1 chip, not so sure if you or anyone has experienced this before.

I can confirm that I installed SciSharp.TensorFlow.Redist 2.3.1.

Have a great day.

@d00ML0rDz
Copy link
Collaborator

d00ML0rDz commented Jul 30, 2022

Hi @justinphamnz,

That code extract all looks OK and I would expect that to work. The Apple M1 chip may be the issue here although as far as I'm aware ML.NET does support Apple's silicon and has done since 1.6.0. It's possible one of the dependencies we are using isn't playing ball.

Would you be happy to wrap the code extract you sent me in a try catch block like this and see if it writes out an error message please?

try
{
    Console.WriteLine("Started");
    var uri = new Uri("https://raw.githubusercontent.com/d00ML0rDz/NsfwSpy/main/NsfwSpy.Test/Assets/flower.jpg");
    var nsfwSpy = new NsfwSpy();
    var result = nsfwSpy.ClassifyImage(uri);
    Console.WriteLine(result.Pornography);
    Console.WriteLine("Completed. Press any key to exit");
    Console.ReadKey();
}
catch (Exception ex)
{
    Console.Write($"{ex.Message} | {ex.InnerException}");
}

I unfortunately don't have access to an M1 Mac myself so testing this will be a challenge, but I can confirm the code extract does run fine on an Intel based Mac Mini.

Cheers

@justinphamnz
Copy link
Author

justinphamnz commented Jul 30, 2022

Thanks @d00ML0rDz,

I did wrap the try-catch and seems there is no catch hit using Visual Studio Code. I then installed Visual Studio 2022 for Mac, and was able to catch the Inner Exception

Message "Unable to load shared library 'tensorflow' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libtensorflow, 0x0001): tried: 'libtensorflow' (no such file), '/usr/local/lib/libtensorflow' (no such file), '/usr/lib/libtensorflow' (no such file), '/Users/justinpham/MacMini/ConsoleNSFW/ConsoleNSFW/ConsoleNSFW/bin/Debug/net6.0/libtensorflow' (no such file)"

@d00ML0rDz
Copy link
Collaborator

I've just found this StackOverflow thread that seems to describe your issue, however it sounds like the solution was to use .NET 5 and I can see you're already using .NET 6 so suspect that won't work.

I also found this GitHub comment which makes me wonder if including the SciSharp.TensorFlow.Redist GPU packages for Windows and Linux by default is interfering in some way.

You could try cloning the NsfwSpy repo and in the NsfwSpy project removing the following package references:

<PackageReference Include="SciSharp.TensorFlow.Redist-Linux-GPU" Version="2.3.1" />
<PackageReference Include="SciSharp.TensorFlow.Redist-Windows-GPU" Version="2.3.1" />

and replacing them with:

<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.1" />

You should then be able to add a new console application to the solution that references that modified version of NsfwSpy and see if your code extract now runs correctly. If that does work, I can work out a solution, maybe two separate Nuget packages, one for GPU and one for CPU.

Sorry this isn't a quick fix!

@justinphamnz
Copy link
Author

Thanks @d00ML0rDz. That's super helpful.
Yeah, I found the thread on StackOverflow but as you said, should resolved by .NET 6. Let me try clone and see if it works then let you know.

Really appreciate your prompt response.

Looking forward to contributing to this wonderful project.

@d00ML0rDz
Copy link
Collaborator

@justinphamnz just done some more research and found this Reddit post where the author said they had some luck using the Microsoft.ML.TensorFlow.Redist nuget package instead of SciSharp.TensorFlow.Redist with their M1 Mac. From my tests that didn't work on my Windows or Intel based Mac though.

In the comments of that post someone also commented this document saying that TensorFlow isn't supported on M1 Macs yet when using ML.NET, so that might be why it's currently not working 😕

Would love for you to help on the project if you're able to find a way to get it working though!

@d00ML0rDz d00ML0rDz changed the title Program exit when using this library on MacOS Monterey Image classification fails on M1 chip Macs Aug 12, 2022
@Halfooda
Copy link

Hi
I also have issues on arm64 (RPI 4B 4GB), does the lib work with ASP.NET 6.0 inside of Docker on an arm64 machine?

Keep up the amazing work!
Adam Koprek

@d00ML0rDz
Copy link
Collaborator

@Halfooda We have a page on our wiki that mentions CPUs must support AVX for this library, which from a quick google, sounds like the Raspberry Pi doesn't 😕

Don't think it will be possible to get this running unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants