부적절한 이미지 감지 - Amazon Rekognition

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

부적절한 이미지 감지

DetectModerationLabels작업을 사용하여 이미지에 부적절하거나 불쾌한 콘텐츠가 포함되어 있는지 확인할 수 있습니다. Amazon Rekognition의 조절 레이블 목록은 이미지 및 비디오 조절 API 사용을 참조하세요.

이미지에서 부적절한 콘텐츠 감지

이미지는 .jpg 또는 .png 형식이어야 합니다. 입력 이미지를 이미지 바이트 배열(base64 인코딩 이미지 바이트)로 제공하거나 Amazon S3 객체를 지정할 수 있습니다. 이 절차에서는 이미지(.jpg 또는 .png)를 S3 버킷에 업로드합니다.

이 절차를 실행하려면 AWS CLI 또는 적절한 AWS SDK가 설치되어 있어야 합니다. 자세한 정보는 Amazon Rekognition 시작을 참조하세요. 사용할 AWS 계정은 Amazon Rekognition API에 대한 액세스 권한을 가지고 있어야 합니다. 자세한 내용은 Amazon Rekognition에서 정의한 작업을 참조하세요.

이미지에서 조정 레이블(SDK)을 감지하려면
  1. 아직 설정하지 않았다면 다음과 같이 하세요.

    1. AmazonRekognitionFullAccess 권한과 AmazonS3ReadOnlyAccess 권한을 가진 사용자를 생성하거나 업데이트합니다. 자세한 정보는 1단계: AWS 계정 설정 및 사용자 생성을 참조하세요.

    2. 및 AWS SDK를 설치 AWS CLI 및 구성합니다. 자세한 정보는 2단계: AWS CLI 및 AWS SDK 설정을 참조하세요.

  2. S3 버킷에 이미지를 업로드합니다.

    이에 관한 지침은 Amazon Simple Storage Service 사용 설명서에서 Amazon S3에 객체 업로드를 참조하세요.

  3. 다음 예제를 사용하여 DetectModerationLabels 작업을 호출합니다.

    Java

    이 예제는 감지된 부적절한 콘텐츠의 레이블 이름, 신뢰도 수준 및 감지된 조절 레이블의 상위 레이블을 출력합니다.

    bucketphoto 값을 2단계에서 사용한 S3 버킷 이름과 이미지 파일 이름으로 바꿉니다.

    //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) package aws.example.rekognition.image; import com.amazonaws.services.rekognition.AmazonRekognition; import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder; import com.amazonaws.services.rekognition.model.AmazonRekognitionException; import com.amazonaws.services.rekognition.model.DetectModerationLabelsRequest; import com.amazonaws.services.rekognition.model.DetectModerationLabelsResult; import com.amazonaws.services.rekognition.model.Image; import com.amazonaws.services.rekognition.model.ModerationLabel; import com.amazonaws.services.rekognition.model.S3Object; import java.util.List; public class DetectModerationLabels { public static void main(String[] args) throws Exception { String photo = "input.jpg"; String bucket = "bucket"; AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient(); DetectModerationLabelsRequest request = new DetectModerationLabelsRequest() .withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket))) .withMinConfidence(60F); try { DetectModerationLabelsResult result = rekognitionClient.detectModerationLabels(request); List<ModerationLabel> labels = result.getModerationLabels(); System.out.println("Detected labels for " + photo); for (ModerationLabel label : labels) { System.out.println("Label: " + label.getName() + "\n Confidence: " + label.getConfidence().toString() + "%" + "\n Parent:" + label.getParentName()); } } catch (AmazonRekognitionException e) { e.printStackTrace(); } } }
    Java V2

    이 코드는 AWS 문서 SDK 예제 GitHub 저장소에서 가져왔습니다. 전체 예제는 여기에서 확인하세요.

    //snippet-start:[rekognition.java2.recognize_video_text.import] //snippet-start:[rekognition.java2.detect_mod_labels.import] import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import software.amazon.awssdk.services.rekognition.model.Image; import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsRequest; import software.amazon.awssdk.services.rekognition.model.DetectModerationLabelsResponse; import software.amazon.awssdk.services.rekognition.model.ModerationLabel; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.List; //snippet-end:[rekognition.java2.detect_mod_labels.import] /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ModerateLabels { public static void main(String[] args) { final String usage = "\n" + "Usage: " + " <sourceImage>\n\n" + "Where:\n" + " sourceImage - The path to the image (for example, C:\\AWS\\pic1.png). \n\n"; if (args.length < 1) { System.out.println(usage); System.exit(1); } String sourceImage = args[0]; Region region = Region.US_WEST_2; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create("profile-name")) .build(); detectModLabels(rekClient, sourceImage); rekClient.close(); } // snippet-start:[rekognition.java2.detect_mod_labels.main] public static void detectModLabels(RekognitionClient rekClient, String sourceImage) { try { InputStream sourceStream = new FileInputStream(sourceImage); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); Image souImage = Image.builder() .bytes(sourceBytes) .build(); DetectModerationLabelsRequest moderationLabelsRequest = DetectModerationLabelsRequest.builder() .image(souImage) .minConfidence(60F) .build(); DetectModerationLabelsResponse moderationLabelsResponse = rekClient.detectModerationLabels(moderationLabelsRequest); List<ModerationLabel> labels = moderationLabelsResponse.moderationLabels(); System.out.println("Detected labels for image"); for (ModerationLabel label : labels) { System.out.println("Label: " + label.name() + "\n Confidence: " + label.confidence().toString() + "%" + "\n Parent:" + label.parentName()); } } catch (RekognitionException | FileNotFoundException e) { e.printStackTrace(); System.exit(1); } } // snippet-end:[rekognition.java2.detect_mod_labels.main]
    AWS CLI

    이 AWS CLI 명령은 detect-moderation-labels CLI 작업에 대한 JSON 출력을 표시합니다.

    bucketinput.jpg을 2단계에서 사용한 S3 버킷 이름과 이미지 파일 이름으로 바꿉니다. profile_name의 값을 개발자 프로필 이름으로 대체하세요. 어댑터를 사용하려면 프로젝트 버전의 ARN을 project-version 파라미터에 제공하세요.

    aws rekognition detect-moderation-labels --image "{S3Object:{Bucket:<bucket-name>,Name:<image-name>}}" \ --profile profile-name \ --project-version "ARN"

    Windows 디바이스에서 CLI에 액세스하는 경우 작은따옴표 대신 큰따옴표를 사용하고 내부 큰따옴표는 백슬래시(즉 \)로 이스케이프 처리하여 발생할 수 있는 구문 분석 오류를 해결합니다. 예를 들어 다음을 참조하세요.

    aws rekognition detect-moderation-labels --image "{\"S3Object\":{\"Bucket\":\"bucket-name\",\"Name\":\"image-name\"}}" \ --profile profile-name
    Python

    이 예제는 감지된 부적절하거나 불쾌감을 주는 콘텐츠의 레이블 이름, 신뢰도 수준 및 감지된 부적절한 콘텐츠 레이블의 상위 레이블을 출력합니다.

    main 함수에서, bucketphoto 값을 2단계에서 사용한 S3 버킷과 이미지의 이름으로 바꿉니다. Rekognition 세션을 생성하는 라인에서 profile_name의 값을 개발자 프로필의 이름으로 대체합니다.

    #Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. #PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) import boto3 def moderate_image(photo, bucket): session = boto3.Session(profile_name='profile-name') client = session.client('rekognition') response = client.detect_moderation_labels(Image={'S3Object':{'Bucket':bucket,'Name':photo}}) print('Detected labels for ' + photo) for label in response['ModerationLabels']: print (label['Name'] + ' : ' + str(label['Confidence'])) print (label['ParentName']) return len(response['ModerationLabels']) def main(): photo='image-name' bucket='bucket-name' label_count=moderate_image(photo, bucket) print("Labels detected: " + str(label_count)) if __name__ == "__main__": main()
    .NET

    이 예제는 감지된 부적절하거나 불쾌감을 주는 콘텐츠의 레이블 이름, 신뢰도 수준 및 감지된 조절 레이블의 상위 레이블을 출력합니다.

    bucketphoto 값을 2단계에서 사용한 S3 버킷 이름과 이미지 파일 이름으로 바꿉니다.

    //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.) using System; using Amazon.Rekognition; using Amazon.Rekognition.Model; public class DetectModerationLabels { public static void Example() { String photo = "input.jpg"; String bucket = "bucket"; AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient(); DetectModerationLabelsRequest detectModerationLabelsRequest = new DetectModerationLabelsRequest() { Image = new Image() { S3Object = new S3Object() { Name = photo, Bucket = bucket }, }, MinConfidence = 60F }; try { DetectModerationLabelsResponse detectModerationLabelsResponse = rekognitionClient.DetectModerationLabels(detectModerationLabelsRequest); Console.WriteLine("Detected labels for " + photo); foreach (ModerationLabel label in detectModerationLabelsResponse.ModerationLabels) Console.WriteLine("Label: {0}\n Confidence: {1}\n Parent: {2}", label.Name, label.Confidence, label.ParentName); } catch (Exception e) { Console.WriteLine(e.Message); } } }

