Nudity Detection Using Deep Learning
By: Aditya H
Tags: Pornography, Deep Learning, Data Science, Machine Learning, Convolutional Network

You know that it’s nudity when you see an image. Have you ever wondered whether your computer can detect nudity instead of you seeing the image?

Here let’s gets started.

Introduction:

According to a recent survey by Pew Research Center, nearly 95% of adolescents have access to the internet and almost half (45%) of them are constantly online . The internet provides great advantages, such as information sharing. Yet, it also introduces numerous problems dealing with accessing and sharing of explicit content, including sexting, cyberbullying, and child pornography . Prolific sharing, combined with the permanence of digitally captured nudity, is particularly problematic for minors. While the dissemination of child pornography is a crime punishable by law , such momentary mistakes could also cause physical harm and prolonged psychological problems for adolescents, including sexual predation, emotional trauma, cyberbullying, and even suicidal behaviors. It is estimated that about 15% of teens on Snapchat report having received sexually explicit photos. In addition, 4% of cellphone-owning teens, ages 12–25, report having sent sexually suggestive, nude, or nearly nude images of themselves to someone else via text messaging. Sexting behaviors make adolescents vulnerable to a number of offline risks, such as bullying and sexual predation . These types of teen sexting behaviors can be perpetuated by mobile technologies and by several direct messaging applications available on smartphone devices, such as Kik, Snapchat, and Instagram . Unfortunately, such activities often fall under the jurisdiction of child pornography laws. Child pornography is illegal, and the federal law states the following: “A picture of a naked child may constitute illegal child pornography if it is sufficiently sexually suggestive. Additionally, the age of consent for sexual activity in a given state is irrelevant; any depiction of a minor under 18 years of age engaging in sexually explicit conduct is illegal” . So, while sexting behaviors may seem innocent and exploratory to teens, in reality, they can have severe negative consequences. The one stop solution to this problem is a to train a Deep Learning model which can detect nudity and hence we can stay safe from pornography and other sensual content.

Building The Model

First of all to build the nudity detection model one should have learnt various deep learning techniques such as Deep Neural Network, Optimization, Convolution Neural Network etc. I have learnt all this and have implemented various techniques in various Deep learning problems. To train this model first I collected dataset online. My dataset contains two class of images, Nudity and Non-Nudity images. Then I cleaned my dataset(threw few images). After cleaning the dataset I started constructing my model. If you’re a reader who’s familiar with Convolution Neural Network, then you might know how much the training costs. Cost in the preceding context points to the amount of time it takes to train the model, amount of GPU, amount of Ram it needs and the amount of TPU it needs if required. To the novice reader, the above two lines just describes how humongous the deep learning task is! As we all now know that the training of the deep learning model costs a lot, I used a pre-trained model to train my model. I used VGG-16 pretrained model. To the novice readers, pre-trained model simply means that the model(VGG-16) has already have been trained on a huge image dataset like the ImageNet dataset. Pretrained models know how to extract features from the image(Curves, lines, edges, color, shape etc) and hence it makes our work easy by reducing the training cost. Using Adam optimizer the model converges around 0.9268. For testing I picked some random images from the internet both nude and non-nude images. Also in the testing phase one of my friends helped me to construct a test dataset in which the images were kind of confusing like the test dataset we constructed had a lot of semi-nude images which confuses the model. My model performed well on the test dataset and classified those images which were slightly exposed as Nude and other images as Non-nude/Safe.

Nudity

Safe image

Importing VGG-16 model, Extracting the features and Training the model

Training graph and Loss graph

Making Predictions

images are taken from Source: Google

Bam!! We have built our nudity detection model.

What’s happening behind the scenes?

Our model takes an image as an input and classifies whether it’s nude or non-nude by extracting the features of the image. If the model finds any exposed part or sensual content in the image then it’ll predict it as nudity. So basically this is a binary classification problem. I have used Convolution Neural Network to classify images. To novice readers, Basically CNN extracts the features of the image pixel by pixel. A typical CNN model is comprised of different computational layers some with learnable parameters, and some solely mathematical operations with different purposes. In the following, these layers and their functions are explained.

• Convolutional Layer: performs a set of randomly initialized 2D convolutions in order to increase the depth of the input image or the previous layer.

•Batch Normalization: speeds up the training process by normalizing channels of the input image or previous layer.

• Rectified Linear Unit (ReLU): performs thresholding on all channels of the input image or previous layer to add non-linearity.

• Max Pooling Layer: applies down-sizing on the input image or previous layer and generates an output of the decreased width and height but same depth.

• Fully Connected Layer (FC): multiplies all the values of the input image or previous layer by its weights.

• Sigmoid Layer: assigns the values in an FC layer to their corresponding probability values.

Conclusion

This model can detect nudity with high accuracy. It classifies nudity accurately, for instance it knows the difference between humans wearing short dresses and naked. Hence, it should be integrated to various platforms and social media sites to avoid illicit content and to ban Pornography.

Project can be found at : https://github.com/AdityaIyer2609/NudityDetection-Using-Deeplearning.git