Caffe crop to pytorch

Hi,

I am trying to write a caffe model in pytorch but they are using a crop module not implemented in pytorch, which is taking as input a [1,3,224,224] tensor and a [1,1,300,300]
and output a [1,3,224,224] tensor which should be a cropped version of the [1,1,300,300].

I tried slicing but I till end up with a [1,1,224,224] tensor and I really don’t understand what they are doing. Any idea what is happening and how I should do it in pytorch ?

the model

a tool to see it

Yours

Justin

1 Like

I’m trying to read the caffe docs and it looks like they’re cropping a [1,1,300,300] to the size [1,3,224,224]. Not sure what the behavior is when some dimensions of the resulting crop are larger than the original input. It’s possible that the values are repeated, or zero-filled.

That is what I thought but I didn’t find any way to do it with pytorch except slicing my tensor and not taking care about the [1,3,224,224] tensor. Still searching tho.

Based on the two things I hypothesized it could be doing, you could do the following:

  1. Repeat the values
slice_output  # (1, 1, 224, 224)
output = slice_output.expand(1, 3, 224, 224)
  1. Zero-fill the values
slice_output  # (1, 1, 224, 224)
zeros = torch.zeros_like(1,2, 224, 224)
output = torch.cat([slice_output, zeros], dim=1)

Alright, thanks for your help :slight_smile: