MCPcopy Create free account
hub / github.com/JaydenLyh/Reward-Forcing / forward

Method forward

demo_utils/vae.py:168–196  ·  view source on GitHub ↗
(
            self,
            z: torch.Tensor,
            is_first_frame: torch.Tensor,
            *feat_cache: List[torch.Tensor]
    )

Source from the content-addressed store, hash-verified

166 self.conv2 = CausalConv3d(self.z_dim, self.z_dim, 1)
167
168 def forward(
169 self,
170 z: torch.Tensor,
171 is_first_frame: torch.Tensor,
172 *feat_cache: List[torch.Tensor]
173 ):
174 # from [batch_size, num_frames, num_channels, height, width]
175 # to [batch_size, num_channels, num_frames, height, width]
176 z = z.permute(0, 2, 1, 3, 4)
177 assert z.shape[2] == 1
178 feat_cache = list(feat_cache)
179 is_first_frame = is_first_frame.bool()
180
181 device, dtype = z.device, z.dtype
182 scale = [self.mean.to(device=device, dtype=dtype),
183 1.0 / self.std.to(device=device, dtype=dtype)]
184
185 if isinstance(scale[0], torch.Tensor):
186 z = z / scale[1].view(1, self.z_dim, 1, 1, 1) + scale[0].view(
187 1, self.z_dim, 1, 1, 1)
188 else:
189 z = z / scale[1] + scale[0]
190 x = self.conv2(z)
191 out, feat_cache = self.decoder(x, is_first_frame, feat_cache=feat_cache)
192 out = out.clamp_(-1, 1)
193 # from [batch_size, num_channels, num_frames, height, width]
194 # to [batch_size, num_frames, num_channels, height, width]
195 out = out.permute(0, 2, 1, 3, 4)
196 return out, feat_cache
197
198
199class VAEDecoder3d(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected