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
OpenDAS
diffusers
Commits
46dae846
Commit
46dae846
authored
Jun 08, 2022
by
Patrick von Platen
Browse files
add clip to ddim
parent
485797b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
models/vision/ddim/example.py
models/vision/ddim/example.py
+23
-0
models/vision/ddim/modeling_ddim.py
models/vision/ddim/modeling_ddim.py
+1
-0
No files found.
models/vision/ddim/example.py
0 → 100755
View file @
46dae846
#!/usr/bin/env python3
import
os
import
pathlib
from
modeling_ddim
import
DDIM
import
PIL.Image
import
numpy
as
np
model_ids
=
[
"ddim-celeba-hq"
,
"ddim-lsun-church"
,
"ddim-lsun-bedroom"
]
for
model_id
in
model_ids
:
path
=
os
.
path
.
join
(
"/home/patrick/images/hf"
,
model_id
)
pathlib
.
Path
(
path
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
ddpm
=
DDIM
.
from_pretrained
(
"fusing/"
+
model_id
)
image
=
ddpm
(
batch_size
=
4
)
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
)
for
i
in
range
(
image_processed
.
shape
[
0
]):
image_pil
=
PIL
.
Image
.
fromarray
(
image_processed
[
i
])
image_pil
.
save
(
os
.
path
.
join
(
path
,
f
"image_
{
i
}
.png"
))
models/vision/ddim/modeling_ddim.py
View file @
46dae846
...
@@ -59,6 +59,7 @@ class DDIM(DiffusionPipeline):
...
@@ -59,6 +59,7 @@ class DDIM(DiffusionPipeline):
# predict mean of prev image
# predict mean of prev image
pred_mean
=
alpha_prod_t_rsqrt
*
(
image
-
beta_prod_t_sqrt
*
noise_residual
)
pred_mean
=
alpha_prod_t_rsqrt
*
(
image
-
beta_prod_t_sqrt
*
noise_residual
)
pred_mean
=
torch
.
clamp
(
pred_mean
,
-
1
,
1
)
pred_mean
=
(
1
/
alpha_prod_t_prev_rsqrt
)
*
pred_mean
+
coeff_2
*
noise_residual
pred_mean
=
(
1
/
alpha_prod_t_prev_rsqrt
)
*
pred_mean
+
coeff_2
*
noise_residual
# if eta > 0.0 add noise. Note eta = 1.0 essentially corresponds to DDPM
# if eta > 0.0 add noise. Note eta = 1.0 essentially corresponds to DDPM
...
...
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