- def seq2img(self, seq, upscale=15):
- f_first = seq[:, : self.height * self.width].reshape(
- -1, self.height, self.width
- )
- f_second = seq[:, self.height * self.width + 1 :].reshape(
- -1, self.height, self.width
- )
- direction = seq[:, self.height * self.width]
-
- direction_symbol = torch.full(
- (direction.size(0), self.height * upscale - 1, upscale), 0
- )
- direction_symbol = self.colors[direction_symbol].permute(0, 3, 1, 2)
- separator = torch.full((direction.size(0), 3, self.height * upscale - 1, 1), 0)
-
- for n in range(direction_symbol.size(0)):
- if direction[n] == self.token_forward:
- for k in range(upscale):
- direction_symbol[
- n,
- :,
- (self.height * upscale) // 2 - upscale // 2 + k,
- 3 + upscale // 2 - abs(k - upscale // 2),
- ] = 0
- elif direction[n] == self.token_backward:
- for k in range(upscale):
- direction_symbol[
- n,
- :,
- (self.height * upscale) // 2 - upscale // 2 + k,
- 3 + abs(k - upscale // 2),
- ] = 0
- else:
- for k in range(2, upscale - 2):
- direction_symbol[
- n, :, (self.height * upscale) // 2 - upscale // 2 + k, k
- ] = 0
- direction_symbol[
- n,
- :,
- (self.height * upscale) // 2 - upscale // 2 + k,
- upscale - 1 - k,
- ] = 0
-
- return torch.cat(
- [
- self.frame2img(f_first, upscale),
+ def seq2img(self, seq, scale=15):
+ all = [
+ self.frame2img(
+ seq[:, : self.height * self.width].reshape(-1, self.height, self.width),
+ scale,
+ )
+ ]
+
+ separator = torch.full((seq.size(0), 3, self.height * scale - 1, 1), 0)
+
+ t = self.height * self.width
+
+ while t < seq.size(1):
+ direction_tokens = seq[:, t]
+ t += 1
+
+ direction_images = self.colors[
+ torch.full(
+ (direction_tokens.size(0), self.height * scale - 1, scale), 0
+ )
+ ].permute(0, 3, 1, 2)
+
+ for n in range(direction_tokens.size(0)):
+ if direction_tokens[n] == self.token_forward:
+ for k in range(scale):
+ for l in [0, 1]:
+ direction_images[
+ n,
+ :,
+ (self.height * scale) // 2 - scale // 2 + k - l,
+ 3 + scale // 2 - abs(k - scale // 2),
+ ] = 0
+ elif direction_tokens[n] == self.token_backward:
+ for k in range(scale):
+ for l in [0, 1]:
+ direction_images[
+ n,
+ :,
+ (self.height * scale) // 2 - scale // 2 + k - l,
+ 3 + abs(k - scale // 2),
+ ] = 0
+ else:
+ for k in range(2, scale - 2):
+ for l in [0, 1]:
+ direction_images[
+ n,
+ :,
+ (self.height * scale) // 2 - scale // 2 + k - l,
+ k,
+ ] = 0
+ direction_images[
+ n,
+ :,
+ (self.height * scale) // 2 - scale // 2 + k - l,
+ scale - 1 - k,
+ ] = 0
+
+ all += [