- 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),
- separator,
- direction_symbol,
- separator,
- self.frame2img(f_second, upscale),
- ],
- dim=3,
- )
-