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
a4b2c2f1
Unverified
Commit
a4b2c2f1
authored
Mar 16, 2023
by
Will Berman
Committed by
GitHub
Mar 16, 2023
Browse files
train_unconditional save restore unet parameters (#2706)
parent
77e0ea80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
examples/unconditional_image_generation/train_unconditional.py
...les/unconditional_image_generation/train_unconditional.py
+21
-0
No files found.
examples/unconditional_image_generation/train_unconditional.py
View file @
a4b2c2f1
...
@@ -625,8 +625,11 @@ def main(args):
...
@@ -625,8 +625,11 @@ def main(args):
if
accelerator
.
is_main_process
:
if
accelerator
.
is_main_process
:
if
epoch
%
args
.
save_images_epochs
==
0
or
epoch
==
args
.
num_epochs
-
1
:
if
epoch
%
args
.
save_images_epochs
==
0
or
epoch
==
args
.
num_epochs
-
1
:
unet
=
accelerator
.
unwrap_model
(
model
)
unet
=
accelerator
.
unwrap_model
(
model
)
if
args
.
use_ema
:
if
args
.
use_ema
:
ema_model
.
store
(
unet
.
parameters
())
ema_model
.
copy_to
(
unet
.
parameters
())
ema_model
.
copy_to
(
unet
.
parameters
())
pipeline
=
DDPMPipeline
(
pipeline
=
DDPMPipeline
(
unet
=
unet
,
unet
=
unet
,
scheduler
=
noise_scheduler
,
scheduler
=
noise_scheduler
,
...
@@ -641,6 +644,9 @@ def main(args):
...
@@ -641,6 +644,9 @@ def main(args):
output_type
=
"numpy"
,
output_type
=
"numpy"
,
).
images
).
images
if
args
.
use_ema
:
ema_model
.
restore
(
unet
.
parameters
())
# denormalize the images and save to tensorboard
# denormalize the images and save to tensorboard
images_processed
=
(
images
*
255
).
round
().
astype
(
"uint8"
)
images_processed
=
(
images
*
255
).
round
().
astype
(
"uint8"
)
...
@@ -659,7 +665,22 @@ def main(args):
...
@@ -659,7 +665,22 @@ def main(args):
if
epoch
%
args
.
save_model_epochs
==
0
or
epoch
==
args
.
num_epochs
-
1
:
if
epoch
%
args
.
save_model_epochs
==
0
or
epoch
==
args
.
num_epochs
-
1
:
# save the model
# save the model
unet
=
accelerator
.
unwrap_model
(
model
)
if
args
.
use_ema
:
ema_model
.
store
(
unet
.
parameters
())
ema_model
.
copy_to
(
unet
.
parameters
())
pipeline
=
DDPMPipeline
(
unet
=
unet
,
scheduler
=
noise_scheduler
,
)
pipeline
.
save_pretrained
(
args
.
output_dir
)
pipeline
.
save_pretrained
(
args
.
output_dir
)
if
args
.
use_ema
:
ema_model
.
restore
(
unet
.
parameters
())
if
args
.
push_to_hub
:
if
args
.
push_to_hub
:
repo
.
push_to_hub
(
commit_message
=
f
"Epoch
{
epoch
}
"
,
blocking
=
False
)
repo
.
push_to_hub
(
commit_message
=
f
"Epoch
{
epoch
}
"
,
blocking
=
False
)
...
...
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