Getting Started#
Prerequisites#
Refer to the Support Matrix to make sure that you have the supported hardware and software stack.
An NGC personal API key. The NIM microservice uses the API key to download models from NVIDIA NGC. Refer to Generating a Personal API Key in the NVIDIA NGC User Guide for more information.
When you create an NGC API personal key, select at least NGC Catalog from the Services Included menu. You can specify more services to use the key for additional purposes.
Model credentials Get the credentials to download the models from Hive.
Starting the NIM Container#
Export your personal API key and model credentials as environment variables:
export NGC_API_KEY="..." export NIM_REPOSITORY_OVERRIDE="s3://..." export AWS_REGION="..." export AWS_ACCESS_KEY_ID="..." export AWS_SECRET_ACCESS_KEY="..."
A more secure alternative is to use a password manager, such as https://www.passwordstore.org.
Login to NVIDIA NGC so that you can pull the NIM container:
$ echo "$NGC_API_KEY" | docker login nvcr.io --username '$oauthtoken' --password-stdin
Use
$oauthtoken
as the user name and$NGC_API_KEY
as the password. The$oauthtoken
user name indicates that you authenticate with an API key and not a user name and password.Start the NIM container with one of the Multimodal Safety models:
docker run -it --rm --name=nim-server \ --runtime=nvidia \ --gpus='"device=0"' \ -e NIM_REPOSITORY_OVERRIDE \ -e AWS_REGION \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e NIM_HTTP_API_PORT=8003 \ -p 8003:8003 \ -p 8002:8002 \ nvcr.io/nim/hive/ai-generated-image-detection:1.0.0
docker run -it --rm --name=nim-server \ --runtime=nvidia \ --gpus='"device=0"' \ -e NIM_REPOSITORY_OVERRIDE \ -e AWS_REGION \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e NIM_HTTP_API_PORT=8003 \ -p 8003:8003 \ -p 8002:8002 \ nvcr.io/nim/hive/deepfake-image-detection:1.0.0
Optional: Confirm the service is ready to respond to inference requests:
$ curl -X GET http://localhost:8003/v1/health/ready
Example Output
{"status":"ready"}
Send an inference request:
invoke_url="http://localhost:8003/v1/infer" input_image_path="input.jpg" # download an example image curl https://assets.ngc.nvidia.com/products/api-catalog/sdxl/sdxl1.jpg > $input_image_path image_b64=$(base64 $input_image_path) length=${#image_b64} echo '{ "input": ["data:image/png;base64,'${image_b64}'"] }' > payload.json curl $invoke_url \ -H "Content-Type: application/json" \ -d @payload.json
Expected output:
is_ai_generated
represents probability value between 0 and 1.0 indicating the likelihood that the input image was generated by a Generative AI model.possible_sources
provides further details as to the image’s source, with support for the most popular AI art generators currently in use. If the model cannot identify a source, it will return none as a possible source. All possible source scores are normalized to sum to 1.0, with each score ranging from 0 to 1.0.{ "data": [ { "index": 0, "is_ai_generated": 0.9994508624076843, "possible_sources": { "sora": 6.149838416291686e-9, "pika": 0.00003106551230303012, "haiper": 4.638551895423627e-15, "kling": 3.5930388438826233e-12, "luma": 0.0000019694166439876426, "hedra": 2.335490201232915e-8, "runway": 7.846174820969054e-10, "flux": 0.032329242676496506, "sdxlinpaint": 0.000004169243311480386, "stablediffusioninpaint": 8.627880077050065e-10, "otherimagegenerators": 0.0012155241565778852, "bingimagecreator": 0.000007865392944950145, "adobefirefly": 0.0060778092592954636, "lcm": 7.558705874544103e-7, "dalle": 0.05188118666410446, "pixart": 0.0000012418740880093537, "glide": 2.7829472060147964e-9, "stablediffusion": 0.003196755424141884, "imagen": 0.0016779577126726508, "amused": 1.1864609295031414e-10, "stablecascade": 0.0000036945552892575506, "midjourney": 0.013604957610368729, "deepfloyd": 1.6731604546293966e-8, "gan": 1.9364195225080039e-7, "stablediffusionxl": 0.8875080347061157, "vqdiffusion": 2.0054453653273185e-9, "kandinsky": 0.000013597166798717808, "wuerstchen": 0.0000017195044392792624, "titan": 0.0000012228841796968482, "ideogram": 0.001472753589041531, "none": 0.0009681681985966861 }, "status": "SUCCESS" } ] }
The description of all API parameters could be found in API Reference.
invoke_url="http://localhost:8003/v1/infer" input_image_path="input.jpg" # download an example image curl https://assets.ngc.nvidia.com/products/api-catalog/deepfake-image-detection/input/deepfake.jpg > $input_image_path image_b64=$(base64 $input_image_path) length=${#image_b64} echo '{ "input": ["data:image/png;base64,'${image_b64}'"], "return_image": false }' > payload.json curl $invoke_url \ -H "Content-Type: application/json" \ -d @payload.json
Expected output:
Each detected face in the input image is represented a bounding box with:bbox_confidence
- a confidence value between 0 and 1.0 indicating the model’s confidence in the detection of the face.vertices
- an array of coordinates representing the geometric description of the detected bounding box with the top-left and the bottom-right corners coordinates.is_deepfake
- a probability value between 0 and 1.0 indicating the likelihood that the detected face is a deepfake.image
- a base64-encoded string representing the input image with overlaid bounding boxes indicating the detected faces. This field is only included in the response if the return_image parameter is set to true in the payload.{ "data": [ { "index": 0, "bounding_boxes": [ { "vertices": [ { "x": 167.9155731201172, "y": 105.52117919921875 }, { "x": 327.764404296875, "y": 327.6148376464844 } ], "bbox_confidence": 0.9352303147315979, "is_deepfake": 0.9982458353042603 } ], "status": "SUCCESS" } ] }
The description of all API parameters could be found in API Reference.
Runtime Parameters for the Container#
Flags |
Description |
---|---|
|
|
|
Delete the container after it stops (see Docker docs). |
|
Give a name to the NIM container. Use any preferred value. |
|
Ensure NVIDIA drivers are accessible in the container. |
|
Expose NVIDIA GPU 0 inside the container. If you are running on a host with multiple GPUs, you need to specify which GPU to use. See GPU Enumeration for further information on for mounting specific GPUs. |
|
Specify the profile to load. Refer to Models for information about the available profiles. |
|
Specify the port that would be used by NIM inside the container (default is |
|
Forward the port where the NIM HTTP server is published inside the container to access from the host system. The left-hand side of |
Caching Models#
The first time you start the container, the microservice downloads the model from NGC. You can avoid this download step on future runs by caching the model locally.
export LOCAL_NIM_CACHE=~/.cache/nim_sdxl mkdir -p "$LOCAL_NIM_CACHE" chmod 777 $LOCAL_NIM_CACHE docker run -it --rm --name=nim-server \ --runtime=nvidia \ --gpus='"device=0"' \ -e NIM_REPOSITORY_OVERRIDE \ -e AWS_REGION \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e NIM_HTTP_API_PORT=8003 \ -p 8003:8003 \ -p 8002:8002 \ -v "$LOCAL_NIM_CACHE:/opt/nim/.cache/" \ nvcr.io/nim/hive/ai-generated-image-detection:1.0.0export LOCAL_NIM_CACHE=~/.cache/nim_sdxl mkdir -p "$LOCAL_NIM_CACHE" chmod 777 $LOCAL_NIM_CACHE docker run -it --rm --name=nim-server \ --runtime=nvidia \ --gpus='"device=0"' \ -e NIM_REPOSITORY_OVERRIDE \ -e AWS_REGION \ -e AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY \ -e NIM_HTTP_API_PORT=8003 \ -p 8003:8003 \ -p 8002:8002 \ -v "$LOCAL_NIM_CACHE:/opt/nim/.cache/" \ nvcr.io/nim/hive/deepfake-image-detection:1.0.0
When you use a model cache, if you change the model profile in NIM_MODEL_PROFILE
, then delete the contents of the cache directory on the host before you start the container.
Deleting the directory contents ensure that the microservice loads only the specified model profile.
Stopping the Container#
The following commands stop the container by stopping and removing the running docker container.
docker stop nim-server
docker rm nim-server
Next Steps#
Configuration for environment variables and command-line arguments.