
问题描述:
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
auto *size = reinterpret_cast
auto *bboxes = reinterpret_cast
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算子使用方法