Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
b3b04fef
Unverified
Commit
b3b04fef
authored
Apr 28, 2025
by
tongyu
Committed by
GitHub
Apr 28, 2025
Browse files
[train_text_to_image] Better image interpolation in training scripts follow up (#11426)
* Update train_text_to_image.py * update
parent
0e3f2713
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
examples/text_to_image/train_text_to_image.py
examples/text_to_image/train_text_to_image.py
+18
-2
No files found.
examples/text_to_image/train_text_to_image.py
View file @
b3b04fef
...
...
@@ -499,6 +499,15 @@ def parse_args():
" more information see https://huggingface.co/docs/accelerate/v0.17.0/en/package_reference/accelerator#accelerate.Accelerator"
),
)
parser
.
add_argument
(
"--image_interpolation_mode"
,
type
=
str
,
default
=
"lanczos"
,
choices
=
[
f
.
lower
()
for
f
in
dir
(
transforms
.
InterpolationMode
)
if
not
f
.
startswith
(
"__"
)
and
not
f
.
endswith
(
"__"
)
],
help
=
"The image interpolation method to use for resizing images."
,
)
args
=
parser
.
parse_args
()
env_local_rank
=
int
(
os
.
environ
.
get
(
"LOCAL_RANK"
,
-
1
))
...
...
@@ -787,10 +796,17 @@ def main():
)
return
inputs
.
input_ids
# Preprocessing the datasets.
# Get the specified interpolation method from the args
interpolation
=
getattr
(
transforms
.
InterpolationMode
,
args
.
image_interpolation_mode
.
upper
(),
None
)
# Raise an error if the interpolation method is invalid
if
interpolation
is
None
:
raise
ValueError
(
f
"Unsupported interpolation mode
{
args
.
image_interpolation_mode
}
."
)
# Data preprocessing transformations
train_transforms
=
transforms
.
Compose
(
[
transforms
.
Resize
(
args
.
resolution
,
interpolation
=
transforms
.
InterpolationMode
.
BILINEAR
),
transforms
.
Resize
(
args
.
resolution
,
interpolation
=
interpolation
),
# Use dynamic interpolation method
transforms
.
CenterCrop
(
args
.
resolution
)
if
args
.
center_crop
else
transforms
.
RandomCrop
(
args
.
resolution
),
transforms
.
RandomHorizontalFlip
()
if
args
.
random_flip
else
transforms
.
Lambda
(
lambda
x
:
x
),
transforms
.
ToTensor
(),
...
...
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