Nikronic:

a.unsqueeze(0).unfold(2, 2, 2)[0].unfold(2, 2, 2).contiguous().view(2, 6, 2, 2)


import torch
a = torch.tensor([[[[ 1,  2,  3,  4,  5,  6],
                   [ 7,  8,  9, 10, 11, 12],
                   [13, 14, 15, 16, 17, 18],
                   [19, 20, 21, 22, 23, 24]]],
                  
                 [[[25,  26,  27, 28, 29, 30],
                   [31,  32,  33, 34, 35, 36],
                   [37, 38, 39, 37, 38, 39],
                   [40, 41, 42, 43, 44, 45]]]])

z= a.unsqueeze(0).unfold(2, 2, 2)[0].unfold(2, 2, 2).contiguous().view(2, 6, 2, 2)
print(z)


I received this error:
RuntimeError                              Traceback (most recent call last)
<ipython-input-9-9e80a02d4148> in <module>()
     10                    [40, 41, 42, 43, 44, 45]]]])
     11 
---> 12 z= a.unsqueeze(0).unfold(2, 2, 2)[0].unfold(2, 2, 2).contiguous().view(2, 6, 2, 2)
     13 print(z)

RuntimeError: invalid argument 3: out of range at ..\aten\src\TH/generic/THTensor.cpp:392

Please attention that the dimension of tensor is torch.Size([2, 1, 4, 6]).
I would appreciate it if you check it again.
Thanks a lot