Spaces:
Runtime error
Runtime error
mrbgom2000
commited on
Commit
•
c10274f
1
Parent(s):
6858b77
Update NAhaha
Browse files
NAhaha
CHANGED
@@ -1,27 +1,23 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
import numpy as np
|
3 |
-
from flax.jax_utils import replicate
|
4 |
-
from flax.training.common_utils import shard
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
prompt = num_samples * [prompt]
|
19 |
-
prompt_ids = pipeline.prepare_inputs(prompt)
|
20 |
-
|
21 |
-
# shard inputs and rng
|
22 |
-
params = replicate(params)
|
23 |
-
prng_seed = jax.random.split(prng_seed, num_samples)
|
24 |
-
prompt_ids = shard(prompt_ids)
|
25 |
-
|
26 |
-
images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images
|
27 |
-
images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
|
|
|
1 |
+
from diffusers import DDPMScheduler, UNet2DModel
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
import numpy as np
|
|
|
|
|
5 |
|
6 |
+
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
|
7 |
+
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
|
8 |
+
scheduler.set_timesteps(50)
|
9 |
|
10 |
+
sample_size = model.config.sample_size
|
11 |
+
noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
|
12 |
+
input = noise
|
13 |
|
14 |
+
for t in scheduler.timesteps:
|
15 |
+
with torch.no_grad():
|
16 |
+
noisy_residual = model(input, t).sample
|
17 |
+
prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
|
18 |
+
input = prev_noisy_sample
|
19 |
|
20 |
+
image = (input / 2 + 0.5).clamp(0, 1)
|
21 |
+
image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
|
22 |
+
image = Image.fromarray((image * 255).round().astype("uint8"))
|
23 |
+
image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|