Our support for non-tensor types in tracing is pretty limited (see #14455 62), but your model looks like using script mode would work well. See something like:
@torch.jit.script
def center_slice_helper(layer, diff_y, diff_x, h_end, w_end):
    # type: (Tensor, int, int, int, int) -> Tensor
    return layer[:, :, diff_y:h_end, diff_x:w_end]

class M(torch.jit.ScriptModule):
    @torch.jit.script_method
    def center_crop(self, layer, target_size):
        #_, _, layer_height, layer_width = layer.size()

        diff_y = (layer.shape[2] - target_size.shape[2]) // 2
        diff_x = (layer.shape[3] - target_size.shape[3]) // 2

        h_end = diff_y + target_size.shape[2]
        w_end = diff_x + target_size.shape[3]

        return center_slice_helper(layer, diff_y, diff_x, h_end, w_end)

    @torch.jit.script_method
    def forward(self, x, bridge):
        crop1 = self.center_crop(bridge, x)
        return crop1

m = M()