I want to slice 3D slices from a tensor of size [N,C,H,W] on basis of some indices. The indices are of the format [B,3] where B is the number of slices and 3 corresponds to N,h0,w0 where N corresponds to the batch of the input and h0, w0 correspond to the corner of the slice needed to be cut.
input is the tensor of size [N,C,H,W] where N stands for batch size, C for channels and H,W for width and height. ksize is the size of the block that i want to slice, and kstride is used to upscale the indices to the image size.
This approach is not fast enough for my purposes is there a better way to do this ? I am new to pytorch.
Lets us say I have an input tensor of size [64,3,30,30] and I want to cut out slices of shape [3, 5, 5] . where 5 = ksize[0].
Indices are of the form :
indices = [
[0, 1, 2],
[1, 0, 5],
[60, 4, 1]
]
where each element is the index corresponding to N, w0, h0. Now I want to cut a slice of size [C, 5,5] from input using the indices. So I do it in the following way :
slice = input[N, :, w0:w0+5, h0:h0+5]
So, the indices correspond to the top left of the slice that I want to make