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

As Python module

Installation:

pip install --upgrade NudeNetv2

Classifier Usage:

# Import module
from NudeNetv2 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 NudeNetv2 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.11.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

NudeNetv2-2.0.11-py2.py3-none-any.whl (21.2 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: NudeNetv2-2.0.11.tar.gz
  • Upload date:
  • Size: 10.6 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.11.tar.gz
Algorithm Hash digest
SHA256 32ac948f5c8f0cad2abc96ef9ffc9e985109e24be4160ac8c1d7cc83815c988f
MD5 126fde75bb4c8bf59e42449b282ea5cd
BLAKE2b-256 5933e3e57d30216e4c5c3c679ab9acefb9326b7859d1c87c2044c3392164b1a3

See more details on using hashes here.

File details

Details for the file NudeNetv2-2.0.11-py2.py3-none-any.whl.

File metadata

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

File hashes

Hashes for NudeNetv2-2.0.11-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 681a6859a8826f445d25d720c0dfd920be3ac0776897b5cd5dd5f993710f4483
MD5 0b2a978efce2e6aa4d587c931388f68a
BLAKE2b-256 0a918580d3c8983e381309139bd7bb562ade379280053d9838d8c681590700e7

See more details on using hashes here.

Supported by

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