Welcome to our Support Center

coordinate_transformation_mode

coordinate_transformation_mode : enum, this attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.

 

The coordinate of each dimension is transformed individually. Let’s describe a case using axis x as an example. DenoteΒ x_resizedΒ as the coordinate of axis x in the resized tensor,Β x_originalΒ as the coordinate of axis x in the original tensor,Β length_originalΒ as the length of the original tensor in axis x,Β length_resizedΒ as the length of the resized tensor in axis x,Β scaleΒ =Β length_resizedΒ /Β length_original,Β output_widthΒ the target length on the axis x which can be a fractional number when it is calculated out of a scale factor, andΒ output_width_intΒ the effective output width as an integer.

if coordinate_transformation_mode isΒ "half_pixel",

x_original = (x_resized + 0.5) / scale - 0.5

if coordinate_transformation_mode isΒ "half_pixel_symmetric",

adjustment = output_width_int / output_width
center = input_width / 2
offset = center * (1 - adjustment)
x_ori = offset + (x + 0.5) / scale - 0.5

if coordinate_transformation_mode isΒ "pytorch_half_pixel",

x_original = length_resized > 1 ? (x_resized + 0.5) / scale - 0.5 : 0

if coordinate_transformation_mode isΒ "align_corners",

x_original = x_resized * (length_original - 1) / (length_resized - 1)

if coordinate_transformation_mode isΒ "asymmetric",

x_original = x_resized / scale

if coordinate_transformation_mode isΒ "tf_crop_and_resize",

x_original = length_resized > 1 ? start_x * (length_original - 1) + x_resized * (end_x - start_x) * (length_original - 1) / (length_resized - 1) : 0.5 * (start_x + end_x) * (length_original - 1)
Table of Contents