Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
diffusers
Commits
6f75ef12
Commit
6f75ef12
authored
Jun 06, 2022
by
Patrick von Platen
Browse files
Merge branch 'main' of
https://github.com/huggingface/diffusers
into main
parents
8a79ed69
7ec721c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
README.md
README.md
+15
-16
No files found.
README.md
View file @
6f75ef12
...
@@ -67,10 +67,13 @@ for t in reversed(range(len(scheduler))):
...
@@ -67,10 +67,13 @@ for t in reversed(range(len(scheduler))):
sampled_prev_image
=
prev_image
+
prev_variance
sampled_prev_image
=
prev_image
+
prev_variance
image
=
sampled_prev_image
image
=
sampled_prev_image
# process image to PIL
image_processed
=
image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)
image_processed
=
image
.
cpu
().
permute
(
0
,
2
,
3
,
1
)
image_processed
=
(
image_processed
+
1.0
)
*
127.5
image_processed
=
(
image_processed
+
1.0
)
*
127.5
image_processed
=
image_processed
.
numpy
().
astype
(
np
.
uint8
)
image_processed
=
image_processed
.
numpy
().
astype
(
np
.
uint8
)
image_pil
=
PIL
.
Image
.
fromarray
(
image_processed
[
0
])
image_pil
=
PIL
.
Image
.
fromarray
(
image_processed
[
0
])
# save image
image_pil
.
save
(
"test.png"
)
image_pil
.
save
(
"test.png"
)
```
```
...
@@ -80,28 +83,24 @@ image_pil.save("test.png")
...
@@ -80,28 +83,24 @@ image_pil.save("test.png")
Example:
Example:
```
python
```
python
from
diffusers
import
UNetModel
,
GaussianDDPMScheduler
from
modeling_ddpm
import
DDPM
from
modeling_ddpm
import
DDPM
import
tempfile
import
PIL.Image
import
numpy
as
np
unet
=
UNetModel
.
from_pretrained
(
"fusing/ddpm_dummy"
)
# load model and scheduler
sampler
=
GaussianDDPMScheduler
.
from_config
(
"fusing/ddpm_dummy
"
)
ddpm
=
DDPM
.
from_pretrained
(
"fusing/ddpm-lsun-bedroom-pipe
"
)
# compose Diffusion Pipeline
# run pipeline in inference (sample random noise and denoise)
ddpm
=
DDPM
(
unet
,
sampler
)
# generate / sample
image
=
ddpm
()
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)
# save image
# will also be possible to do so from the Hub
image_pil
.
save
(
"test.png"
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
ddpm
.
save_pretrained
(
tmpdirname
)
print
(
"Model saved"
)
ddpm_new
=
DDPM
.
from_pretrained
(
tmpdirname
)
print
(
"Model loaded"
)
print
(
ddpm_new
)
```
```
## Library structure:
## Library structure:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment