Skip to main content

An ensemble of Neural Nets for Nudity Detection and Censoring

Project description

NudeNet: Neural Nets for Nudity Classification, Detection and selective censoring

This is a fork of the v2 branch of https://github.com/notAI-tech/NudeNet.

This fork exists since the original branch is no longer functional, as it relies upon downloading the classifier model from the github release page, which now requires the user to be logged in.

The emphasis of this fork is to maintain a simple working nudenet python package for easy use, primarily for classification purposes. I also removed the indecent images from the readme, as in my probably prude opinion they do not belong onto the page of a project that's about censoring it.

Classifier classes:

class name Description
safe Image/Video is not sexually explicit
unsafe Image/Video is sexually explicit

TODO: create corresponding docker images

As self-hostable API service

# Classifier
docker run -it -p8080:8080 notaitech/nudenet:classifier

# Detector
docker run -it -p8080:8080 notaitech/nudenet:detector

# See fastDeploy-file_client.py for running predictions via fastDeploy's REST endpoints 
wget https://raw.githubusercontent.com/notAI-tech/fastDeploy/master/cli/fastDeploy-file_client.py
# Single input
python fastDeploy-file_client.py --file PATH_TO_YOUR_IMAGE

# Client side batching
python fastDeploy-file_client.py --dir PATH_TO_FOLDER --ext jpg

Note: golang example https://github.com/notAI-tech/NudeNet/issues/63#issuecomment-729555360, thanks to Preetham Kamidi

As Python module

Installation:

pip install --upgrade nudenet

Classifier Usage:

# Import module
from nudenet import NudeClassifier

# initialize classifier (downloads the checkpoint file automatically the first time)
classifier = NudeClassifier()

# Classify single image
classifier.classify('path_to_image_1')
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}
# Classify multiple images (batch prediction)
# batch_size is optional; defaults to 4
classifier.classify(['path_to_image_1', 'path_to_image_2'], batch_size=BATCH_SIZE)
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY},
#          'path_to_image_2': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}

# Classify video
# batch_size is optional; defaults to 4
classifier.classify_video('path_to_video', batch_size=BATCH_SIZE)
# Returns {"metadata": {"fps": FPS, "video_length": TOTAL_N_FRAMES, "video_path": 'path_to_video'},
#          "preds": {frame_i: {'safe': PROBABILITY, 'unsafe': PROBABILITY}, ....}}

Thanks to Johnny Urosevic, NudeClassifier is also available in tflite.

TFLite Classifier Usage:

# Import module
from nudenet import NudeClassifierLite

# initialize classifier (downloads the checkpoint file automatically the first time)
classifier_lite = NudeClassifierLite()

# Classify single image
classifier_lite.classify('path_to_image_1')
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}
# Classify multiple images (batch prediction)
# batch_size is optional; defaults to 4
classifier_lite.classify(['path_to_image_1', 'path_to_image_2'])
# Returns {'path_to_image_1': {'safe': PROBABILITY, 'unsafe': PROBABILITY},
#          'path_to_image_2': {'safe': PROBABILITY, 'unsafe': PROBABILITY}}

Using the tflite classifier from flutter: https://github.com/ndaysinaiK/nude-test

Detector Usage:

# Import module
from nudenet import NudeDetector

# initialize detector (downloads the checkpoint file automatically the first time)
detector = NudeDetector() # detector = NudeDetector('base') for the "base" version of detector.

# Detect single image
detector.detect('path_to_image')
# fast mode is ~3x faster compared to default mode with slightly lower accuracy.
detector.detect('path_to_image', mode='fast')
# Returns [{'box': LIST_OF_COORDINATES, 'score': PROBABILITY, 'label': LABEL}, ...]

# Detect video
# batch_size is optional; defaults to 2
# show_progress is optional; defaults to True
detector.detect_video('path_to_video', batch_size=BATCH_SIZE, show_progress=BOOLEAN)
# fast mode is ~3x faster compared to default mode with slightly lower accuracy.
detector.detect_video('path_to_video', batch_size=BATCH_SIZE, show_progress=BOOLEAN, mode='fast')
# Returns {"metadata": {"fps": FPS, "video_length": TOTAL_N_FRAMES, "video_path": 'path_to_video'},
#          "preds": {frame_i: {'box': LIST_OF_COORDINATES, 'score': PROBABILITY, 'label': LABEL}, ...], ....}}

Notes:

  • detect_video and classify_video first identify the "unique" frames in a video and run predictions on them for significant performance improvement.
  • V1 of NudeDetector (available in master branch of this repo) was trained on 12000 images labelled by the good folks at cti-community.
  • V2 (current version) of NudeDetector is trained on 160,000 entirely auto-labelled (using classification heat maps and various other hybrid techniques) images.
  • The entire data for the classifier is available at https://archive.org/details/NudeNet_classifier_dataset_v1
  • A part of the auto-labelled data (Images are from the classifier dataset above) used to train the base Detector is available at https://github.com/notAI-tech/NudeNet/releases/download/v0/DETECTOR_AUTO_GENERATED_DATA.zip

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

NudeNetv2-2.0.9.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

NudeNetv2-2.0.9-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file NudeNetv2-2.0.9.tar.gz.

File metadata

  • Download URL: NudeNetv2-2.0.9.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for NudeNetv2-2.0.9.tar.gz
Algorithm Hash digest
SHA256 624f5f3764fd58857e5a63529a3a8b33bf050dc4e63e73a8b4f425a53a53fced
MD5 868cee1558d3021947a6de269a031c85
BLAKE2b-256 1df81e5ba5cce387b00245742f2e2b06c00dc7e4367587c20cf20b0bd8a4cbc0

See more details on using hashes here.

File details

Details for the file NudeNetv2-2.0.9-py3-none-any.whl.

File metadata

  • Download URL: NudeNetv2-2.0.9-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for NudeNetv2-2.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 5b0c8b18d255698a1e7ecc0213ad4500974450e9b60336e6b7c4316ff1cdb02f
MD5 b42b3f383346ec59c3206ead748ecc1a
BLAKE2b-256 bbcc1a9bb63ac622903064a3b010fcfbd9580bb83d8aca387cb8cab18e1b5c89

See more details on using hashes here.

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