mindspore如何让算子输出之一为tuple类型或list类型

问题描述:

1,正在开发的算子有三个输出:begin, size, bboxes

    def infer_shape(self, image_size_shape, min_object_covered_shape, bounding_boxes_shape=None):

"""省略"""

        begin_shape=(3,)

        size_shape=(3,)

        bboxes_shape=(4,)

        return begin_shape, size_shape, bboxes_shape

                

    def infer_dtype(self, image_size_dtype, min_object_covered_dtype, bounding_boxes_dtype=None):

         """省略"""

        begin_dtype = mstype.int32

        size_dtype = mstype.int32

        bboxes_dtype = mstype.float32

        return begin_dtype, size_dtype, bboxes_dtype

2,但实际上 我希望的输出类型如下 因为mindsore.ops.Slice()的输入参数:begin、size期望类型为list或tuple

    def infer_dtype(self, image_size_dtype, min_object_covered_dtype, bounding_boxes_dtype=None):

         """省略"""

        begin_dtype = list #tuple

        size_dtype = list # tuple

        bboxes_dtype = mstype.float32

        return begin_dtype, size_dtype, bboxes_dtype

3,但从其它已有算子的源代码看,似乎没有输出为list或tuple的接口,或者有我还未发现,因此希望了解如何实现上述2中的功能,包括C++侧的代码如何更改。

1,原算子C++注册代码

MS_REG_CPU_KERNEL(SampleDistortedBoundingBox,

                KernelAttr()

                      .AddInputAttr(kNumberTypeUInt16)

                      .AddInputAttr(kNumberTypeFloat32)

                      .AddOutputAttr(kNumberTypeInt32)

                      .AddOutputAttr(kNumberTypeInt32)

                      .AddOutputAttr(kNumberTypeFloat32),

                    SampleDistortedBoundingBoxCPUKernel);

2、原算子输出C++端代码

        auto *begin = reinterpret_cast<int *>(outputs[0]->addr);

        auto *size = reinterpret_cast<int  *>(outputs[1]->addr);

        auto *bboxes = reinterpret_cast<float *>(outputs[2]->addr);

        begin[0]=begin_offset_width_;

        begin[1]=begin_offset_height_;

        begin[2]=begin_depth_;

        size[0]=size_target_width_;

        size[1]=size_target_height_;

        size[2]=size_depth_;

        for(int i=0;i<4;i++)

        {

                bboxes[i]=bboxes_[0][0][i];

        }

        return true;

解答:

框架的算子输出只支持Tensor类型,不支持tuple或list。
算子开发可以参考文档:MindSpore算子众智
Slice算子的begin和size入参只能接受常量输入,你上述传递的入参不满足要求,Slice算子使用方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值