Hi PyTorch ! I'm trying to get a snippet for cropping with offsets. Can you please tell what does -1 specifies here?

offsets = [0, (x1_shape[1] - x2_shape[1]) // 2, (x1_shape[2] - x2_shape[2]) // 2, 0]

size = [-1, x2_shape[1], x2_shape[2], -1]

If you pass the -1 to an operation, which expects a dimension, it would select the “last dimension”.
In your current code snippet it’s unclear, how size is used, so I can only speculate. :wink:

1 Like

That’s clear to me! But I have the TF implementation, I want to reproduce it for PyTorch.

The TF docs might be helpful:

If size[i] is -1, all remaining elements in dimension i are included in the slice. In other words, this is equivalent to setting:
size[i] = input_.dim_size(i) - begin[i]

If you provide the input and desired output (+ shapes), we could try to come up with the corresponding method in PyTorch.