Merge branch 'main' of https://github.com/huggingface/diffusers into main
This commit is contained in:
commit
6f75ef12d4
31
README.md
31
README.md
|
@ -67,10 +67,13 @@ for t in reversed(range(len(scheduler))):
|
|||
sampled_prev_image = prev_image + prev_variance
|
||||
image = sampled_prev_image
|
||||
|
||||
# process image to PIL
|
||||
image_processed = image.cpu().permute(0, 2, 3, 1)
|
||||
image_processed = (image_processed + 1.0) * 127.5
|
||||
image_processed = image_processed.numpy().astype(np.uint8)
|
||||
image_pil = PIL.Image.fromarray(image_processed[0])
|
||||
|
||||
# save image
|
||||
image_pil.save("test.png")
|
||||
```
|
||||
|
||||
|
@ -80,28 +83,24 @@ image_pil.save("test.png")
|
|||
Example:
|
||||
|
||||
```python
|
||||
from diffusers import UNetModel, GaussianDDPMScheduler
|
||||
from modeling_ddpm import DDPM
|
||||
import tempfile
|
||||
import PIL.Image
|
||||
import numpy as np
|
||||
|
||||
unet = UNetModel.from_pretrained("fusing/ddpm_dummy")
|
||||
sampler = GaussianDDPMScheduler.from_config("fusing/ddpm_dummy")
|
||||
# load model and scheduler
|
||||
ddpm = DDPM.from_pretrained("fusing/ddpm-lsun-bedroom-pipe")
|
||||
|
||||
# compose Diffusion Pipeline
|
||||
ddpm = DDPM(unet, sampler)
|
||||
# generate / sample
|
||||
# run pipeline in inference (sample random noise and denoise)
|
||||
image = ddpm()
|
||||
print(image)
|
||||
|
||||
# process image to PIL
|
||||
image_processed = image.cpu().permute(0, 2, 3, 1)
|
||||
image_processed = (image_processed + 1.0) * 127.5
|
||||
image_processed = image_processed.numpy().astype(np.uint8)
|
||||
image_pil = PIL.Image.fromarray(image_processed[0])
|
||||
|
||||
# save and load with 0 extra code (handled by general `DiffusionPipeline` class)
|
||||
# will also be possible to do so from the Hub
|
||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||
ddpm.save_pretrained(tmpdirname)
|
||||
print("Model saved")
|
||||
ddpm_new = DDPM.from_pretrained(tmpdirname)
|
||||
print("Model loaded")
|
||||
print(ddpm_new)
|
||||
# save image
|
||||
image_pil.save("test.png")
|
||||
```
|
||||
|
||||
## Library structure:
|
||||
|
|
Loading…
Reference in New Issue