Пример #1
0
 def roi_align(g, input, rois, spatial_scale, pooled_height, pooled_width,
               sampling_ratio, aligned):
     batch_indices = _cast_Long(
         g,
         squeeze(
             g,
             select(
                 g, rois, 1,
                 g.op('Constant',
                      value_t=torch.tensor([0], dtype=torch.long))), 1),
         False)
     rois = select(
         g, rois, 1,
         g.op('Constant',
              value_t=torch.tensor([1, 2, 3, 4], dtype=torch.long)))
     if aligned:
         warnings.warn(
             "ONNX export of ROIAlign with aligned=True does not match PyTorch when using malformed boxes,"
             " ONNX forces ROIs to be 1x1 or larger.")
         scale = torch.tensor(0.5 / spatial_scale).to(dtype=torch.float)
         rois = g.op("Sub", rois, scale)
     return g.op('RoiAlign',
                 input,
                 rois,
                 batch_indices,
                 spatial_scale_f=spatial_scale,
                 output_height_i=pooled_height,
                 output_width_i=pooled_width,
                 sampling_ratio_i=sampling_ratio)
Пример #2
0
 def roi_align(g, input, rois, spatial_scale, pooled_height, pooled_width,
               sampling_ratio, aligned):
     if (aligned):
         raise RuntimeError(
             'Unsupported: ONNX export of roi_align with aligned')
     batch_indices = _cast_Long(
         g,
         squeeze(
             g,
             select(
                 g, rois, 1,
                 g.op('Constant',
                      value_t=torch.tensor([0], dtype=torch.long))), 1),
         False)
     rois = select(
         g, rois, 1,
         g.op('Constant',
              value_t=torch.tensor([1, 2, 3, 4], dtype=torch.long)))
     return g.op('RoiAlign',
                 input,
                 rois,
                 batch_indices,
                 spatial_scale_f=spatial_scale,
                 output_height_i=pooled_height,
                 output_width_i=pooled_width,
                 sampling_ratio_i=sampling_ratio)
def min_opset9(g, self, dim_or_y=None, keepdim=None):
    # torch.min(input)
    if dim_or_y is None and keepdim is None:
        return _cast_Long(
            g, g.op("ReduceMin", _cast_Int(g, self, False), keepdims_i=0),
            False)
    # torch.min(input, other)
    if keepdim is None:
        return g.op("Min", self, dim_or_y)
    # torch.min(input, dim, keepdim)
    else:
        dim = sym_help._get_const(dim_or_y, 'i', 'dim')
        keepdim = sym_help._get_const(keepdim, 'i', 'keepdim')
        min = g.op("ReduceMin", self, axes_i=[dim], keepdims_i=keepdim)
        indices = g.op('ArgMin', self, axis_i=dim, keepdims_i=keepdim)
        return min, indices
Пример #4
0
    def roi_align(g, input, rois, spatial_scale, pooled_height, pooled_width,
                  sampling_ratio, aligned):
        batch_indices = _cast_Long(
            g,
            squeeze(
                g,
                select(
                    g, rois, 1,
                    g.op("Constant",
                         value_t=torch.tensor([0], dtype=torch.long))), 1),
            False)
        rois = select(
            g, rois, 1,
            g.op("Constant",
                 value_t=torch.tensor([1, 2, 3, 4], dtype=torch.long)))
        # TODO: Remove this warning after ONNX opset 16 is supported.
        if aligned:
            warnings.warn(
                "ROIAlign with aligned=True is not supported in ONNX, but will be supported in opset 16. "
                "The workaround is that the user need apply the patch "
                "https://github.com/microsoft/onnxruntime/pull/8564 "
                "and build ONNXRuntime from source.")

        # ONNX doesn't support negative sampling_ratio
        if sampling_ratio < 0:
            warnings.warn(
                "ONNX doesn't support negative sampling ratio, therefore is set to 0 in order to be exported."
            )
            sampling_ratio = 0
        return g.op(
            "RoiAlign",
            input,
            rois,
            batch_indices,
            spatial_scale_f=spatial_scale,
            output_height_i=pooled_height,
            output_width_i=pooled_width,
            sampling_ratio_i=sampling_ratio,
        )
Пример #5
0
 def roi_align(g, input, rois, spatial_scale, pooled_height, pooled_width,
               sampling_ratio):
     batch_indices = _cast_Long(
         g,
         squeeze(
             g,
             select(
                 g, rois, 1,
                 g.op('Constant',
                      value_t=torch.tensor([0], dtype=torch.long))), 1),
         False)
     rois = select(
         g, rois, 1,
         g.op('Constant',
              value_t=torch.tensor([1, 2, 3, 4], dtype=torch.long)))
     return g.op('RoiAlign',
                 input,
                 rois,
                 batch_indices,
                 spatial_scale_f=spatial_scale,
                 output_height_i=pooled_height,
                 output_width_i=pooled_width,
                 sampling_ratio_i=sampling_ratio)