* Copyright (c) 2026 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file iou3d_infershape.cpp
* \brief Iou3D 算子形状推导实现
*
* shape_rule:
* iou.shape = (bboxes.shape[0], bboxes.shape[2], gtboxes.shape[2]) == (B, N, K)
*/
#include "register/op_impl_registry.h"
#include "exe_graph/runtime/infer_shape_context.h"
#include "op_common/log/log.h"
using namespace ge;
namespace ops {
static ge::graphStatus InferShape4Iou3D(gert::InferShapeContext* context)
{
const gert::Shape* bboxesShape = context->GetInputShape(0);
OP_CHECK_NULL_WITH_CONTEXT(context, bboxesShape);
const gert::Shape* gtboxesShape = context->GetInputShape(1);
OP_CHECK_NULL_WITH_CONTEXT(context, gtboxesShape);
gert::Shape* iouShape = context->GetOutputShape(0);
OP_CHECK_NULL_WITH_CONTEXT(context, iouShape);
if (bboxesShape->GetDimNum() == ge::UNKNOWN_RANK.size() || gtboxesShape->GetDimNum() == ge::UNKNOWN_RANK.size()) {
iouShape->SetDimNum(ge::UNKNOWN_RANK.size());
return ge::GRAPH_SUCCESS;
}
OP_CHECK_IF(bboxesShape->GetDimNum() != 3 || gtboxesShape->GetDimNum() != 3,
OP_LOGE(context, "Iou3D: bboxes/gtboxes must be rank-3, got %zu/%zu", bboxesShape->GetDimNum(),
gtboxesShape->GetDimNum()),
return ge::GRAPH_FAILED);
const int64_t bboxesChannel = bboxesShape->GetDim(1);
const int64_t gtboxesChannel = gtboxesShape->GetDim(1);
OP_CHECK_IF(bboxesChannel != 7 || gtboxesChannel != 7,
OP_LOGE(context, "Iou3D: channel dimension must be 7, got bboxes=%ld, gtboxes=%ld", bboxesChannel,
gtboxesChannel),
return ge::GRAPH_FAILED);
const int64_t batch = bboxesShape->GetDim(0);
const int64_t numN = bboxesShape->GetDim(2);
const int64_t numK = gtboxesShape->GetDim(2);
const int64_t gtboxesBatch = gtboxesShape->GetDim(0);
OP_CHECK_IF(
batch != gtboxesBatch,
OP_LOGE(context, "Iou3D: batch dimension must be consistent, got bboxes=%ld, gtboxes=%ld", batch, gtboxesBatch),
return ge::GRAPH_FAILED);
iouShape->SetDimNum(3);
iouShape->SetDim(0, batch);
iouShape->SetDim(1, numN);
iouShape->SetDim(2, numK);
return ge::GRAPH_SUCCESS;
}
IMPL_OP_INFERSHAPE(Iou3D).InferShape(InferShape4Iou3D);
}