I've downloaded the EMNIST dataset of letters, and I've converted each image to a torch.tensor
object with shape torch.size([28, 28])
. However, I would like divide the 28*28 image into 7*7 blocks, with each block sized 16.
I.E. if the image pixel labeled from left to right, from up to down with 1, 2, ..., 784
[
[1, 2, 3, ..., 28],
...
[ ..., 784]
]
I expect the output to be a torch.tensor
object of size torch.size([7, 7, 16])
[
[
[1, 2, 3, 4, 29, 30, 31, 32, 57, 58, 59, 60, 85, 86, 87, 88],
...
[25, 26, 27, 28, 53, 54, 55, 56, 81, 82, 83, 84, 109, 110, 111, 112]
],
...
[
...
[697, 698, 699, 700, 725, 726, 727, 728, 753, 754, 755, 756, 781, 782, 783, 784]
]
]
I've tried to use torch.view(7, 7, 16)
, but it did not show up as the expected outcome.
Thanks a lot ^_^
a = torch.tensor([[x + 1 for x in range(28 * y, 28 * (y + 1))] for y in range(28)])
c = a.split(4, dim=0)
torch.stack([torch.stack(d.split(4, dim=1)).view(7, 16) for d in c])
will show the desired result, but is there any way faster?