jadechoghari
commited on
Commit
•
59e9a43
1
Parent(s):
a9b9304
Update pipeline.py
Browse files- pipeline.py +53 -28
pipeline.py
CHANGED
@@ -95,44 +95,69 @@ class VidToMePipeline(DiffusionPipeline):
|
|
95 |
from omegaconf import OmegaConf
|
96 |
|
97 |
def _build_config(self, video_path, video_prompt, edit_prompt, control_type,
|
98 |
-
|
99 |
-
|
100 |
-
#
|
101 |
config = OmegaConf.create({
|
102 |
-
'sd_version':
|
103 |
-
'
|
104 |
-
'
|
105 |
-
'work_dir': "
|
106 |
-
'height':
|
107 |
-
'width':
|
108 |
'inversion': {
|
|
|
109 |
'prompt': video_prompt or "Default video prompt.",
|
110 |
-
'
|
111 |
-
'steps': 50,
|
112 |
-
'
|
113 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
},
|
115 |
'generation': {
|
116 |
-
'control':
|
117 |
-
'
|
118 |
-
'
|
119 |
-
'
|
120 |
-
'
|
121 |
-
'
|
122 |
-
'
|
123 |
-
'
|
124 |
-
'
|
125 |
-
'
|
126 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
},
|
128 |
-
'seed': seed,
|
129 |
-
'device': "cuda",
|
130 |
-
'float_precision': "fp16",
|
131 |
-
'enable_xformers_memory_efficient_attention': True
|
132 |
})
|
133 |
|
134 |
return config
|
135 |
|
|
|
136 |
# # Sample usage
|
137 |
# pipeline = VidToMePipeline(device="cuda", sd_version="2.1", float_precision="fp16")
|
138 |
# pipeline(video_path="path/to/video.mp4", video_prompt="A beautiful scene of a sunset",
|
|
|
95 |
from omegaconf import OmegaConf
|
96 |
|
97 |
def _build_config(self, video_path, video_prompt, edit_prompt, control_type,
|
98 |
+
n_timesteps, guidance_scale, negative_prompt, frame_range,
|
99 |
+
use_lora, seed, local_merge_ratio, global_merge_ratio):
|
100 |
+
# Build config using OmegaConf, abstracting as much as possible
|
101 |
config = OmegaConf.create({
|
102 |
+
'sd_version': self.sd_version, # Default sd_version
|
103 |
+
'model_key': self.model_key or None, # Optionally allow model_key to be None
|
104 |
+
'input_path': video_path, # Path to the video
|
105 |
+
'work_dir': "workdir", # Default workdir, can be abstracted further
|
106 |
+
'height': self.height,
|
107 |
+
'width': self.width,
|
108 |
'inversion': {
|
109 |
+
'save_path': "${work_dir}/latents", # Save latents during inversion
|
110 |
'prompt': video_prompt or "Default video prompt.",
|
111 |
+
'n_frames': None, # None to invert all frames
|
112 |
+
'steps': 50, # Default inversion steps
|
113 |
+
'save_intermediate': False, # Default, but can be abstracted to user
|
114 |
+
'save_steps': 50, # Default
|
115 |
+
'use_blip': False, # Abstract BLIP prompt creation
|
116 |
+
'recon': False, # Reconstruct the input video from latents
|
117 |
+
'control': control_type or "none", # Default to 'none', can use 'tile', 'softedge', etc.
|
118 |
+
'control_scale': 1.0, # Default control scale
|
119 |
+
'batch_size': 8, # Default batch size for inversion
|
120 |
+
'force': False, # Default, force inversion even if latents exist
|
121 |
},
|
122 |
'generation': {
|
123 |
+
'control': "pnp", # Default to Plug-and-Play for generation control
|
124 |
+
'pnp_attn_t': 0.5, # PnP args
|
125 |
+
'pnp_f_t': 0.8, # PnP args
|
126 |
+
'control_scale': 1.0, # Scale for ControlNet-like controls
|
127 |
+
'guidance_scale': guidance_scale, # Guidance scale for CFG
|
128 |
+
'n_timesteps': n_timesteps, # Number of diffusion timesteps
|
129 |
+
'negative_prompt': negative_prompt or "ugly, blurry, low res", # Negative prompt to avoid undesired generations
|
130 |
+
'prompt': edit_prompt or None, # Edit prompt during generation
|
131 |
+
'latents_path': "${work_dir}/latents", # Latents path from inversion
|
132 |
+
'output_path': "${work_dir}", # Output directory for final images
|
133 |
+
'chunk_size': 4, # Number of frames processed per chunk
|
134 |
+
'chunk_ord': "mix-4", # Processing order for video chunks
|
135 |
+
'local_merge_ratio': local_merge_ratio, # Merge ratio for blending
|
136 |
+
'merge_global': True, # Enable global merging
|
137 |
+
'global_merge_ratio': global_merge_ratio, # Global merge ratio
|
138 |
+
'global_rand': 0.5, # Randomness in global merge
|
139 |
+
'align_batch': True, # Align batch processing
|
140 |
+
'frame_range': frame_range or [0, 32, 1], # Default frame range
|
141 |
+
'frame_ids': None, # Specify frame IDs to edit
|
142 |
+
'save_frame': True, # Save individual frames
|
143 |
+
'use_lora': use_lora, # Enable LoRA if applicable
|
144 |
+
# Additional LoRA configurations
|
145 |
+
'lora': {
|
146 |
+
'pretrained_model_name_or_path_or_dict': None, # Default LoRA model path
|
147 |
+
'lora_weight_name': None,
|
148 |
+
'lora_adapter': None,
|
149 |
+
'lora_weight': 1.0
|
150 |
+
}
|
151 |
},
|
152 |
+
'seed': seed, # Seed for reproducibility
|
153 |
+
'device': "cuda", # Default to CUDA
|
154 |
+
'float_precision': "fp16", # Enable mixed-precision
|
155 |
+
'enable_xformers_memory_efficient_attention': True # Default to enable xformers memory-efficient attention
|
156 |
})
|
157 |
|
158 |
return config
|
159 |
|
160 |
+
|
161 |
# # Sample usage
|
162 |
# pipeline = VidToMePipeline(device="cuda", sd_version="2.1", float_precision="fp16")
|
163 |
# pipeline(video_path="path/to/video.mp4", video_prompt="A beautiful scene of a sunset",
|