DetectModerationLabels 작업 요청

DetectModerationLabels에 대한 입력은 이미지입니다. 이 예제 JSON 입력에서는 Amazon S3 버킷에서 소스 이미지를 불러옵니다. MinConfidence는 Amazon Rekognition Image가 응답에 반환하기 위해 충족해야 할 감지된 레이블의 최소 정확성 신뢰도 수준입니다.

{ "Image": { "S3Object": { "Bucket": "bucket", "Name": "input.jpg" } }, "MinConfidence": 60 }

DetectModerationLabels 운영 응답

DetectModerationLabels가 S3 버킷의 입력 이미지를 감지하거나, 이미지를 이미지 바이트로 직접 제공할 수 있습니다. 다음 예제는 DetectModerationLabels 호출로부터의 응답입니다.

다음 JSON 응답 예제에서 다음에 유의하십시오.

  • 부적절한 이미지 감지 정보 - 이 예제에서는 이미지에서 발견된 부적절하거나 불쾌감을 주는 콘텐츠의 레이블 목록을 보여줍니다. 이 목록에는 이미지에서 감지되는 최상위 레이블과 각각의 2수준 레이블이 포함됩니다.

    레이블 – 각 레이블에는 이름, 해당 레이블이 정확한지에 대한 Amazon Rekognition의 신뢰도 추정, 상위 레이블의 이름이 있습니다. 최상위 레이블의 상위 이름은 ""입니다.

    레이블 신뢰도 – 각 레이블에는 레이블이 올바른지에 대해 Amazon Rekognition이 가지고 있는 백분율 신뢰도를 나타내는 0에서 100 사이의 신뢰도 값이 있습니다. API 작업 요청에서 응답으로 반환될 레이블에 필요한 신뢰도 수준을 지정합니다.

