Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- video_to_video/utils/__init__.py +0 -0
- video_to_video/utils/config.py +169 -0
- video_to_video/utils/logger.py +94 -0
- video_to_video/utils/seed.py +14 -0
video_to_video/utils/__init__.py
ADDED
|
File without changes
|
video_to_video/utils/config.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import os
|
| 5 |
+
import os.path as osp
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from easydict import EasyDict
|
| 10 |
+
|
| 11 |
+
cfg = EasyDict(__name__='Config: VideoLDM Decoder')
|
| 12 |
+
|
| 13 |
+
# ---------------------------work dir--------------------------
|
| 14 |
+
cfg.work_dir = 'workspace/'
|
| 15 |
+
|
| 16 |
+
# ---------------------------Global Variable-----------------------------------
|
| 17 |
+
cfg.resolution = [448, 256]
|
| 18 |
+
cfg.max_frames = 32
|
| 19 |
+
# -----------------------------------------------------------------------------
|
| 20 |
+
|
| 21 |
+
# ---------------------------Dataset Parameter---------------------------------
|
| 22 |
+
cfg.mean = [0.5, 0.5, 0.5]
|
| 23 |
+
cfg.std = [0.5, 0.5, 0.5]
|
| 24 |
+
cfg.max_words = 1000
|
| 25 |
+
|
| 26 |
+
# PlaceHolder
|
| 27 |
+
cfg.vit_out_dim = 1024
|
| 28 |
+
cfg.vit_resolution = [224, 224]
|
| 29 |
+
cfg.depth_clamp = 10.0
|
| 30 |
+
cfg.misc_size = 384
|
| 31 |
+
cfg.depth_std = 20.0
|
| 32 |
+
|
| 33 |
+
cfg.frame_lens = 32
|
| 34 |
+
cfg.sample_fps = 8
|
| 35 |
+
|
| 36 |
+
cfg.batch_sizes = 1
|
| 37 |
+
# -----------------------------------------------------------------------------
|
| 38 |
+
|
| 39 |
+
# ---------------------------Mode Parameters-----------------------------------
|
| 40 |
+
# Diffusion
|
| 41 |
+
cfg.schedule = 'cosine'
|
| 42 |
+
cfg.num_timesteps = 1000
|
| 43 |
+
cfg.mean_type = 'v'
|
| 44 |
+
cfg.var_type = 'fixed_small'
|
| 45 |
+
cfg.loss_type = 'mse'
|
| 46 |
+
cfg.ddim_timesteps = 50
|
| 47 |
+
cfg.ddim_eta = 0.0
|
| 48 |
+
cfg.clamp = 1.0
|
| 49 |
+
cfg.share_noise = False
|
| 50 |
+
cfg.use_div_loss = False
|
| 51 |
+
cfg.noise_strength = 0.1
|
| 52 |
+
|
| 53 |
+
# classifier-free guidance
|
| 54 |
+
cfg.p_zero = 0.1
|
| 55 |
+
cfg.guide_scale = 3.0
|
| 56 |
+
|
| 57 |
+
# clip vision encoder
|
| 58 |
+
cfg.vit_mean = [0.48145466, 0.4578275, 0.40821073]
|
| 59 |
+
cfg.vit_std = [0.26862954, 0.26130258, 0.27577711]
|
| 60 |
+
|
| 61 |
+
# Model
|
| 62 |
+
cfg.scale_factor = 0.18215
|
| 63 |
+
cfg.use_fp16 = True
|
| 64 |
+
cfg.temporal_attention = True
|
| 65 |
+
cfg.decoder_bs = 8
|
| 66 |
+
|
| 67 |
+
cfg.UNet = {
|
| 68 |
+
'type': 'Vid2VidSDUNet',
|
| 69 |
+
'in_dim': 4,
|
| 70 |
+
'dim': 320,
|
| 71 |
+
'y_dim': cfg.vit_out_dim,
|
| 72 |
+
'context_dim': 1024,
|
| 73 |
+
'out_dim': 8 if cfg.var_type.startswith('learned') else 4,
|
| 74 |
+
'dim_mult': [1, 2, 4, 4],
|
| 75 |
+
'num_heads': 8,
|
| 76 |
+
'head_dim': 64,
|
| 77 |
+
'num_res_blocks': 2,
|
| 78 |
+
'attn_scales': [1 / 1, 1 / 2, 1 / 4],
|
| 79 |
+
'dropout': 0.1,
|
| 80 |
+
'temporal_attention': cfg.temporal_attention,
|
| 81 |
+
'temporal_attn_times': 1,
|
| 82 |
+
'use_checkpoint': False,
|
| 83 |
+
'use_fps_condition': False,
|
| 84 |
+
'use_sim_mask': False,
|
| 85 |
+
'num_tokens': 4,
|
| 86 |
+
'default_fps': 8,
|
| 87 |
+
'input_dim': 1024
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
cfg.guidances = []
|
| 91 |
+
|
| 92 |
+
# auotoencoder from stabel diffusion
|
| 93 |
+
cfg.auto_encoder = {
|
| 94 |
+
'type': 'AutoencoderKL',
|
| 95 |
+
'ddconfig': {
|
| 96 |
+
'double_z': True,
|
| 97 |
+
'z_channels': 4,
|
| 98 |
+
'resolution': 256,
|
| 99 |
+
'in_channels': 3,
|
| 100 |
+
'out_ch': 3,
|
| 101 |
+
'ch': 128,
|
| 102 |
+
'ch_mult': [1, 2, 4, 4],
|
| 103 |
+
'num_res_blocks': 2,
|
| 104 |
+
'attn_resolutions': [],
|
| 105 |
+
'dropout': 0.0
|
| 106 |
+
},
|
| 107 |
+
'embed_dim': 4,
|
| 108 |
+
'pretrained': 'models/v2-1_512-ema-pruned.ckpt'
|
| 109 |
+
}
|
| 110 |
+
# clip embedder
|
| 111 |
+
cfg.embedder = {
|
| 112 |
+
'type': 'FrozenOpenCLIPEmbedder',
|
| 113 |
+
'layer': 'penultimate',
|
| 114 |
+
'vit_resolution': [224, 224],
|
| 115 |
+
'pretrained': 'open_clip_pytorch_model.bin'
|
| 116 |
+
}
|
| 117 |
+
# -----------------------------------------------------------------------------
|
| 118 |
+
|
| 119 |
+
# ---------------------------Training Settings---------------------------------
|
| 120 |
+
# training and optimizer
|
| 121 |
+
cfg.ema_decay = 0.9999
|
| 122 |
+
cfg.num_steps = 600000
|
| 123 |
+
cfg.lr = 5e-5
|
| 124 |
+
cfg.weight_decay = 0.0
|
| 125 |
+
cfg.betas = (0.9, 0.999)
|
| 126 |
+
cfg.eps = 1.0e-8
|
| 127 |
+
cfg.chunk_size = 16
|
| 128 |
+
cfg.alpha = 0.7
|
| 129 |
+
cfg.save_ckp_interval = 1000
|
| 130 |
+
# -----------------------------------------------------------------------------
|
| 131 |
+
|
| 132 |
+
# ----------------------------Pretrain Settings---------------------------------
|
| 133 |
+
# Default: load 2d pretrain
|
| 134 |
+
cfg.fix_weight = False
|
| 135 |
+
cfg.load_match = False
|
| 136 |
+
cfg.pretrained_checkpoint = 'v2-1_512-ema-pruned.ckpt'
|
| 137 |
+
cfg.pretrained_image_keys = 'stable_diffusion_image_key_temporal_attention_x1.json'
|
| 138 |
+
cfg.resume_checkpoint = 'img2video_ldm_0779000.pth'
|
| 139 |
+
# -----------------------------------------------------------------------------
|
| 140 |
+
|
| 141 |
+
# -----------------------------Visual-------------------------------------------
|
| 142 |
+
# Visual videos
|
| 143 |
+
cfg.viz_interval = 1000
|
| 144 |
+
cfg.visual_train = {
|
| 145 |
+
'type': 'VisualVideoTextDuringTrain',
|
| 146 |
+
}
|
| 147 |
+
cfg.visual_inference = {
|
| 148 |
+
'type': 'VisualGeneratedVideos',
|
| 149 |
+
}
|
| 150 |
+
cfg.inference_list_path = ''
|
| 151 |
+
|
| 152 |
+
# logging
|
| 153 |
+
cfg.log_interval = 100
|
| 154 |
+
|
| 155 |
+
# Default log_dir
|
| 156 |
+
cfg.log_dir = 'workspace/output_data'
|
| 157 |
+
# -----------------------------------------------------------------------------
|
| 158 |
+
|
| 159 |
+
# ---------------------------Others--------------------------------------------
|
| 160 |
+
# seed
|
| 161 |
+
cfg.seed = 8888
|
| 162 |
+
|
| 163 |
+
cfg.negative_prompt = 'painting, oil painting, illustration, drawing, art, sketch, oil painting, cartoon, \
|
| 164 |
+
CG Style, 3D render, unreal engine, blurring, dirty, messy, worst quality, low quality, frames, watermark, \
|
| 165 |
+
signature, jpeg artifacts, deformed, lowres, over-smooth'
|
| 166 |
+
|
| 167 |
+
cfg.positive_prompt = 'Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, \
|
| 168 |
+
hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, \
|
| 169 |
+
skin pore detailing, hyper sharpness, perfect without deformations.'
|
video_to_video/utils/logger.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
| 2 |
+
|
| 3 |
+
import importlib
|
| 4 |
+
import logging
|
| 5 |
+
from typing import Optional
|
| 6 |
+
from torch import distributed as dist
|
| 7 |
+
|
| 8 |
+
init_loggers = {}
|
| 9 |
+
|
| 10 |
+
formatter = logging.Formatter(
|
| 11 |
+
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_logger(log_file: Optional[str] = None,
|
| 15 |
+
log_level: int = logging.INFO,
|
| 16 |
+
file_mode: str = 'w'):
|
| 17 |
+
""" Get logging logger
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
log_file: Log filename, if specified, file handler will be added to
|
| 21 |
+
logger
|
| 22 |
+
log_level: Logging level.
|
| 23 |
+
file_mode: Specifies the mode to open the file, if filename is
|
| 24 |
+
specified (if filemode is unspecified, it defaults to 'w').
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
logger_name = __name__.split('.')[0]
|
| 28 |
+
logger = logging.getLogger(logger_name)
|
| 29 |
+
logger.propagate = False
|
| 30 |
+
if logger_name in init_loggers:
|
| 31 |
+
add_file_handler_if_needed(logger, log_file, file_mode, log_level)
|
| 32 |
+
return logger
|
| 33 |
+
|
| 34 |
+
# handle duplicate logs to the console
|
| 35 |
+
# Starting in 1.8.0, PyTorch DDP attaches a StreamHandler <stderr> (NOTSET)
|
| 36 |
+
# to the root logger. As logger.propagate is True by default, this root
|
| 37 |
+
# level handler causes logging messages from rank>0 processes to
|
| 38 |
+
# unexpectedly show up on the console, creating much unwanted clutter.
|
| 39 |
+
# To fix this issue, we set the root logger's StreamHandler, if any, to log
|
| 40 |
+
# at the ERROR level.
|
| 41 |
+
for handler in logger.root.handlers:
|
| 42 |
+
if type(handler) is logging.StreamHandler:
|
| 43 |
+
handler.setLevel(logging.ERROR)
|
| 44 |
+
|
| 45 |
+
stream_handler = logging.StreamHandler()
|
| 46 |
+
handlers = [stream_handler]
|
| 47 |
+
|
| 48 |
+
if importlib.util.find_spec('torch') is not None:
|
| 49 |
+
is_worker0 = is_master()
|
| 50 |
+
else:
|
| 51 |
+
is_worker0 = True
|
| 52 |
+
|
| 53 |
+
if is_worker0 and log_file is not None:
|
| 54 |
+
file_handler = logging.FileHandler(log_file, file_mode)
|
| 55 |
+
handlers.append(file_handler)
|
| 56 |
+
|
| 57 |
+
for handler in handlers:
|
| 58 |
+
handler.setFormatter(formatter)
|
| 59 |
+
handler.setLevel(log_level)
|
| 60 |
+
logger.addHandler(handler)
|
| 61 |
+
|
| 62 |
+
if is_worker0:
|
| 63 |
+
logger.setLevel(log_level)
|
| 64 |
+
else:
|
| 65 |
+
logger.setLevel(logging.ERROR)
|
| 66 |
+
|
| 67 |
+
init_loggers[logger_name] = True
|
| 68 |
+
|
| 69 |
+
return logger
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def add_file_handler_if_needed(logger, log_file, file_mode, log_level):
|
| 73 |
+
for handler in logger.handlers:
|
| 74 |
+
if isinstance(handler, logging.FileHandler):
|
| 75 |
+
return
|
| 76 |
+
|
| 77 |
+
if importlib.util.find_spec('torch') is not None:
|
| 78 |
+
is_worker0 = is_master()
|
| 79 |
+
else:
|
| 80 |
+
is_worker0 = True
|
| 81 |
+
|
| 82 |
+
if is_worker0 and log_file is not None:
|
| 83 |
+
file_handler = logging.FileHandler(log_file, file_mode)
|
| 84 |
+
file_handler.setFormatter(formatter)
|
| 85 |
+
file_handler.setLevel(log_level)
|
| 86 |
+
logger.addHandler(file_handler)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def is_master(group=None):
|
| 90 |
+
return dist.get_rank(group) == 0 if is_dist() else True
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def is_dist():
|
| 94 |
+
return dist.is_available() and dist.is_initialized()
|
video_to_video/utils/seed.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Alibaba, Inc. and its affiliates.
|
| 2 |
+
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def setup_seed(seed):
|
| 10 |
+
torch.manual_seed(seed)
|
| 11 |
+
torch.cuda.manual_seed_all(seed)
|
| 12 |
+
np.random.seed(seed)
|
| 13 |
+
random.seed(seed)
|
| 14 |
+
torch.backends.cudnn.deterministic = True
|