• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Amazon Rekognition for nudity detection, tagging and more

teejam

Chevereto Member
Hi all - thought I'd share my little project here in case it helps someone. I think v4 of Chevereto might have this (?), but in the meantime here's one way to do it.

Overview
Amazon Rekognition is a deep-learning algorithm that can detect objects in scenes, faces, and nudity. I'm using it for the latter, but you could easily modify this code to support auto tagging and more. At the moment new users get 5,000 image credits a month for free for the first year, then it's $1-ish per 1,000 after that.

Step 1: Sign up and sign into your AWS account
You can follow this guide, which I sort of sum up in the next four steps: https://docs.aws.amazon.com/rekognition/latest/dg/setting-up.html

Step 2: Create an Identity and Access Management (IAM) user
Info for that is also at the previous link.

Step 3: After creating the IAM user, grant them the AmazonRekognitionFullAccess permission
More info: https://docs.aws.amazon.com/rekognition/latest/dg/authentication-and-access-control.html

Step 4: Make a note of the key and secret, under the "Security credentials" tab for that user
Navigating AWS is the toughest part, but once you have the key and secret, and the proper permissions set up, you can continue.

Step 5: Download and install the AWS SDK for PHP (these guys are in love with acronyms)
https://aws.amazon.com/sdk-for-php/

Step 6: Copy route.json.php to overrides
Copy the /app/routes/route.json.php file to the overrides folder, e.g. /app/routes/overrides/route.json.php

Step 7: Edit the OVERRIDE version as follows (read comments and edit as necessary):
At the top of the script, right below the copyright disclaimer, add:

PHP:
require($_SERVER['DOCUMENT_ROOT'] . '/PATH_TO_REKOGNIZE/aws-autoloader.php');
use Aws\S3\S3Client;

(The above assumes you've downloaded the SDK zip from step 5 and placed it in a folder on your site. There are other ways to install it if you'd prefer, at the link in step 5.)

ABOVE the line of code $uploaded_id = CHV\Image::uploadToWebsite($source, $logged_user, $_REQUEST); add this:

PHP:
// If this user claims the image is SFW, let's double check
// You could remove this if you wanted to check all images, even ones marked as NSFW
// like if you wanted to fix user input errors or something
if($_REQUEST['nsfw'] == 0){
    
    // Is the file coming from a local source?
    if(isset($source['tmp_name'])){
        $img = file_get_contents($source['tmp_name']);
    }
    
    // ... or a remote source?
    else{
        $img = file_get_contents($source);
    }

    // Let's make sure that worked
    if($img !== false){
        
        // Fire up Rekognition
        $s3 = new \Aws\Rekognition\RekognitionClient([
            'version' => 'latest',
            
            // Modify the region depending on your AWS setup
            'region'  => 'us-west-2',
            
            // You don't have to hard-code these here, but that's the way I roll
            'credentials' => [
                'key'    => 'KEY_CODE_HERE',
                'secret' => 'SECRET_CODE_HERE'
            ]
        ]);
        
        // Here's where we check for nudity. You can also replace or add object detection (https://docs.aws.amazon.com/rekognition/latest/dg/labels-detect-labels-image.html)
        // and face detection (https://docs.aws.amazon.com/rekognition/latest/dg/faces-detect-images.html), etc.
        $result = $s3->DetectModerationLabels([
            'Image' => [ // REQUIRED
                'Bytes' => $img
            ]
        ]);
        
        // If the image has some level of tawdriness :)
        // I'm not worried about details/level of the confidence score, because I'm just looking for a yes or no if there's explicit nudity or not (see below)
        if(isset($result['ModerationLabels'][0]['Confidence'])){
            
            // Personally I'm just interested in marking nudity as NSFW, but it also detects things like bikinis, partial nudity, etc.
            if($result['ModerationLabels'][0]['Name'] == 'Explicit Nudity'){
                
                // Boobies or weenies found ... let's mark the sucker
                // Here's where you could add tags, etc. to be entered into the DB as well if you used detect labels
                $_REQUEST['nsfw'] = 1;
            }
        }
    }
}

Hope that's useful to someone! I'd recommend if you have a massive site though to keep an eye on the billing, because it could add up fast. :eek:
 
How expensive is this recognition thing?
I put a general rundown of it in the post, but their pricing is pretty specific to the user's needs: https://aws.amazon.com/rekognition/pricing/


Are you satisfied with the results?
How good is it to detect sexually provocative images?
I am so far, but I just started using it. You can demo it here but you need to sign up for a free AWS account: https://console.aws.amazon.com/rekognition/home

I'd look at Google's Vision API as well. I just went with Amazon because it's cheaper.
 
Wow. It costs $1 per 1000 images. To do this on my site, that'd be a pretty penny!

I also found this software a while ago. Which would be pretty cool to see it as a plugin on Chevereto one day. IT'd give it facial recognition. But, it requires python :/ https://github.com/ageitgey/face_recognition It's a full 100% free alternative.
 
Back
Top