A Python package for analyzing images using Caffe and Yahoo's open_nsfw models.
Project description
python-nsfw
A Python package for analyzing images using Caffe and Yahoo's open_nsfw models.
Prerequisites
python-nsfw requires Python 3 and runs on Caffe-compatible systems.
Caffe
If you're using macOS and Homebrew, the easiest way to install Caffe is with Homebrew:
brew install caffe
Alternatively, you could use a Docker Linux image (e.g. debian:stretch-slim
) and install the necessary dependencies:
apt update && apt install caffe-cpu python3 python3-pip wget
Yahoo's open_nsfw Models
Yahoo's open_nsfw models may be downloaded directly from GitHub. These files can go anywhere on your system, but we'll use /opt/open_nsfw
.
mkdir -p /opt/open_nsfw
wget -q -O - https://github.com/yahoo/open_nsfw/archive/master.tar.gz | tar xz -C /opt/open_nsfw --strip 1
Installation
python-nsfw may be installed using pip:
pip3 install nsfw
Usage
from nsfw import classify
from PIL import Image
image = Image.open("/path/to/image.jpg")
sfw, nsfw = classify(image, "/opt/open_nsfw/nsfw_model/deploy.prototxt", "/opt/open_nsfw/nsfw_model/resnet_50_1by2_nsfw.caffemodel")
print("SFW Probability: {}".format(sfw))
print("NSFW Probability: {}".format(nsfw))
License
python-nsfw is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file nsfw-0.2.0.tar.gz
.
File metadata
- Download URL: nsfw-0.2.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50ee022f2bede186638b71f343036cf7a62fae1c4730adc3b8907872db599628 |
|
MD5 | edefbaeb8e5588eea127b193ebd7461d |
|
BLAKE2b-256 | d5ce80fd890bb8da45a1160ca0185d564e0000427795f3020249f73c6e727146 |