nvidia/maisi

RUN ANYWHERE

MAISI is a pre-trained volumetric (3D) CT Latent Diffusion Generative Model.

By running the below commands, you accept the NVIDIA AI Enterprise Terms of Use and the NVIDIA Community Models License.

Pull and run nvidia/maisi using Docker (this will download the full model and run it in your local environment)

$ docker login nvcr.io Username: $oauthtoken Password: <PASTE_API_KEY_HERE>

Start NIM

  1. Export NGC_API_KEY variable.
export NGC_API_KEY=<your personal NGC key>
  1. The NIM container automatically downloads any required models. To save time and bandwidth it is recommended to provide a local cache directory. This way the NIM will be able to reuse any already downloaded models. Execute the following command to setup the cache directory:
export LOCAL_NIM_CACHE=~/.cache/nim mkdir -p $LOCAL_NIM_CACHE

Note that you may need to run (sudo) chmod -R 777 $LOCAL_NIM_CACHE after the MAISI model is downloaded to avoid permission issues.

  1. Run the NIM container with the following commands:
docker run --rm -it --name maisi \ --runtime=nvidia -e CUDA_VISIBLE_DEVICES=0 \ -p 8000:8000 \ -e NGC_API_KEY=$NGC_API_KEY \ nvcr.io/nim/nvidia/maisi:latest

This command will start the NIM container and expose port 8000 for the user to interact with the NIM.

  1. Open a new terminal, leaving the terminal open with the just launched service. In the new terminal, wait until the health check end point returns {"status":"ready"} before proceeding. This may take a couple of minutes. You can use the following command to query the health check.
curl -X 'GET' \ 'http://localhost:8000/v1/health/ready' \ -H 'accept: application/json'

Python Client Example: Generate CT volumes

  1. Save following Python example to a file named nim_client.py. Here's a script to generate synthetic images, this script will POST a request to /v1/maisi/run with image generation parameters. It then handles the response, saving ZIP files or displaying JSON messages as appropriate.
import requests from datetime import datetime base_url = "http://localhost:8000" # Generate synthetic image payload = { "num_output_samples": 1, "body_region": ["abdomen"], "anatomy_list": ["liver", "spleen"], "output_size": [512, 512, 512], "spacing": [1.0, 1.0, 1.0], "image_output_ext": ".nii.gz", "label_output_ext": ".nii.gz", } generation_response = requests.post(f"{base_url}/v1/maisi/run", json=payload) if generation_response.status_code == 200: print("Image generation request successful") if generation_response.headers.get('Content-Type') == 'application/zip': # Save ZIP file with timestamp timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") zip_filename = f"output_{timestamp}.zip" with open(zip_filename, "wb") as f: f.write(generation_response.content) print(f"Output saved as {zip_filename}") elif 'application/json' in generation_response.headers.get('Content-Type', ''): response_json = generation_response.json() print("Response:", response_json.get('message') or response_json.get('error')) else: print("Unexpected response format") else: print(f"Error {generation_response.status_code}: {generation_response.text}")
  1. Execute the example.
python nim_client.py
  1. The resulting CT volume and label files will be returned and written to output.zip.