# ControlNet

With Auto1111SDK, you can use ControlNet as follows:

1. Initialize a ControlNet model first. This can be done as follows:

```python
from auto1111sdk import ControlNetModel

model = ControlNetModel(model="<THE CONTROLNET MODEL FILE NAME (WITHOUT EXTENSION)>", 
                   image="<PATH TO IMAGE>")
```

&#x20;An example of this would be:

```
model = ControlNet(model="control_v11p_sd15_openpose", 
                   image="stock_mountain.png")
```

A full list of parameters is shown below:

<pre class="language-python"><code class="lang-python">model: str # The name of the model
image: str # The path to the image
weight: float = 1.0
resize_mode: int = 1
lowvram: bool = False
processor_res: int = 64
threshold_a: int = 64
threshold_b: int = 64
<strong>guidance_start: float = 0.0
</strong>guidance_end: float = 1.0
control_mode: int = 0
pixel_perfect: bool = False
</code></pre>

2. Add the controlnet model to the StableDiffusionPipeline for text-to-image or image-to-image

```
pipe = StableDiffusionPipeline("dreamshaper.safetensors", controlnet=model)
prompt = "closeup portrait photo of black dog, 8k uhd, high quality, cinematic"
negative_prompt = "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime), text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck"
output = pipe.generate_txt2img(num_images = 1, prompt = prompt, negative_prompt = negative_prompt, steps = 20)

output[0].save("huh.png")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flush-ai.gitbook.io/automatic-1111-sdk/pipelines/controlnet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
