栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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(outputs[0]->addr);

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

        auto *bboxes = reinterpret_cast(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算子使用方法

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/986699.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号