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

Method forward

examples/WanVSR/utils/utils.py:92–124  ·  view source on GitHub ↗
(self, video)

Source from the content-addressed store, hash-verified

90 self.clip_idx = 0
91
92 def forward(self, video):
93 self.clear_cache()
94 # x: (B, C, F, H, W)
95
96 t = video.shape[2]
97 iter_ = 1 + (t - 1) // 4
98 first_frame = video[:, :, :1, :, :].repeat(1, 1, 3, 1, 1)
99 video = torch.cat([first_frame, video], dim=2)
100 # print(video.shape)
101
102 out_x = []
103 for i in range(iter_):
104 x = self.pixel_shuffle(video[:,:,i*4:(i+1)*4,:,:])
105 cache1_x = x[:, :, -CACHE_T:, :, :].clone()
106 self.cache['conv1'] = cache1_x
107 x = self.conv1(x, self.cache['conv1'])
108 x = self.norm1(x)
109 x = self.act1(x)
110 cache2_x = x[:, :, -CACHE_T:, :, :].clone()
111 self.cache['conv2'] = cache2_x
112 if i == 0:
113 continue
114 x = self.conv2(x, self.cache['conv2'])
115 x = self.norm2(x)
116 x = self.act2(x)
117 out_x.append(x)
118 out_x = torch.cat(out_x, dim = 2)
119 # print(out_x.shape)
120 out_x = rearrange(out_x, 'b c f h w -> b (f h w) c')
121 outputs = []
122 for i in range(self.layer_num):
123 outputs.append(self.linear_layers[i](out_x))
124 return outputs
125
126 def clear_cache(self):
127 self.cache = {}

Callers

nothing calls this directly

Calls 1

clear_cacheMethod · 0.95

Tested by

no test coverage detected