|
| 1 | +--- |
| 2 | +title: Analyze image container - Azure AI content safety |
| 3 | +titleSuffix: Azure AI services |
| 4 | +description: Install and run content safety analyze image containers with Docker to detect harmful content in image. |
| 5 | +author: |
| 6 | +manager: |
| 7 | +ms.service: azure-ai-content-safety |
| 8 | +ms.topic: |
| 9 | +ms.date: 9/11/2024 |
| 10 | +ms.author: |
| 11 | +keywords: on-premises, Docker, container |
| 12 | +--- |
| 13 | + |
| 14 | +# Analyze image content with docker containers |
| 15 | + |
| 16 | +The analyze image container scans image for sexual content, violence, hate, and self harm with multi-severity levels. In this article, you learn how to download, install, and run a content safety to image container. |
| 17 | + |
| 18 | +For more information about prerequisites, validating that a container is running, running multiple containers on the same host, and running disconnected containers, see [Install and run content safety containers with Docker](container-install-run.md). |
| 19 | + |
| 20 | +## Container images |
| 21 | + |
| 22 | +The content safety analyze image container image for all supported versions can be found on the [Microsoft Container Registry (MCR)]( https://mcr.microsoft.com/en-us/product/azure-cognitive-services/contentsafety/image-analyze/tags) syndicate. It resides within the `azure-cognitive-services/contentsafety` repository and is named `image-analyze`. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +**to do: update MCR screenshot** **[to-do]** update MCR screenshot for AACS image analyze image. the MCR release is in progress, expect to finish by EOD 9/20 PST. the MCR link is https://mcr.microsoft.com/en-us/product/azure-cognitive-services/contentsafety/image-analyze/tags |
| 27 | + |
| 28 | + |
| 29 | +The fully qualified container image name is, `mcr.microsoft.com/en-us/product/azure-cognitive-services/contentsafety/image-analyze`. Either append a specific version or append `:latest` to get the most recent version. |
| 30 | + |
| 31 | +| Version | Path | |
| 32 | +|-----------|------------| |
| 33 | +| Latest | `mcr.microsoft.com/azure-cognitive-services/contentsafety/image-analyze:latest`<br/><br/>The `latest` tag pulls the latest image. | |
| 34 | +|1.0.0-amd64-preview|`mcr.microsoft.com/azure-cognitive-services/contentsafety/image-analyze:1.0.0-amd64-preview`| |
| 35 | + |
| 36 | +## Get the container image with docker pull |
| 37 | + |
| 38 | +You need the [prerequisites](container-install-run.md#prerequisites) including required hardware. Also see the [recommended allocation of resources](container-install-run.md#host-computer-requirements-and-recommendations) |
| 39 | +for each content safety container. |
| 40 | + |
| 41 | +Use the [docker pull](https://docs.docker.com/engine/reference/commandline/pull/) command to download a container image from Microsoft Container Registry: |
| 42 | + |
| 43 | +```bash |
| 44 | +docker mcr.microsoft.com/azure-cognitive-services/contentsafety/image-analyze:latest |
| 45 | +``` |
| 46 | + |
| 47 | + |
| 48 | +## Run the container with docker run |
| 49 | + |
| 50 | +Use the [docker run](https://docs.docker.com/engine/reference/commandline/run/) command to run the container. |
| 51 | + |
| 52 | +# [Standard container](#tab/standard) |
| 53 | + |
| 54 | +The following table represents the various `docker run` parameters and their corresponding descriptions: |
| 55 | + |
| 56 | +| Parameter | Description | |
| 57 | +|---------|---------| |
| 58 | +| `{ENDPOINT_URI}` | The endpoint is required for metering and billing. For more information, see [billing arguments](content safety-container-howto.md#billing-arguments). | |
| 59 | +| `{API_KEY}` | The API key is required. For more information, see [billing arguments](content safety-container-howto.md#billing-arguments). | |
| 60 | + |
| 61 | +When you run the content safety to image container, configure the port, memory, and CPU according to the content safety to image container [requirements and recommendations](content safety-container-howto.md#container-requirements-and-recommendations). |
| 62 | + |
| 63 | +Here's an example `docker run` command with placeholder values. You must specify the `ENDPOINT_URI` and `API_KEY` values: |
| 64 | + |
| 65 | +```bash |
| 66 | +docker run --rm -it -p 5000:5000 --gpus all \ |
| 67 | +mcr.microsoft.com/azure-cognitive-services/contentsafety/image-analyze:latest \ |
| 68 | +Eula=accept \ |
| 69 | +Billing={ENDPOINT_URI} \ |
| 70 | +ApiKey={API_KEY} |
| 71 | +``` |
| 72 | + |
| 73 | +This command: |
| 74 | +* Runs a `image-analyze` container from the container image. |
| 75 | +* `--gpus all` Use all available GPU resources. Content safety container requires CUDA for optimal performance. See more in [host requirements and recommendations](./container-install-run.md#host-computer-requirements-and-recommendations). Also make sure your host install [NVIDIA container toolkit](./container-install-run.md#installing-the-nvidia-container-toolkit) |
| 76 | +* Exposes TCP port 5000 and allocates a pseudo-TTY for the container. |
| 77 | +* Automatically removes the container after it exits. The container image is still available on the host computer. |
| 78 | + |
| 79 | +# [Disconnected container](#tab/disconnected) |
| 80 | + |
| 81 | +To run disconnected containers (not connected to the internet), you must submit [this request form](https://aka.ms/csdisconnectedcontainers) and wait for approval. For more information about applying and purchasing a commitment plan to use containers in disconnected environments, see [Use containers in disconnected environments](../containers/disconnected-containers.md) in the Azure AI services documentation. |
| 82 | + |
| 83 | +If you're approved to run the container disconnected from the internet, the following example shows the formatting of the `docker run` command to use, with placeholder values. Replace these placeholder values with your own values. |
| 84 | + |
| 85 | +The `DownloadLicense=True` parameter in your `docker run` command downloads a license file to enable your Docker container to run when it isn't connected to the internet. It also contains an expiration date, after which the license file is invalid to run the container. You can only use a license file with the appropriate container that you're approved for. For example, you can't use a license file for a `content safety-to-image` container with a `neural-image-to-content safety` container. |
| 86 | + |
| 87 | +| Placeholder | Description | |
| 88 | +|-------------|-------| |
| 89 | +| `{IMAGE}` | The container image you want to use.<br/><br/>For example: `mcr.microsoft.com/azure-cognitive-services/content safety-to-image:latest` | |
| 90 | +| `{LICENSE_MOUNT}` | The path where the license is downloaded, and mounted.<br/><br/>For example: `/host/license:/path/to/license/directory` | |
| 91 | +| `{ENDPOINT_URI}` | The endpoint for authenticating your service request. You can find it on your resource's **Key and endpoint** page, on the Azure portal.<br/><br/>For example: `https://<your-resource-name>.cognitiveservices.azure.com` | |
| 92 | +| `{API_KEY}` | The key for your content safety resource. You can find it on your resource's **Key and endpoint** page, on the Azure portal. | |
| 93 | +| `{CONTAINER_LICENSE_DIRECTORY}` | Location of the license folder on the container's local filesystem.<br/><br/>For example: `/path/to/license/directory` | |
| 94 | + |
| 95 | +```bash |
| 96 | +docker run --rm -it -p 5000:5000 \ |
| 97 | +-v {LICENSE_MOUNT} \ |
| 98 | +{IMAGE} \ |
| 99 | +eula=accept \ |
| 100 | +billing={ENDPOINT_URI} \ |
| 101 | +apikey={API_KEY} \ |
| 102 | +DownloadLicense=True \ |
| 103 | +Mounts:License={CONTAINER_LICENSE_DIRECTORY} |
| 104 | +``` |
| 105 | + |
| 106 | +Once the license file is downloaded, you can run the container in a disconnected environment. The following example shows the formatting of the `docker run` command you use, with placeholder values. Replace these placeholder values with your own values. |
| 107 | + |
| 108 | +Wherever the container is run, the license file must be mounted to the container and the location of the license folder on the container's local filesystem must be specified with `Mounts:License=`. An output mount must also be specified so that billing usage records can be written. |
| 109 | + |
| 110 | +Placeholder | Value | Format or example | |
| 111 | +|-------------|-------|---| |
| 112 | +| `{IMAGE}` | The container image you want to use.<br/><br/>For example: `mcr.microsoft.com/azure-cognitive-services/content safety-to-image:latest` | |
| 113 | + `{MEMORY_SIZE}` | The appropriate size of memory to allocate for your container.<br/><br/>For example: `4g` | |
| 114 | +| `{NUMBER_CPUS}` | The appropriate number of CPUs to allocate for your container.<br/><br/>For example: `4` | |
| 115 | +| `{LICENSE_MOUNT}` | The path where the license is located and mounted.<br/><br/>For example: `/host/license:/path/to/license/directory` | |
| 116 | +| `{OUTPUT_PATH}` | The output path for logging.<br/><br/>For example: `/host/output:/path/to/output/directory`<br/><br/>For more information, see [usage records](../containers/disconnected-containers.md#usage-records) in the Azure AI services documentation. | |
| 117 | +| `{CONTAINER_LICENSE_DIRECTORY}` | Location of the license folder on the container's local filesystem.<br/><br/>For example: `/path/to/license/directory` | |
| 118 | +| `{CONTAINER_OUTPUT_DIRECTORY}` | Location of the output folder on the container's local filesystem.<br/><br/>For example: `/path/to/output/directory` | |
| 119 | + |
| 120 | +```bash |
| 121 | +docker run --rm -it -p 5000:5000 --memory {MEMORY_SIZE} --cpus {NUMBER_CPUS} \ |
| 122 | +-v {LICENSE_MOUNT} \ |
| 123 | +-v {OUTPUT_PATH} \ |
| 124 | +{IMAGE} \ |
| 125 | +eula=accept \ |
| 126 | +Mounts:License={CONTAINER_LICENSE_DIRECTORY} |
| 127 | +Mounts:Output={CONTAINER_OUTPUT_DIRECTORY} |
| 128 | +``` |
| 129 | + |
| 130 | +Content safety containers provide a default directory for writing the license file and billing log at runtime. The default directories are /license and /output respectively. |
| 131 | + |
| 132 | +When you're mounting these directories to the container with the `docker run -v` command, make sure the local machine directory is set ownership to `user:group nonroot:nonroot` before running the container. |
| 133 | + |
| 134 | +Here's a sample command to set file/directory ownership. |
| 135 | + |
| 136 | +```bash |
| 137 | +sudo chown -R nonroot:nonroot <YOUR_LOCAL_MACHINE_PATH_1> <YOUR_LOCAL_MACHINE_PATH_2> ... |
| 138 | +``` |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## Test the container |
| 143 | + |
| 144 | +Once the container is up and running, you can validate its operation by sending a request to the REST endpoint deployed within the container. To do this, follow below article. Note, you need to replace the endpoint URL with the Docker URL specific to your container deployment. Also, ensure that you're using host authentication, rather than key-based authentication. |
| 145 | + |
| 146 | + |
| 147 | + - [analyze image quick start](./quickstart-text.md#analyze-image-content) |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +## Next steps |
| 154 | + |
| 155 | +* See the [content safety containers overview](content safety-container-overview.md) |
| 156 | +* Review [configure containers](content safety-container-configuration.md) for configuration settings |
| 157 | +* Use more [Azure AI containers](../cognitive-services-container-support.md) |
0 commit comments