have a tensor named input with dimensions 16x3x64x64. It is a minibatch of 16 RGB images, each 64x64 pixels. I’d like to crop each image down to a patch . Then I want to resize all the patches to the same size(32×32). So the output tensor I want would have dimensions 64x3×32x32.

I’d like to crop each image based on the point of lefttop and rightdown . They are given by a 4-dimensional numpy array named box [x1,y1,x2,y2] with dimensions 64x4.

I try crop the input with:

for i in range (batchsize):

output[i] = input[ i, : , box[i, 0]:box[i, 2], box[i, 1]:box[i, 3] ]

Then I translate the tensor output to numpy and resize it. Finally I translate it back to the tensor to forward.

However, when I do this,it tells:

TypeError: only integer tensors of a single element can be converted to an index.

I really do not know where is wrong. And Is there an efficient way to do the process I say (crop the tensor and resize based on a batch) in pytorch (on the gpu)? And if I translate the tensor to numpy, does it influence the gradient?

Thanks for any help!