提交 71d42d21 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!5814 switch from ctx Malloc to new in detection post process anchors

Merge pull request !5814 from wangzhe/master
......@@ -27,7 +27,6 @@ using mindspore::schema::PrimitiveType_DetectionPostProcess;
namespace mindspore::kernel {
int DetectionPostProcessCPUKernel::Init() {
MS_ASSERT(context_->allocator != nullptr);
auto anchor_tensor = in_tensors_.at(2);
DetectionPostProcessParameter *parameter = reinterpret_cast<DetectionPostProcessParameter *>(op_parameter_);
parameter->anchors_ = nullptr;
......@@ -36,8 +35,7 @@ int DetectionPostProcessCPUKernel::Init() {
const double scale = quant_params.at(0).scale;
const int32_t zp = quant_params.at(0).zeroPoint;
auto anchor_uint8 = reinterpret_cast<uint8_t *>(anchor_tensor->Data());
auto anchor_fp32 =
reinterpret_cast<float *>(context_->allocator->Malloc(anchor_tensor->ElementsNum() * sizeof(float)));
auto anchor_fp32 = new (std::nothrow) float[anchor_tensor->ElementsNum()];
if (anchor_fp32 == nullptr) {
MS_LOG(ERROR) << "Malloc anchor failed";
return RET_ERROR;
......@@ -47,7 +45,7 @@ int DetectionPostProcessCPUKernel::Init() {
}
parameter->anchors_ = anchor_fp32;
} else if (anchor_tensor->data_type() == kNumberTypeFloat32) {
parameter->anchors_ = reinterpret_cast<float *>(context_->allocator->Malloc(anchor_tensor->Size()));
parameter->anchors_ = new (std::nothrow) float[anchor_tensor->ElementsNum()];
if (parameter->anchors_ == nullptr) {
MS_LOG(ERROR) << "Malloc anchor failed";
return RET_ERROR;
......@@ -62,7 +60,7 @@ int DetectionPostProcessCPUKernel::Init() {
DetectionPostProcessCPUKernel::~DetectionPostProcessCPUKernel() {
DetectionPostProcessParameter *parameter = reinterpret_cast<DetectionPostProcessParameter *>(op_parameter_);
context_->allocator->Free(parameter->anchors_);
delete [](parameter->anchors_);
}
int DetectionPostProcessCPUKernel::ReSize() { return RET_OK; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册