Skip to main content

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.

PyPI Python

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

nsfw-0.2.0.tar.gz (3.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page