Skip to main content

Stand-alone wrapper for Yahoo's OpenNSFW model using ONNX.

Project description


License: MIT PyPi CircleCI

A small library for intergrating yahoo/open_nsfw model directly into an application.

This library uses the ONNX Runtime to run inference against Open NSFW. The conversion from the original Caffe model provided by yahoo/open_nsfw was done as following:

  1. Convert from Caffe to Tensorflow using ethereon/caffe-tensorflow.
  2. Convert from Tensorflow to ONNX using onnx/tensorflow-onnx.

The image pre-processing routine was approximated and is implemented using Pillow.


  • ONNX Runtime 1.x
  • NumPy 1.x


$ pip install opennsfw-standalone



import sys

from opennsfw_standalone import OpenNSFWInferenceRunner

inference_runner = OpenNSFWInferenceRunner.load()

for image_filename in sys.argv[1:]:
    with open(image_filename, "rb") as fp:
        nsfw_score = inference_runner.infer(
        print(image_filename, nsfw_score)


$ python -m opennsfw_standalone myimage.jpeg mysecondimage.jpeg
myimage.jpg 0.9997739
mysecondimage.jpg 0.9984438


Although this repository is MIT licensed, the model itself is subject to the BSD 2-Clause license Yahoo provided.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

opennsfw_standalone-0.0.6-py3-none-any.whl (21.9 MB view hashes)

Uploaded Python 3

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