Hi,



 trougnouf:

I read that the fold/unfold function may be able to help by creating a sliding window


Yes it works, actually, in your case you are extracting patches using sliding window then permuting channels.
Here is the code that will do the job for your arbitrary example:
x.unfold(2, 2, 2)[0].unfold(2, 2, 2).contiguous().view(3, -1, 2, 2).permute((1, 0, 2, 3))

But if you have question how it works, here is another post I have explained the calculations:

  
    
    
    Change the dimension of tensor 
  
  
    Hi, 
I have a tensor with dimension [1, 1, 4, 6] like this: 
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]]])

I want to change it to a tensor like this: 
[[ [[1, 2],
    [7, 8]],

   [[3, 4],
    [9, 10]],

   [[5, 6],
    [11, 12]],

   [[13, 14],
    [19, 20]],

   [[15, 16],
    [21, 22]],

   [[17, 18],
    [23, 24]] ]]
   

Is it possible? 
if we use this cod…
  


Bests