{ "ModerationLabels": [ { "Confidence": 99.44782257080078, "Name": "Smoking", "ParentName": "Drugs & Tobacco Paraphernalia & Use", "TaxonomyLevel": 3 }, { "Confidence": 99.44782257080078, "Name": "Drugs & Tobacco Paraphernalia & Use", "ParentName": "Drugs & Tobacco", "TaxonomyLevel": 2 }, { "Confidence": 99.44782257080078, "Name": "Drugs & Tobacco", "ParentName": "", "TaxonomyLevel": 1 } ], "ModerationModelVersion": "7.0", "ContentTypes": [ { "Confidence": 99.9999008178711, "Name": "Illustrated" } ] }

콘텐츠 조정 버전 7 테스트 및 API 응답 변환

Amazon Rekognition은 콘텐츠 조정 레이블 감지 기능에 대한 기계 학습 모델을 버전 6.1에서 7로 업데이트했습니다. 이 업데이트는 전반적인 정확도를 향상시키고 다른 카테고리를 수정함과 함께 몇 가지 새로운 카테고리를 도입했습니다.

현재 버전 6.1을 사용하는 경우 다음 조치를 취하여 버전 7로 원활하게 전환하는 것이 좋습니다.

  1. 다음 중 하나를 사용합니다.

    • AWS 프라이빗 SDK (참조AWS 콘텐츠 조정 버전 7용 SDK 및 사용 가이드 ) 를 다운로드하여 사용하여 StartMediaAnalysisJob API를 DetectModerationLabels 호출하십시오.

    • Amazon Rekognition 대량 분석 콘솔 또는 데모 콘솔에 이미지를 업로드하여 버전 7을 테스트하십시오.

  2. API 응답 또는 콘솔에 반환된 레이블 및 신뢰도 점수의 업데이트된 목록을 검토하십시오. 필요한 경우 애플리케이션 사후 처리 로직을 적절히 조정하십시오.

  3. 계정은 2024년 3월 4일까지 버전 6.1을 유지합니다. 2024년 3월 4일 이후에 버전 6.1을 사용하려면 2024년 3월 1일까지 AWS Support 팀에 연락하여 연장을 요청하십시오. 2024년 4월 2일까지 버전 6.1을 유지하도록 계정을 연장할 수 있습니다. 2024년 3월 1일까지 연락이 없으면 2024년 3월 4일에서 2024년 3월 26일 사이에 계정이 버전 7.0으로 자동 마이그레이션됩니다.

AWS 콘텐츠 조정 버전 7용 SDK 및 사용 가이드

선택한 개발 언어에 해당하는 SDK를 다운로드하고 해당 사용 설명서를 참조하십시오.

