Exemplo n.º 1
0
    def symbolic_fn(g, input, output_size, *args):
        scales, align_corners = sym_help._get_interpolate_attributes(g, interpolate_mode, args)
        align_corners = sym_help._maybe_get_scalar(align_corners)
        coordinate_transformation_mode = "asymmetric" if interpolate_mode == "nearest" \
            else "align_corners" if align_corners else "pytorch_half_pixel"
        empty_tensor = g.op("Constant", value_t=torch.tensor([], dtype=torch.float32))

        if scales is None:
            input_size = g.op("Shape", input)
            input_size_beg = sym_help._slice_helper(g, input_size, axes=[0], ends=[2], starts=[0])
            output_size = g.op("Cast", output_size, to_i=sym_help.cast_pytorch_to_onnx["Long"])
            output_size = g.op("Concat", input_size_beg, output_size, axis_i=0)
            scales = g.op("Constant", value_t=torch.tensor([], dtype=torch.float32))
            return g.op("Resize",
                        input,
                        empty_tensor,  # roi only takes effect whith coordinate_transformation_mode="tf_crop_and_resize"
                        scales,  # scales is not needed since we are sending out_size
                        output_size,
                        coordinate_transformation_mode_s=coordinate_transformation_mode,
                        cubic_coeff_a_f=-0.75,  # only valid when mode="cubic"
                        mode_s=interpolate_mode,  # nearest, linear, or cubic
                        nearest_mode_s="floor")  # only valid when mode="nearest"
        else:
            return g.op("Resize",
                        input,
                        empty_tensor,  # roi only takes effect with coordinate_transformation_mode="tf_crop_and_resize"
                        scales,  # scales is not needed since we are sending out_size
                        coordinate_transformation_mode_s=coordinate_transformation_mode,
                        cubic_coeff_a_f=-0.75,  # only valid when mode="cubic"
                        mode_s=interpolate_mode,  # nearest, linear, or cubic
                        nearest_mode_s="floor")  # only valid when mode="nearest"
Exemplo n.º 2
0
 def symbolic_fn(g, input, output_size, *args):
     scales, align_corners = sym_help._get_interpolate_attributes(g, interpolate_mode, args)
     sym_help._interpolate_warning(interpolate_mode)
     align_corners = sym_help._maybe_get_scalar(align_corners)
     if align_corners:
         return _unimplemented(name, "align_corners == True")
     if scales is None:
         scales = sym_help._interpolate_size_to_scales(g, input, output_size, dim)
     return g.op("Resize", input, scales, mode_s=interpolate_mode)
Exemplo n.º 3
0
 def symbolic_fn(g, input, output_size, *args):
     scales, align_corners = sym_help._get_interpolate_attributes(g, interpolate_mode, args)
     sym_help._interpolate_warning(interpolate_mode)
     align_corners = sym_help._maybe_get_scalar(align_corners)
     if align_corners:
         return _unimplemented(name, "align_corners == True")
     output_size = sym_help._maybe_get_const(output_size, 'is')
     if sym_help._is_value(output_size):
         return _unimplemented(name, "torch._C.Value (output_size) indexing")
     if scales is None:
         scales = [1. if i < 2 else
                   float(output_size[-(dim - i)]) / float(input.type().sizes()[-(dim - i)])
                   for i in range(0, dim)]
     return g.op("Upsample", input, mode_s=interpolate_mode, scales_f=scales)