MCPcopy Create free account
hub / github.com/MeiGen-AI/InfiniteTalk / encode

Method encode

wan/modules/vae.py:516–542  ·  view source on GitHub ↗
(self, x, scale)

Source from the content-addressed store, hash-verified

514 return x_recon, mu, log_var
515
516 def encode(self, x, scale):
517 self.clear_cache()
518 ## cache
519 t = x.shape[2]
520 iter_ = 1 + (t - 1) // 4
521 ## 对encode输入的x,按时间拆分为1、4、4、4....
522 for i in range(iter_):
523 self._enc_conv_idx = [0]
524 if i == 0:
525 out = self.encoder(
526 x[:, :, :1, :, :],
527 feat_cache=self._enc_feat_map,
528 feat_idx=self._enc_conv_idx)
529 else:
530 out_ = self.encoder(
531 x[:, :, 1 + 4 * (i - 1):1 + 4 * i, :, :],
532 feat_cache=self._enc_feat_map,
533 feat_idx=self._enc_conv_idx)
534 out = torch.cat([out, out_], 2)
535 mu, log_var = self.conv1(out).chunk(2, dim=1)
536 if isinstance(scale[0], torch.Tensor):
537 mu = (mu - scale[0].view(1, self.z_dim, 1, 1, 1)) * scale[1].view(
538 1, self.z_dim, 1, 1, 1)
539 else:
540 mu = (mu - scale[0]) * scale[1]
541 self.clear_cache()
542 return mu
543
544 def decode(self, z, scale):
545 self.clear_cache()

Callers 2

forwardMethod · 0.95
sampleMethod · 0.95

Calls 1

clear_cacheMethod · 0.95

Tested by

no test coverage detected