Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model:
|
3 |
+
- stabilityai/stable-diffusion-2-inpainting
|
4 |
+
- stabilityai/stable-diffusion-2-1
|
5 |
+
pipeline_tag: image-to-image
|
6 |
+
---
|
7 |
+
```
|
8 |
+
from transformers import AutoConfig, AutoModel, ModelCard
|
9 |
+
|
10 |
+
# Load the gray-inpaint model
|
11 |
+
gray_inpaintor = AutoModel.from_pretrained(
|
12 |
+
'jwengr/stable-diffusion-2-gray-inpaint-to-rgb',
|
13 |
+
subfolder='gray-inpaint',
|
14 |
+
trust_remote_code=True,
|
15 |
+
)
|
16 |
+
|
17 |
+
# Load the gray2rgb model
|
18 |
+
gray2rgb = AutoModel.from_pretrained(
|
19 |
+
'jwengr/stable-diffusion-2-gray-inpaint-to-rgb',
|
20 |
+
subfolder='gray2rgb',
|
21 |
+
trust_remote_code=True,
|
22 |
+
)
|
23 |
+
|
24 |
+
|
25 |
+
# Move models to GPU
|
26 |
+
gray2rgb.to('cuda')
|
27 |
+
gray_inpaintor.to('cuda')
|
28 |
+
|
29 |
+
# Enable memory-efficient attention for xFormers
|
30 |
+
gray2rgb.unet.enable_xformers_memory_efficient_attention()
|
31 |
+
gray_inpaintor.unet.enable_xformers_memory_efficient_attention()
|
32 |
+
|
33 |
+
# Generate images using gray_inpaintor and gray2rgb
|
34 |
+
image_gray_restored = gray_inpaintor(batch, seed=inpaint_seed)
|
35 |
+
image_gray_restored = [img.convert('RGB') for img in image_gray_restored]
|
36 |
+
image_restored_pil = gray2rgb(image_gray_restored)
|
37 |
+
image_restored_pt = gray2rgb(image_gray_restored, output_type='pt')
|
38 |
+
```
|