버전 6.1~7의 레이블 매핑

콘텐츠 조정 버전 7에는 새 레이블 범주가 추가되고 기존 레이블 이름이 수정되었습니다. 6.1 레이블을 7개 레이블에 매핑하는 방법을 결정할 레이블 카테고리 때는 에 있는 분류표를 참조하십시오.

레이블 매핑의 몇 가지 예는 다음 섹션에 나와 있습니다. 애플리케이션의 사후 처리 로직에 따라 필요한 업데이트를 수행하기 전에 이러한 매핑과 레이블 정의를 검토하는 것이 좋습니다.

L1 매핑 스키마

최상위 카테고리 (L1) (예: Explicit NuditySuggestive, Violence 등) 만 필터링하는 포스트 프로세싱 로직을 사용하는 경우 아래 표를 참조하여 코드를 업데이트하십시오.

V6.1 L1 V7 L1
Explicit Nudity Explicit
Suggestive Non-Explicit Nudity of Intimate parts and Kissing
Swimwear or Underwear
Violence Violence
Visually Disturbing Visually Disturbing
Rude Gestures Rude Gestures
Drugs Drugs & Tobacco
Tobacco Drugs & Tobacco
Alcohol Alcohol
Gambling Gambling
Hate Symbols Hate Symbols

L2 매핑 스키마

L1 및 L2 카테고리 (예: Violence / Weapon Violence 등) 를 필터링하는 포스트 프로세싱 로직을 사용하는 경우 아래 표를 참조하여 코드를 업데이트하십시오. Explicit Nudity / Nudity, Suggestive / Female Swimwear Or Underwear

V6.1 L1 V6.1 L2 V7 L1 V7 L2 V7 L3 V7 ContentTypes
Explicit Nudity Nudity Explicit Explicit Nudity

노출된 여성 젖꼭지

노출된 엉덩이 또는 항문

Graphic Male Nudity Explicit Explicit Nudity Exposed Male Genitalia
Graphic Female Nudity Explicit Explicit Nudity Exposed Female Genitalia
Sexual Activity Explicit Explicit Sexual Activity
Illustrated Explicit Nudity Explicit Explicit Nudity Map to "Animated" and "Illustrated"
Illustrated Explicit Nudity Explicit Explicit Sexual Activity Map to "Animated" and "Illustrated"
Adult Toys Explicit Sex Toys
Suggestive Female Swimwear Or Underwear Swimwear or Underwear Female Swimwear or Underwear
Male Swimwear Or Underwear Swimwear or Underwear Male Swimwear or Underwear
Partial Nudity Non-Explicit Nudity of Intimate parts and Kissing Non-Explicit Nudity Implied Nudity
Barechested Male Non-Explicit Nudity of Intimate parts and Kissing Non-Explicit Nudity Exposed Male Nipple
Revealing Clothes Non-Explicit Nudity of Intimate parts and Kissing Non-Explicit Nudity
Non-Explicit Nudity of Intimate parts and Kissing Obstructed Intimate Parts
Sexual Situations Non-Explicit Nudity of Intimate parts and Kissing Kissing on the Lips
Violence Graphic Violence Or Gore Violence Graphic Violence Blood & Gore
Physical Violence Violence Graphic Violence Physical Violence
Weapon Violence Violence Graphic Violence Weapon Violence
Weapons Violence Weapons
Self Injury Violence Graphic Violence Self-Harm
Visually Disturbing Emaciated Bodies Visually Disturbing Death and Emaciation Emaciated Bodies
Corpses Visually Disturbing Death and Emaciation Corpses
Hanging Visually Disturbing Death and Emaciation Corpses
Air Crash Visually Disturbing Crashes Air Crash
Explosions And Blasts Violence Graphic Violence Explosions and Blasts
Rude Gestures Middle Finger Rude Gestures Middle Finger
Drugs Drug Products Drugs & Tobacco Products
Drug Use Drugs & Tobacco Drugs & Tobacco Paraphernalia & Use
Pills Drugs & Tobacco Products Pills
Drug Paraphernalia Drugs & Tobacco Drugs & Tobacco Paraphernalia & Use
Tobacco Tobacco Products Drugs & Tobacco Products
Smoking Drugs & Tobacco Drugs & Tobacco Paraphernalia & Use Smoking
Alcohol Drinking Alcohol Alcohol Use Drinking
Alcoholic Beverages Alcohol Alcoholic Beverages
Gambling Gambling Gambling
Hate Symbols Nazi Party Hate Symbols Nazi Party
White Supremacy Hate Symbols White Supremacy
Extremist Hate Symbols Extremist