Skip to main content

An effective CNN for detecting NSFW content in images

Project description

NSFW-Detection-Pytorch

Description

In this repository you can find an effective CNN model for detecting NSFW content in images. It achieves a 97.70% accuracy on the pornography-2k dataset. Apart from the provided code you need to reproduce the model, you can also use this model as python module (see below).

Usage

First install the python module:

pip install --upgrade nsfwdetection

Then use the model by:

#import the model
from nsfwdetection.model import Model

# initialize the model
net = Model()

# make a prediction
output = net.predict(<imagepath>)

# make multiple predictions
output = net.predict([<imagepath>, <imagepath>])

The model's output is as follows: {'image_path': {'Label': SFW or NSFW , 'Score': 0 to 1 }}

Reproducability

Using the provided code you can retrain the model. Regarding the training/testing data, the corresponding splits are provided in folder "splits". You can find and download the necessary data from here (this is a private dataset, due to its content and you should send a request to gain access - find more info in the link) and here. After downloading the 2 datasets, you should run the

python script1_extract_image_frames.py

to extract the frames from the videos of the pornography-2k dataset and then you can run the

bash train_exps.sh 

to start training the model.

Results Visualisation

As you can see in the following attention maps, the model exhibits high accuracy in terms of the image regions it focuses. (Censored images)

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

NSFWDetection-1.0.2.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file NSFWDetection-1.0.2.tar.gz.

File metadata

  • Download URL: NSFWDetection-1.0.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.13.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

File hashes

Hashes for NSFWDetection-1.0.2.tar.gz
Algorithm Hash digest
SHA256 975d0a67a52313fe881fcb2c99b7369a44b8de9ba867b7c5a96b537321e8b6d7
MD5 cc984fc7cc9e5c30ce8eb2c6336a3d2c
BLAKE2b-256 c5ca1b994c934bb5e4d9faa6241f653153fc242097640f0627784966d6adc8b2

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