Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
datasets:
|
3 |
+
- eurecom-ds/shapes3d
|
4 |
+
library_name: diffusers
|
5 |
+
pipeline_tag: Conditional Image Generation
|
6 |
+
---
|
7 |
+
|
8 |
+
```python
|
9 |
+
# !pip install diffusers
|
10 |
+
from diffusers import DiffusionPipeline
|
11 |
+
import torch
|
12 |
+
|
13 |
+
from PIL import Image
|
14 |
+
|
15 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
16 |
+
model_id = "eurecom-ds/scoresdeve-conditional-ema-shapes3d-64"
|
17 |
+
|
18 |
+
# load model and scheduler
|
19 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, trust_remote_code=True)
|
20 |
+
pipe.to(device)
|
21 |
+
|
22 |
+
|
23 |
+
# run pipeline in inference (sample random noise and denoise)
|
24 |
+
generator = torch.Generator(device=device).manual_seed(46)
|
25 |
+
class_labels = torch.tensor([[0, 0, 0, 0, 1, 0], # condition on shape cube
|
26 |
+
[0, 0, 0, 0, 2, 0], # condition on shape cylinder
|
27 |
+
[0, 0, 0, 0, 3, 0], # condition on shape sphere
|
28 |
+
[0, 0, 0, 0, 4, 0], # condition on shape capsule
|
29 |
+
[0, 0, 0, 0, 0, 0], # unconditional
|
30 |
+
[1, 1, 1, 1, 1, 1], # condition on red floor, object red, orientation right, small scale, shape cube, wall red
|
31 |
+
[0, 0, 0, 0, 0, 0], # unconditional
|
32 |
+
[0, 0, 0, 0, 0, 0], # uncondtional
|
33 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
34 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
35 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
36 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
37 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
38 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
39 |
+
[0, 0, 0, 0, 1, 0], # condition on shape cube
|
40 |
+
[0, 0, 0, 0, 1, 0] # condition on shape cube
|
41 |
+
]).to(device=pipe.device)
|
42 |
+
image = pipe(
|
43 |
+
generator=generator,
|
44 |
+
batch_size=16,
|
45 |
+
class_labels=class_labels,
|
46 |
+
num_inference_steps=1000
|
47 |
+
).images
|
48 |
+
width, height = image[0].size
|
49 |
+
|
50 |
+
# Create a new image with enough space for 2 rows x 8 columns
|
51 |
+
grid = Image.new('RGB', (width * 8, height * 2))
|
52 |
+
|
53 |
+
for index, img in enumerate(image):
|
54 |
+
x = index % 8 * width # Column index (0-7) times width of one image
|
55 |
+
y = index // 8 * height # Row index (0-1) times height of one image
|
56 |
+
grid.paste(img, (x, y))
|
57 |
+
|
58 |
+
# Save the final grid image
|
59 |
+
grid.save("sde_ve_conditional_generated_grid.png")
|
60 |
+
```
|
61 |
+

|