mirror of
https://github.com/THUDM/CogVideo.git
synced 2025-12-02 18:52:08 +08:00
remove alpha channel from init
This commit is contained in:
parent
a150e9dab1
commit
903c2a98fc
16
predict.py
16
predict.py
@ -486,7 +486,7 @@ class Predictor(BasePredictor):
|
|||||||
description="Run both stages (uncheck to run more quickly and output only a few frames)", default=True
|
description="Run both stages (uncheck to run more quickly and output only a few frames)", default=True
|
||||||
),
|
),
|
||||||
use_guidance: bool = Input(description="Use stage 1 guidance (recommended)", default=True),
|
use_guidance: bool = Input(description="Use stage 1 guidance (recommended)", default=True),
|
||||||
image_prompt: Path = Input(description="Starting image", default=None)
|
image_prompt: Path = Input(description="Starting image (optional, prompt has little effect when used)", default=None)
|
||||||
) -> typing.Iterator[Path]:
|
) -> typing.Iterator[Path]:
|
||||||
if translate:
|
if translate:
|
||||||
prompt = self.translator.translate(prompt.strip())
|
prompt = self.translator.translate(prompt.strip())
|
||||||
@ -500,11 +500,15 @@ class Predictor(BasePredictor):
|
|||||||
self.image_prompt = None
|
self.image_prompt = None
|
||||||
if os.path.exists(str(image_prompt)):
|
if os.path.exists(str(image_prompt)):
|
||||||
try:
|
try:
|
||||||
Image.open(str(image_prompt))
|
image = Image.open(str(image_prompt)).convert("RGBA")
|
||||||
|
# Remove alpha channel if present
|
||||||
|
bg = Image.new("RGBA", image.size, (255, 255, 255))
|
||||||
|
image = Image.alpha_composite(bg, image).convert("RGB")
|
||||||
|
imagefile = f'{tempfile.mkdtemp()}/input.png'
|
||||||
|
image.save(imagefile, format="png")
|
||||||
|
self.image_prompt = imagefile
|
||||||
except (FileNotFoundError, UnidentifiedImageError):
|
except (FileNotFoundError, UnidentifiedImageError):
|
||||||
logging.debug("Bad image prompt; ignoring") # Is there a better way to input images?
|
logging.debug("Bad image prompt; ignoring") # Is there a better way to input images?
|
||||||
else:
|
|
||||||
self.image_prompt = str(image_prompt)
|
|
||||||
self.args.both_stages = both_stages
|
self.args.both_stages = both_stages
|
||||||
|
|
||||||
for file in self.run():
|
for file in self.run():
|
||||||
@ -805,4 +809,4 @@ class Predictor(BasePredictor):
|
|||||||
my_save_multiple_images(decoded_videos[sample_i], outputdir,subdir=f"frames/{sample_i+sample_num*gpu_rank}", debug=False)
|
my_save_multiple_images(decoded_videos[sample_i], outputdir,subdir=f"frames/{sample_i+sample_num*gpu_rank}", debug=False)
|
||||||
output_file = f"{outputdir}/{sample_i+sample_num*gpu_rank}.gif"
|
output_file = f"{outputdir}/{sample_i+sample_num*gpu_rank}.gif"
|
||||||
subprocess.check_output(f"gifmaker -i '{outputdir}'/frames/'{sample_i+sample_num*gpu_rank}'/0*.jpg -o '{output_file}' -d 0.125", shell=True)
|
subprocess.check_output(f"gifmaker -i '{outputdir}'/frames/'{sample_i+sample_num*gpu_rank}'/0*.jpg -o '{output_file}' -d 0.125", shell=True)
|
||||||
yield output_file
|
yield output_file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user