--- library_name: pytorch license: other tags: - generative_ai - android pipeline_tag: unconditional-image-generation --- ![](https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/controlnet_canny/web-assets/model_demo.png) # ControlNet-Canny: Optimized for Mobile Deployment ## Generating visual arts from text prompt and input guiding image On-device, high-resolution image synthesis from text and image prompts. ControlNet guides Stable-diffusion with provided input image to generate accurate images from given input prompt. This model is an implementation of ControlNet-Canny found [here](https://github.com/lllyasviel/ControlNet). This repository provides scripts to run ControlNet-Canny on Qualcomm® devices. More details on model performance across various devices, can be found [here](https://aihub.qualcomm.com/models/controlnet_canny). ### Model Details - **Model Type:** Model_use_case.image_generation - **Model Stats:** - Input: Text prompt and input image as a reference - Conditioning Input: Canny-Edge - Text Encoder Number of parameters: 340M - UNet Number of parameters: 865M - VAE Decoder Number of parameters: 83M - ControlNet Number of parameters: 361M - Model size: 1.4GB | Model | Precision | Device | Chipset | Target Runtime | Inference Time (ms) | Peak Memory Range (MB) | Primary Compute Unit | Target Model |---|---|---|---|---|---|---|---|---| | text_encoder | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | QNN_CONTEXT_BINARY | 22.037 ms | 0 - 14 MB | NPU | Use Export Script | | text_encoder | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | PRECOMPILED_QNN_ONNX | 34.135 ms | 0 - 13 MB | NPU | Use Export Script | | text_encoder | w8a16 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_CONTEXT_BINARY | 7.442 ms | 0 - 8 MB | NPU | Use Export Script | | text_encoder | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_CONTEXT_BINARY | 3.246 ms | 0 - 3 MB | NPU | Use Export Script | | text_encoder | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | PRECOMPILED_QNN_ONNX | 5.491 ms | 0 - 162 MB | NPU | Use Export Script | | text_encoder | w8a16 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_CONTEXT_BINARY | 3.508 ms | 0 - 9 MB | NPU | Use Export Script | | text_encoder | w8a16 | SA7255P ADP | Qualcomm® SA7255P | QNN_CONTEXT_BINARY | 7.442 ms | 0 - 8 MB | NPU | Use Export Script | | text_encoder | w8a16 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_CONTEXT_BINARY | 3.246 ms | 0 - 2 MB | NPU | Use Export Script | | text_encoder | w8a16 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_CONTEXT_BINARY | 3.214 ms | 0 - 2 MB | NPU | Use Export Script | | text_encoder | w8a16 | SA8775P ADP | Qualcomm® SA8775P | QNN_CONTEXT_BINARY | 3.508 ms | 0 - 9 MB | NPU | Use Export Script | | text_encoder | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_CONTEXT_BINARY | 2.329 ms | 0 - 20 MB | NPU | Use Export Script | | text_encoder | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | PRECOMPILED_QNN_ONNX | 3.96 ms | 0 - 19 MB | NPU | Use Export Script | | text_encoder | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_CONTEXT_BINARY | 1.746 ms | 0 - 16 MB | NPU | Use Export Script | | text_encoder | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | PRECOMPILED_QNN_ONNX | 3.13 ms | 0 - 14 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | QNN_CONTEXT_BINARY | 3.624 ms | 0 - 14 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | PRECOMPILED_QNN_ONNX | 5.752 ms | 0 - 14 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_CONTEXT_BINARY | 1.54 ms | 0 - 10 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | PRECOMPILED_QNN_ONNX | 2.622 ms | 0 - 10 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_CONTEXT_BINARY | 3.598 ms | 0 - 0 MB | NPU | Use Export Script | | text_encoder | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | PRECOMPILED_QNN_ONNX | 5.671 ms | 157 - 157 MB | NPU | Use Export Script | | unet | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | QNN_CONTEXT_BINARY | 2078.956 ms | 13 - 24 MB | NPU | Use Export Script | | unet | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | PRECOMPILED_QNN_ONNX | 2323.924 ms | 13 - 26 MB | NPU | Use Export Script | | unet | w8a16 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_CONTEXT_BINARY | 265.894 ms | 11 - 19 MB | NPU | Use Export Script | | unet | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_CONTEXT_BINARY | 114.963 ms | 13 - 15 MB | NPU | Use Export Script | | unet | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | PRECOMPILED_QNN_ONNX | 116.648 ms | 0 - 882 MB | NPU | Use Export Script | | unet | w8a16 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_CONTEXT_BINARY | 108.505 ms | 6 - 14 MB | NPU | Use Export Script | | unet | w8a16 | SA7255P ADP | Qualcomm® SA7255P | QNN_CONTEXT_BINARY | 265.894 ms | 11 - 19 MB | NPU | Use Export Script | | unet | w8a16 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_CONTEXT_BINARY | 114.887 ms | 13 - 15 MB | NPU | Use Export Script | | unet | w8a16 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_CONTEXT_BINARY | 114.975 ms | 13 - 15 MB | NPU | Use Export Script | | unet | w8a16 | SA8775P ADP | Qualcomm® SA8775P | QNN_CONTEXT_BINARY | 108.505 ms | 6 - 14 MB | NPU | Use Export Script | | unet | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_CONTEXT_BINARY | 80.67 ms | 13 - 29 MB | NPU | Use Export Script | | unet | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | PRECOMPILED_QNN_ONNX | 86.931 ms | 13 - 29 MB | NPU | Use Export Script | | unet | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_CONTEXT_BINARY | 61.336 ms | 5 - 21 MB | NPU | Use Export Script | | unet | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | PRECOMPILED_QNN_ONNX | 66.951 ms | 5 - 16 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | QNN_CONTEXT_BINARY | 176.43 ms | 13 - 26 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | PRECOMPILED_QNN_ONNX | 178.974 ms | 11 - 21 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_CONTEXT_BINARY | 47.318 ms | 13 - 24 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | PRECOMPILED_QNN_ONNX | 48.732 ms | 13 - 21 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_CONTEXT_BINARY | 116.519 ms | 13 - 13 MB | NPU | Use Export Script | | unet | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | PRECOMPILED_QNN_ONNX | 115.83 ms | 829 - 829 MB | NPU | Use Export Script | | vae | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | QNN_CONTEXT_BINARY | 6122.737 ms | 0 - 14 MB | NPU | Use Export Script | | vae | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | PRECOMPILED_QNN_ONNX | 5411.761 ms | 2 - 15 MB | NPU | Use Export Script | | vae | w8a16 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_CONTEXT_BINARY | 718.637 ms | 0 - 9 MB | NPU | Use Export Script | | vae | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_CONTEXT_BINARY | 269.846 ms | 0 - 3 MB | NPU | Use Export Script | | vae | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | PRECOMPILED_QNN_ONNX | 226.709 ms | 0 - 66 MB | NPU | Use Export Script | | vae | w8a16 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_CONTEXT_BINARY | 251.431 ms | 1 - 10 MB | NPU | Use Export Script | | vae | w8a16 | SA7255P ADP | Qualcomm® SA7255P | QNN_CONTEXT_BINARY | 718.637 ms | 0 - 9 MB | NPU | Use Export Script | | vae | w8a16 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_CONTEXT_BINARY | 269.335 ms | 0 - 2 MB | NPU | Use Export Script | | vae | w8a16 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_CONTEXT_BINARY | 269.749 ms | 0 - 3 MB | NPU | Use Export Script | | vae | w8a16 | SA8775P ADP | Qualcomm® SA8775P | QNN_CONTEXT_BINARY | 251.431 ms | 1 - 10 MB | NPU | Use Export Script | | vae | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_CONTEXT_BINARY | 203.734 ms | 0 - 18 MB | NPU | Use Export Script | | vae | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | PRECOMPILED_QNN_ONNX | 163.111 ms | 3 - 23 MB | NPU | Use Export Script | | vae | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_CONTEXT_BINARY | 178.105 ms | 0 - 13 MB | NPU | Use Export Script | | vae | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | PRECOMPILED_QNN_ONNX | 146.877 ms | 3 - 14 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | QNN_CONTEXT_BINARY | 514.198 ms | 0 - 14 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | PRECOMPILED_QNN_ONNX | 445.416 ms | 3 - 17 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_CONTEXT_BINARY | 116.031 ms | 2 - 13 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | PRECOMPILED_QNN_ONNX | 94.818 ms | 3 - 13 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_CONTEXT_BINARY | 266.234 ms | 0 - 0 MB | NPU | Use Export Script | | vae | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | PRECOMPILED_QNN_ONNX | 219.532 ms | 59 - 59 MB | NPU | Use Export Script | | controlnet | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | QNN_CONTEXT_BINARY | 1063.49 ms | 2 - 14 MB | NPU | Use Export Script | | controlnet | w8a16 | Dragonwing Q-6690 MTP | Qualcomm® Qcm6690 | PRECOMPILED_QNN_ONNX | 882.494 ms | 2 - 17 MB | NPU | Use Export Script | | controlnet | w8a16 | QCS8275 (Proxy) | Qualcomm® QCS8275 (Proxy) | QNN_CONTEXT_BINARY | 130.285 ms | 2 - 10 MB | NPU | Use Export Script | | controlnet | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | QNN_CONTEXT_BINARY | 70.099 ms | 2 - 4 MB | NPU | Use Export Script | | controlnet | w8a16 | QCS8550 (Proxy) | Qualcomm® QCS8550 (Proxy) | PRECOMPILED_QNN_ONNX | 59.406 ms | 0 - 384 MB | NPU | Use Export Script | | controlnet | w8a16 | QCS9075 (Proxy) | Qualcomm® QCS9075 (Proxy) | QNN_CONTEXT_BINARY | 66.205 ms | 2 - 11 MB | NPU | Use Export Script | | controlnet | w8a16 | SA7255P ADP | Qualcomm® SA7255P | QNN_CONTEXT_BINARY | 130.285 ms | 2 - 10 MB | NPU | Use Export Script | | controlnet | w8a16 | SA8255 (Proxy) | Qualcomm® SA8255P (Proxy) | QNN_CONTEXT_BINARY | 69.994 ms | 2 - 4 MB | NPU | Use Export Script | | controlnet | w8a16 | SA8650 (Proxy) | Qualcomm® SA8650P (Proxy) | QNN_CONTEXT_BINARY | 69.791 ms | 2 - 4 MB | NPU | Use Export Script | | controlnet | w8a16 | SA8775P ADP | Qualcomm® SA8775P | QNN_CONTEXT_BINARY | 66.205 ms | 2 - 11 MB | NPU | Use Export Script | | controlnet | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | QNN_CONTEXT_BINARY | 53.524 ms | 2 - 21 MB | NPU | Use Export Script | | controlnet | w8a16 | Samsung Galaxy S24 | Snapdragon® 8 Gen 3 Mobile | PRECOMPILED_QNN_ONNX | 45.398 ms | 32 - 50 MB | NPU | Use Export Script | | controlnet | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | QNN_CONTEXT_BINARY | 34.868 ms | 1 - 18 MB | NPU | Use Export Script | | controlnet | w8a16 | Samsung Galaxy S25 | Snapdragon® 8 Elite For Galaxy Mobile | PRECOMPILED_QNN_ONNX | 32.913 ms | 33 - 45 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | QNN_CONTEXT_BINARY | 117.593 ms | 0 - 14 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon 7 Gen 4 QRD | Snapdragon® 7 Gen 4 Mobile | PRECOMPILED_QNN_ONNX | 113.375 ms | 20 - 32 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | QNN_CONTEXT_BINARY | 28.041 ms | 2 - 12 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon 8 Elite Gen 5 QRD | Snapdragon® 8 Elite Gen5 Mobile | PRECOMPILED_QNN_ONNX | 29.237 ms | 33 - 44 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | QNN_CONTEXT_BINARY | 67.472 ms | 2 - 2 MB | NPU | Use Export Script | | controlnet | w8a16 | Snapdragon X Elite CRD | Snapdragon® X Elite | PRECOMPILED_QNN_ONNX | 59.051 ms | 351 - 351 MB | NPU | Use Export Script | ## Installation Install the package via pip: ```bash # NOTE: 3.10 <= PYTHON_VERSION < 3.14 is supported. pip install "qai-hub-models[controlnet-canny]" ``` ## Configure Qualcomm® AI Hub Workbench to run this model on a cloud-hosted device Sign-in to [Qualcomm® AI Hub Workbench](https://workbench.aihub.qualcomm.com/) with your Qualcomm® ID. Once signed in navigate to `Account -> Settings -> API Token`. With this API token, you can configure your client to run models on the cloud hosted devices. ```bash qai-hub configure --api_token API_TOKEN ``` Navigate to [docs](https://workbench.aihub.qualcomm.com/docs/) for more information. ## Demo off target The package contains a simple end-to-end demo that downloads pre-trained weights and runs this model on a sample input. ```bash python -m qai_hub_models.models.controlnet_canny.demo ``` The above demo runs a reference implementation of pre-processing, model inference, and post processing. **NOTE**: If you want running in a Jupyter Notebook or Google Colab like environment, please add the following to your cell (instead of the above). ``` %run -m qai_hub_models.models.controlnet_canny.demo ``` ### Run model on a cloud-hosted device In addition to the demo, you can also run the model on a cloud-hosted Qualcomm® device. This script does the following: * Performance check on-device on a cloud-hosted device * Downloads compiled assets that can be deployed on-device for Android. * Accuracy check between PyTorch and on-device outputs. ```bash python -m qai_hub_models.models.controlnet_canny.export ``` ## Deploying compiled model to Android The models can be deployed using multiple runtimes: - TensorFlow Lite (`.tflite` export): [This tutorial](https://www.tensorflow.org/lite/android/quickstart) provides a guide to deploy the .tflite model in an Android application. - QNN (`.so` export ): This [sample app](https://docs.qualcomm.com/bundle/publicresource/topics/80-63442-50/sample_app.html) provides instructions on how to use the `.so` shared library in an Android application. ## View on Qualcomm® AI Hub Get more details on ControlNet-Canny's performance across various devices [here](https://aihub.qualcomm.com/models/controlnet_canny). Explore all available models on [Qualcomm® AI Hub](https://aihub.qualcomm.com/) ## License * The license for the original implementation of ControlNet-Canny can be found [here](https://github.com/lllyasviel/ControlNet/blob/main/LICENSE). ## References * [Adding Conditional Control to Text-to-Image Diffusion Models](https://arxiv.org/abs/2302.05543) * [Source Model Implementation](https://github.com/lllyasviel/ControlNet) ## Community * Join [our AI Hub Slack community](https://aihub.qualcomm.com/community/slack) to collaborate, post questions and learn more about on-device AI. * For questions or feedback please [reach out to us](mailto:ai-hub-support@qti.qualcomm.com).