CLIP-based-NSFW-Detector : AI model that can detect inappropriate images

David Cochard
axinc-ai
Published in
3 min readNov 12, 2023

This is an introduction to「CLIP-based-NSFW-Detector」, a machine learning model that can be used with ailia SDK. You can easily use this model to create AI applications using ailia SDK as well as many other ready-to-use ailia MODELS.

Overview

CLIP-based-NSFW-Detector is an inappropriate image (aka. NSFW, or Not Safe For Work) detection model using CLIP features. The idea is to compute CLIP features for an input image, run a decision model on those features, and output the probability of the image to be inappropriate.

For more information on CLIP, please refer to the article below.

Training Dataset

The training data for CLIP-based-NSFW-Detector is not published as images, but as pre-computed CLIP features. Although the actual data for the inappropriate images is not included, additional re-training can be performed by computing the CLIP features for any image in the same way.

The amount of feature data for training is 334 MB. The categories are drawing (41 370 items), hentai (30 367 items), neutral (64 491 items), porn (70 681 items), and sexy (35 158 items).

Architecture

CLIP is applied to the input image to obtain a feature vector, and the classification model outputs the probability that the image is NSFW.

Architecture of CLIP -based-NFSW-Detector

CLIP features are contained in a 768-dimension vector for ViT-L/14, and a 512-dimension vector for Vit-B/32.

Source: https://openai.com/blog/clip/

The classification model has simple linear model architecture.

Usage

CLIP-based-NSFW-Detector can be used with ailia SDK with the following command.

$ python3 clip-based-nsfw-detector.py --input sexy.jpg

The output score is as follows.

### Estimating NSFW confidence ###
NSFW: 99.450

Applications

This kind of model can be useful for services that allow users to freely post images. For example, it can be used to determine if an image posted on a social networking service is inappropriate.

The image generation AI, StableDiffusion, also has a similar NSFW Detector, which contains a process to black-fill the generated image if it is an inappropriate image.

ax Inc. has developed ailia SDK, which enables cross-platform, GPU-based rapid inference.

ax Inc. provides a wide range of services from consulting and model creation, to the development of AI-based applications and SDKs. Feel free to contact us for any inquiry.

--

--

David Cochard
axinc-ai

Engineer with 10+ years in game engines & multiplayer backend development. Now focused on machine learning, computer vision, graphics and AR