MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / decode_video

Method decode_video

diffsynth/models/svd_vae_decoder.py:165–199  ·  view source on GitHub ↗
(
        self, sample,
        batch_time=8, batch_height=128, batch_width=128,
        stride_time=4, stride_height=32, stride_width=32,
        progress_bar=lambda x:x
    )

Source from the content-addressed store, hash-verified

163
164
165 def decode_video(
166 self, sample,
167 batch_time=8, batch_height=128, batch_width=128,
168 stride_time=4, stride_height=32, stride_width=32,
169 progress_bar=lambda x:x
170 ):
171 sample = sample.permute(1, 0, 2, 3)
172 data_device = sample.device
173 computation_device = self.conv_in.weight.device
174 torch_dtype = sample.dtype
175 _, T, H, W = sample.shape
176
177 weight = torch.zeros((1, T, H*8, W*8), dtype=torch_dtype, device=data_device)
178 values = torch.zeros((3, T, H*8, W*8), dtype=torch_dtype, device=data_device)
179
180 # Split tasks
181 tasks = []
182 for t in range(0, T, stride_time):
183 for h in range(0, H, stride_height):
184 for w in range(0, W, stride_width):
185 if (t-stride_time >= 0 and t-stride_time+batch_time >= T)\
186 or (h-stride_height >= 0 and h-stride_height+batch_height >= H)\
187 or (w-stride_width >= 0 and w-stride_width+batch_width >= W):
188 continue
189 tasks.append((t, t+batch_time, h, h+batch_height, w, w+batch_width))
190
191 # Run
192 for tl, tr, hl, hr, wl, wr in progress_bar(tasks):
193 sample_batch = sample[:, tl:tr, hl:hr, wl:wr].to(computation_device)
194 sample_batch = self.forward(sample_batch).to(data_device)
195 mask = self.build_mask(sample_batch, is_bound=(tl==0, tr>=T, hl==0, hr>=H, wl==0, wr>=W))
196 values[:, tl:tr, hl*8:hr*8, wl*8:wr*8] += sample_batch * mask
197 weight[:, tl:tr, hl*8:hr*8, wl*8:wr*8] += mask
198 values /= weight
199 return values
200
201
202 @staticmethod

Callers

nothing calls this directly

Calls 3

forwardMethod · 0.95
build_maskMethod · 0.95
toMethod · 0.45

Tested by

no test coverage detected