Stand-alone wrapper for Yahoo's OpenNSFW model using ONNX.
Project description
opennsfw-standalone
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:
- Convert from Caffe to Tensorflow using ethereon/caffe-tensorflow.
- Convert from Tensorflow to ONNX using onnx/tensorflow-onnx.
The image pre-processing routine was approximated and is implemented using Pillow.
Prerequisites
- ONNX Runtime 1.x
- NumPy 1.x
Installation
$ pip install opennsfw-standalone
Usage
Python
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(fp.read())
print(image_filename, nsfw_score)
CLI
$ python -m opennsfw_standalone myimage.jpeg mysecondimage.jpeg
myimage.jpg 0.9997739
mysecondimage.jpg 0.9984438
License
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 Distribution
opennsfw-standalone-0.0.5.tar.gz
(22.0 MB
view hashes)
Built Distribution
Close
Hashes for opennsfw-standalone-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbb99d367ae954b91c00fe620001178455cf98fa47858c09b7fba9d459d29f32 |
|
MD5 | 6751c8364f1a5e848665c752923e48c1 |
|
BLAKE2b-256 | 39f9a936ec3cb1b52ce110e7ad35912f7f1ecfa89f66d1cabaf1f521753a0eff |
Close
Hashes for opennsfw_standalone-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9599ef138279538681e1999d3b59b4f91505d7b5b7959f643bf22a6d53a61a2 |
|
MD5 | fe8f68f661c4f48fddf65cca0f707f7a |
|
BLAKE2b-256 | cca6b5dfcc89088b7f1d19ea95d14c27ac61afcf5b5991998de8571b5cee4c63 |