GantMan / nsfw_model

Keras model of NSFW detector
Other
1.75k stars 273 forks source link

Unable to install nsfw-detector 1.1.1 on macOS ARM64 #121

Closed colindean closed 1 year ago

colindean commented 1 year ago

I'd like to install nsfw-detector on my Apple Silicon Mac. It appears to pull in tensorflow, which has no installation candidate for arm64 Macs as of 2.11.0.

I realize that this is more of a tensorflow packaging problem than nsfw-detector, but I think there's an acceptable workaround. See below.

Current behavior

I'm specifying the dependency in pyproject.toml for retrieval with Poetry:

[tool.poetry.dependencies]
# [others omitted]
nsfw-detector = "^1.1.1"

When I run poetry update to install it:

$ poetry update
Updating dependencies
Resolving dependencies... (90.4s)

Package operations: 14 installs, 0 updates, 0 removals

  • Installing tensorflow (2.11.0): Failed

  RuntimeError

  Unable to find installation candidates for tensorflow (2.11.0)

It's because nsfw-detector has a hard dependency on tensorflow:

$ poetry show --tree
…
nsfw-detector 1.1.1 NSFW Image Detection with Deep Learning
├── pillow *
├── tensorflow >=2.1.0
…

And tensorflow has no macos*arm64 packages listed in the files for 2.11.0.

Expected behavior

It'd be lovely for nsfw-detector to require tensorflow_macos automatically through markers in the requirements.txt that nsfw-detector uses.

tensorflow>=2.1.0;sys_platform != 'darwin'
tensorflow_macos>=2.5.0;sys_platform == 'darwin'
tensorflow-hub==0.7.0
pillow

Alternatively, I'd could specify an extra that will use tensorflow_macos instead of tensorflow.

[tool.poetry.dependencies]
# [others omitted]
nsfw-detector = { version = "^1.1.1", extras = ["macos"], markers = "sys_platform == 'darwin'" }
nsfw-detector = { version = "^1.1.1", markers = "sys_platform != 'darwin'" }

I'm unfamiliar with handling that in setup.py since the tensorflow dependency would have to be dropped from the REQUIRED section read from requirements.txt when the macos extra flag is requested. Maybe tensorflow could be added as a default extra? Not sure how best to proceed here.

System info

$ sw_vers
ProductName:        macOS
ProductVersion:     13.1
BuildVersion:       22C65
$ uname -m
arm64
$ python --version
Python 3.9.11
$ python -c 'import sys; import platform; import os; print(f"sys_platform: {sys.platform}\nplatform_machine: {platform.machine()}\nplatform_system: {platform.system()}\nos_name: {os.name}")'
sys_platform: darwin
platform_machine: arm64
platform_system: Darwin
os_name: posix
colindean commented 1 year ago

I was able to install successfully on my machine by altering the requirements.txt as suggested above and referencing my fork, e.g.

[tool.poetry.dependencies]
nsfw-detector = { git = "https://github.com/colindean/nsfw_model_macos.git", branch = "tensorflow_macos" }

I'll put up a PR for it.