{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# Notebook for Evaluating Content Moderation Service\n",
"\n",
"This notebook is part of the AWS blog series about Evaluating Content Moderation Service, and provides a sample code to streamline steps from creating ground truth labeling job to generating evaluation metrics.\n",
" \n",
"\n",
"Prerequisite: **You must prepare an image dataset (evaluation dataset) ready for evaluation and [upload it to a S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html). The dataset should contain the moderation labels of interest to your use case.** \n",
"\n",
"Follow the steps in this notebook to evaluate Amazon Rekognition for content moderation:\n",
"- [Step 1: Setup Notebook.](#step1)\n",
"- [Step 2: Use Amazon SageMaker Ground Truth service to assign ground truth moderation labels to the evaluation dataset.](#step2)\n",
"- [Step 3: Use Amazon Rekognition pre-trained moderation API to generate predicted labels for the evaluation dataset.](#step3) \n",
"- [Step 4: Assess the performance.](#step4)"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## Step 1: Setup Notebook "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let's get the latest installations of our dependencies."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"!pip install --upgrade pip\n",
"!pip install boto3 --upgrade\n",
"!pip install sagemaker --upgrade"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to start, it's necessary to create a bucket where to host evaluation dataset, then set proper values for following variables."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"import itertools\n",
"import json\n",
"import time\n",
"import boto3\n",
"import sagemaker\n",
"\n",
"BUCKET = '' # S3 bucket holds your evaluation dataset\n",
"FILE_PREFIX = '' # The prefix for your evaluation dataset\n",
"EXP_NAME = '' # S3 prefix for SageMaker Ground Truth labeling job, please do not add trailing \"/\"\n",
"INPUT_MANIFEST = '' # Input manifest filename for SageMaker Ground Truth labeling job e.g. input.manifest\n",
"OUTPUT_MANIFEST = '