| 21 | print(name, tensor, tensor.shape) |
| 22 | |
| 23 | def tensor2summ(tensor, permute_dim=False): |
| 24 | # if permute_dim = True: |
| 25 | # for 2d tensor, assume input is torch format B x S x C x H x W, we want B x S x H x W x C |
| 26 | # for 3d tensor, assume input is torch format B x S x C x H x W x D, we want B x S x H x W x C x D |
| 27 | # and finally unbind the sequeence dimension and return a list of [B x H x W x C]. |
| 28 | assert(tensor.ndim == 5 or tensor.ndim == 6) |
| 29 | assert(tensor.size()[1] == 2) #sequense length should be 2 |
| 30 | if permute_dim: |
| 31 | if tensor.ndim == 6: #3d tensor |
| 32 | tensor = tensor.permute(0, 1, 3, 4, 5, 2) |
| 33 | elif tensor.ndim == 5: #2d tensor |
| 34 | tensor = tensor.permute(0, 1, 3, 4, 2) |
| 35 | |
| 36 | tensor = torch.unbind(tensor, dim=1) |
| 37 | return tensor |
| 38 | |
| 39 | def normalize_single(d): |
| 40 | # d is a whatever shape torch tensor |