File size: 2,033 Bytes
649a29c
 
f1f325f
 
 
 
649a29c
f1f325f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
license: apache-2.0
tags:
- pytorch
- diffusers
- text-to-image
---

# Chinese ControlNet Model (Canny)

## 简介 Brief Introduction

我们开源了一个中文 ControlNet 模型,该模型适配 diffusion 模型 `alibaba-pai/pai-diffusion-artist-large-zh`,您可以使用该模型控制 diffusion 模型生成的图像。

We release a Chinese ControlNet model, which works with diffusion model `alibaba-pai/pai-diffusion-artist-large-zh`. You can use this model to control the diffusion model generating images as you wish.

* Github: [EasyNLP](https://github.com/alibaba/EasyNLP)

## 使用 Usage

```python
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
from transformers import pipeline
from PIL import Image
import numpy as np
import cv2


def to_canny(image):
    low_threshold = 100
    high_threshold = 200
    image = np.array(image)
    image = cv2.Canny(image, low_threshold, high_threshold)
    image = image[:, :, None]
    image = np.concatenate([image, image, image], axis=2)
    image = Image.fromarray(image)
    return image


controlnet_id = "alibaba-pai/pai-diffusion-artist-large-zh-controlnet-canny"
controlnet = ControlNetModel.from_pretrained(controlnet_id)
model_id = "alibaba-pai/pai-diffusion-artist-large-zh"
pipe = StableDiffusionControlNetPipeline.from_pretrained(model_id, controlnet=controlnet)
pipe = pipe.to("cuda")

image = Image.open("image.png")
controlnet_image = to_canny(image)
prompt = "白色羽毛的小鸟"
image = pipe(prompt, controlnet_image).images[0]

controlnet_image.save("image_canny.png")
image.save("image_canny_output.png")
```

## 使用须知 Notice for Use

使用上述模型需遵守[AIGC模型开源特别条款](https://terms.alicdn.com/legal-agreement/terms/common_platform_service/20230505180457947/20230505180457947.html)。

If you want to use this model, please read this [document](https://terms.alicdn.com/legal-agreement/terms/common_platform_service/20230505180457947/20230505180457947.html) carefully and abide by the terms.