The Advanced Nudity Detection API is an A.I.-based service to determine the nudity content of images and videos. There are 15 nudity classes and 3 context classes that you can use to automatically understand the content of your images/videos, and set the appropriate rules.
Here are the 15 nudity classes starting with the most explicit ones:
Explicit classes | Sexual Activity | sexual_activity |
Sexual Display | sexual_display | |
Sextoy | sextoy | |
Erotica | erotica | |
Suggestive classes | Female underwear | lingerie |
Male underwear | male_underwear | |
Very revealing cleavage | cleavage_categories.very_revealing | |
Revealing cleavage | cleavage_categories.revealing | |
Very revealing male chest | male_chest_categories.very_revealing | |
Revealing male chest | male_chest_categories.revealing | |
Slightly revealing male chest | male_chest_categories.slightly_revealing | |
Bikini | bikini | |
Miniskirt | miniskirt | |
Other suggestive scene or pose | other | |
Safe | None | none |
Here are the 3 context classes that can be used to further refine your filtering:
Context classes | Sea, lake, pool | sea_lake_pool |
Other outdoor | outdoor_other | |
Other indoor | indoor_other |
Some moderation decisions need to be based on context. As an example, shirtless men or women in bikinis might be moderated differently if they are at the beach or in their bathroom.
To help you perform such fine-grained decisions, additional context information is available with the following classes:
The scores are returned in a way that puts the emphasis on the most explicit class corresponding to the image/video. As an example, the class sexual_display shouldn't be understood as "is there sexual display in the image?" but rather "is there sexual display AND no sexual activity in the image?".
As an illustration, an image of a woman in lingerie will score highly on the suggestive class. But if that woman is engaged in a sexual act, the API will focus on the most explicit class (sexual_activity) and return a very low score for the less explicit one (suggestive and suggestive.lingerie), because the image as a whole is explicit and should not be labelled as simply "suggestive" or "lingerie".
The Nudity Detection model works with Images, GIFs and Videos. Most types and formats of images or videos are supported.
If you haven't already, create an account to get your own API keys.
Let's say you want to moderate the following image:
You can either share a URL to the image, or upload the raw binary image.
Here's how to proceed if you choose to share the image URL:
curl -X GET -G 'https://api.sightengine.com/1.0/check.json' \
-d 'models=nudity-2.0' \
-d 'api_user={api_user}&api_secret={api_secret}' \
--data-urlencode 'url=https://sightengine.com/assets/img/examples/example-fac-1000.jpg'
# this example uses requests
import requests
import json
params = {
'url': 'https://sightengine.com/assets/img/examples/example-fac-1000.jpg',
'models': 'nudity-2.0',
'api_user': '{api_user}',
'api_secret': '{api_secret}'
}
r = requests.get('https://api.sightengine.com/1.0/check.json', params=params)
output = json.loads(r.text)
$params = array(
'url' => 'https://sightengine.com/assets/img/examples/example-fac-1000.jpg',
'models' => 'nudity-2.0',
'api_user' => '{api_user}',
'api_secret' => '{api_secret}',
);
// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check.json?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$output = json_decode($response, true);
// this example uses axios
const axios = require('axios');
axios.get('https://api.sightengine.com/1.0/check.json', {
params: {
'url': 'https://sightengine.com/assets/img/examples/example-fac-1000.jpg',
'models': 'nudity-2.0',
'api_user': '{api_user}',
'api_secret': '{api_secret}',
}
})
.then(function (response) {
// on success: handle response
console.log(response.data);
})
.catch(function (error) {
// handle error
if (error.response) console.log(error.response.data);
else console.log(error.message);
});
Here's how to proceed if you choose to upload the raw image:
curl -X POST 'https://api.sightengine.com/1.0/check.json' \
-F 'media=@/path/to/image.jpg' \
-F 'models=nudity-2.0' \
-F 'api_user={api_user}' \
-F 'api_secret={api_secret}'
# this example uses requests
import requests
import json
params = {
'models': 'nudity-2.0',
'api_user': '{api_user}',
'api_secret': '{api_secret}'
}
files = {'media': open('/path/to/image.jpg', 'rb')}
r = requests.post('https://api.sightengine.com/1.0/check.json', files=files, data=params)
output = json.loads(r.text)
$params = array(
'media' => new CurlFile('/path/to/image.jpg'),
'models' => 'nudity-2.0',
'api_user' => '{api_user}',
'api_secret' => '{api_secret}',
);
// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check.json');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
$output = json_decode($response, true);
// this example uses axios and form-data
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
data = new FormData();
data.append('media', fs.createReadStream('/path/to/image.jpg'));
data.append('models', 'nudity-2.0');
data.append('api_user', '{api_user}');
data.append('api_secret', '{api_secret}');
axios({
method: 'post',
url:'https://api.sightengine.com/1.0/check.json',
data: data,
headers: data.getHeaders()
})
.then(function (response) {
// on success: handle response
console.log(response.data);
})
.catch(function (error) {
// handle error
if (error.response) console.log(error.response.data);
else console.log(error.message);
});
The API will then return a JSON response with the following structure:
{
"status": "success",
"request": {
"id": "req_1SJJxJjUHnSVWreApx9fF",
"timestamp": 1693574119.571633,
"operations": 1
},
"nudity": {
"sexual_activity": 0.01,
"sexual_display": 0.01,
"erotica": 0.01,
"sextoy": 0.01,
"suggestive": 0.01,
"suggestive_classes": {
"bikini": 0.01,
"cleavage": 0.01,
"cleavage_categories": {
"very_revealing": 0.01,
"revealing": 0.01,
"none": 0.99
},
"lingerie": 0.01,
"male_chest": 0.01,
"male_chest_categories": {
"very_revealing": 0.01,
"revealing": 0.01,
"slightly_revealing": 0.01,
"none": 0.99
},
"male_underwear": 0.01,
"miniskirt": 0.01,
"other": 0.01
},
"none": 0.99,
"context": {
"sea_lake_pool": 0.01,
"outdoor_other": 0.99,
"indoor_other": 0.01
}
},
"media": {
"id": "med_1SJJEFuLqeSedThQjhNoS",
"uri": "https://sightengine.com/assets/img/examples/example-fac-1000.jpg"
}
}
You can use the classes under the nudity object to determine the nudity level of the image. In the above example the winning class is nudity.none with a confidence of 0.99, meaning that the API is very confident in its classification.
See our full list of Image/Video models for details on other filters and checks you can run on your images and videos. You might also want to check our Text models to moderate text-based content: messages, reviews, comments, usernames...
Was this page helpful?