Commit ·
987db9c
1
Parent(s): dce20cf
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
A model trained with Pyramid Noise - see https://wandb.ai/johnowhitaker/multires_noise/reports/Multi-Resolution-Noise-for-Diffusion-Model-Training--VmlldzozNjYyOTU2 for details
|
| 2 |
+
|
| 3 |
+
```python
|
| 4 |
+
from torch import nn
|
| 5 |
+
import random
|
| 6 |
+
|
| 7 |
+
def pyramid_noise_like(x, discount=0.9):
|
| 8 |
+
b, c, w, h = x.shape
|
| 9 |
+
u = nn.Upsample(size=(w, h), mode='bilinear')
|
| 10 |
+
noise = torch.randn_like(x)
|
| 11 |
+
for i in range(6):
|
| 12 |
+
r = random.random()*2+2 # Rather than always going 2x,
|
| 13 |
+
w, h = max(1, int(w/(r**i))), max(1, int(h/(r**i)))
|
| 14 |
+
noise += u(torch.randn(b, c, w, h).to(x)) * discount**i
|
| 15 |
+
if w==1 or h==1: break
|
| 16 |
+
return noise / noise.std() # Scale back to unit variance
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
To use the mode for inference, just load it like a normal stable diffusion pipeline:
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
from diffusers import StableDiffusionPipeline
|
| 23 |
+
|
| 24 |
+
model_path = "pyramid_noise_test_500steps"
|
| 25 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)
|
| 26 |
+
pipe.to("cuda")
|
| 27 |
+
|
| 28 |
+
image = pipe(prompt="A black image").images[0]
|
| 29 |
+
image
|
| 30 |
+
```
|