File size: 4,044 Bytes
4c53d64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# 'Deforum' plugin for Automatic1111's Stable Diffusion WebUI.
# Copyright (C) 2023 Artem Khrapov (kabachuha) and Deforum team listed in AUTHORS.md
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Contact the dev team: https://discord.gg/deforum
import os
from math import ceil
import tqdm
from modules.shared import progress_print_out, opts, cmd_opts
class DeforumTQDM:
def __init__(self, args, anim_args, parseq_args, video_args):
self._tqdm = None
self._args = args
self._anim_args = anim_args
self._parseq_args = parseq_args
self._video_args = video_args
def reset(self):
from .animation_key_frames import DeformAnimKeys
from .parseq_adapter import ParseqAnimKeys
deforum_total = 0
# FIXME: get only amount of steps
use_parseq = self._parseq_args.parseq_manifest is not None and self._parseq_args.parseq_manifest.strip()
keys = DeformAnimKeys(self._anim_args) if not use_parseq else ParseqAnimKeys(self._parseq_args, self._anim_args, self._video_args, mute=True)
start_frame = 0
if self._anim_args.resume_from_timestring:
for tmp in os.listdir(self._args.outdir):
filename = tmp.split("_")
# don't use saved depth maps to count number of frames
if self._anim_args.resume_timestring in filename and "depth" not in filename:
start_frame += 1
start_frame = start_frame - 1
using_vid_init = self._anim_args.animation_mode == 'Video Input'
turbo_steps = 1 if using_vid_init else int(self._anim_args.diffusion_cadence)
if self._anim_args.resume_from_timestring:
last_frame = start_frame - 1
if turbo_steps > 1:
last_frame -= last_frame % turbo_steps
if turbo_steps > 1:
turbo_next_frame_idx = last_frame
turbo_prev_frame_idx = turbo_next_frame_idx
start_frame = last_frame + turbo_steps
frame_idx = start_frame
had_first = False
while frame_idx < self._anim_args.max_frames:
strength = keys.strength_schedule_series[frame_idx]
if not had_first and self._args.use_init and self._args.init_image is not None and self._args.init_image != '':
deforum_total += int(ceil(self._args.steps * (1 - strength)))
had_first = True
elif not had_first:
deforum_total += self._args.steps
had_first = True
else:
deforum_total += int(ceil(self._args.steps * (1 - strength)))
if turbo_steps > 1:
frame_idx += turbo_steps
else:
frame_idx += 1
self._tqdm = tqdm.tqdm(
desc="Deforum progress",
total=deforum_total,
position=1,
file=progress_print_out
)
def update(self):
if not opts.multiple_tqdm or cmd_opts.disable_console_progressbars:
return
if self._tqdm is None:
self.reset()
self._tqdm.update()
def updateTotal(self, new_total):
if not opts.multiple_tqdm or cmd_opts.disable_console_progressbars:
return
if self._tqdm is None:
self.reset()
self._tqdm.total = new_total
def clear(self):
if self._tqdm is not None:
self._tqdm.close()
self._tqdm = None
|