forked from mindspore-Ecosystem/mindspore
!11197 retore the resize ir
From: @yeyunpeng2020 Reviewed-by: @hangangqiang,@zhang_xue_tong Signed-off-by: @hangangqiang
This commit is contained in:
commit
64b0a5a497
|
@ -24,10 +24,14 @@ enum ResizeMethod: byte {
|
|||
}
|
||||
|
||||
enum CoordinateTransformMode: byte {
|
||||
ASYMMETRIC = 0,
|
||||
ALIGN_CORNERS = 1,
|
||||
HALF_PIXEL = 2,
|
||||
CROP_AND_RESIZE = 3
|
||||
COMMON = 0,
|
||||
HALF_PIXEL = 1,
|
||||
PYTORCH_HALF_PIXEL = 2,
|
||||
TF_HALF_PIXEL = 3,
|
||||
TF_CROP_AND_RESIZE = 4,
|
||||
ALIGN_CORNERS = 5,
|
||||
ASYMMETRIC = 6,
|
||||
ALIGN_CORNERS_WITH_HALF_PIEXL = 7
|
||||
}
|
||||
|
||||
enum NearestMode : byte {
|
||||
|
|
|
@ -31,16 +31,19 @@ namespace mindspore::kernel {
|
|||
int ResizeCPUKernel::Init() {
|
||||
auto ret = ResizeBaseCPUKernel::Init();
|
||||
switch (coordinate_transform_mode_) {
|
||||
case schema::CoordinateTransformMode_COMMON:
|
||||
case schema::CoordinateTransformMode_ASYMMETRIC:
|
||||
calculate_ = CalculateAsymmetric;
|
||||
break;
|
||||
case schema::CoordinateTransformMode_ALIGN_CORNERS:
|
||||
calculate_ = CalculateAlignCorners;
|
||||
break;
|
||||
case schema::CoordinateTransformMode_PYTORCH_HALF_PIXEL:
|
||||
case schema::CoordinateTransformMode_TF_HALF_PIXEL:
|
||||
case schema::CoordinateTransformMode_HALF_PIXEL:
|
||||
calculate_ = CalculateHalfPixel;
|
||||
break;
|
||||
case schema::CoordinateTransformMode_CROP_AND_RESIZE:
|
||||
case schema::CoordinateTransformMode_TF_CROP_AND_RESIZE:
|
||||
break;
|
||||
default:
|
||||
MS_LOG(ERROR) << "Do not support coordinate transform mode. Mode is"
|
||||
|
@ -72,7 +75,7 @@ int ResizeCPUKernel::ReSize() {
|
|||
|
||||
auto input = in_tensors_.at(0);
|
||||
auto input_shape = input->shape();
|
||||
if (coordinate_transform_mode_ == schema::CoordinateTransformMode_CROP_AND_RESIZE) {
|
||||
if (coordinate_transform_mode_ == schema::CoordinateTransformMode_TF_CROP_AND_RESIZE) {
|
||||
auto boxes = reinterpret_cast<float *>(in_tensors_.at(1)->data_c());
|
||||
auto box_idx = reinterpret_cast<int32_t *>(in_tensors_.at(2)->data_c());
|
||||
ret = PrepareCropAndResizeBilinear(input_shape.data(), boxes, box_idx, out_tensors_.at(0)->shape().data(),
|
||||
|
@ -92,7 +95,7 @@ int ResizeCPUKernel::MallocTmpBuffer() {
|
|||
int b = in_tensors_.at(0)->Batch();
|
||||
// Malloc buffer to save coordinate. For mode CROP_AND_RESIZE, different batches require different cache coordinates.
|
||||
// For other modes, different batches have different cache coordinates.
|
||||
if (coordinate_transform_mode_ != schema::CoordinateTransformMode_CROP_AND_RESIZE) {
|
||||
if (coordinate_transform_mode_ != schema::CoordinateTransformMode_TF_CROP_AND_RESIZE) {
|
||||
b = 1;
|
||||
}
|
||||
int c = in_tensors_.at(0)->Channel();
|
||||
|
@ -203,7 +206,7 @@ int ResizeCPUKernel::RunImpl(int task_id) {
|
|||
float *line0 = line_buffer_ + new_width_ * c * 2 * task_id;
|
||||
float *line1 = line0 + new_width_ * c;
|
||||
|
||||
bool is_crop = coordinate_transform_mode_ == schema::CoordinateTransformMode_CROP_AND_RESIZE;
|
||||
bool is_crop = coordinate_transform_mode_ == schema::CoordinateTransformMode_TF_CROP_AND_RESIZE;
|
||||
ret = ResizeBilinear(input_data, output_data, input_shape.data(), out_tensors_.at(0)->shape().data(), y_bottoms_,
|
||||
y_tops_, x_lefts_, x_rights_, y_bottom_weights_, x_left_weights_, line0, line1, h_begin,
|
||||
h_end, is_crop);
|
||||
|
|
|
@ -138,7 +138,7 @@ int ResizeInt8CPUKernel::CalRatio() {
|
|||
auto out_height = out_tensor->Height();
|
||||
resize_quant_arg_.ratio_x_ = ((1 << 10) * in_width + out_width / 2) / out_width;
|
||||
resize_quant_arg_.ratio_y_ = ((1 << 10) * in_height + out_height / 2) / out_height;
|
||||
bool align_corners = coordinate_transform_mode_ == 1;
|
||||
bool align_corners = coordinate_transform_mode_ == schema::CoordinateTransformMode_ALIGN_CORNERS;
|
||||
if (align_corners && out_width > 1) {
|
||||
resize_quant_arg_.ratio_x_ = ((1 << 10) * (in_width - 1) + (out_width - 1) / 2) / (out_width - 1);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ int ResizeInt8CPUKernel::CalFloatRatio() {
|
|||
auto out_height = out_tensor->Height();
|
||||
resize_float_quant_arg_.ratio_x_ = static_cast<float>(in_width) / out_width;
|
||||
resize_float_quant_arg_.ratio_y_ = static_cast<float>(in_height) / out_height;
|
||||
bool align_corners = coordinate_transform_mode_ == 1;
|
||||
bool align_corners = coordinate_transform_mode_ == schema::CoordinateTransformMode_ALIGN_CORNERS;
|
||||
if (align_corners && out_width > 1) {
|
||||
resize_float_quant_arg_.ratio_x_ = static_cast<float>(in_width - 1) / (out_width - 1);
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ int ResizeInt8CPUKernel::RunImpl(int task_id) {
|
|||
case static_cast<int>(schema::ResizeMethod_NEAREST): {
|
||||
bool same_zp = quant_in_->zp_ == quant_out_->zp_;
|
||||
bool same_scale = abs(quant_out_->scale_ - quant_in_->scale_) < 1e-6;
|
||||
bool align_corners = coordinate_transform_mode_ == 1;
|
||||
bool align_corners = coordinate_transform_mode_ == schema::CoordinateTransformMode_ALIGN_CORNERS;
|
||||
if (same_zp && same_scale) {
|
||||
ret =
|
||||
ResizeNearestNeighborInt8Simple(input_data, output_data, input_shape.data(), out_tensors_[0]->shape().data(),
|
||||
|
|
|
@ -50,7 +50,8 @@ int ResizeNPUKernel::SetNPUInputs(const std::vector<lite::Tensor *> &inputs, con
|
|||
MS_LOG(ERROR) << " op is nullptr.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
op->set_attr_align_corners(resize_parameter_->coordinate_transform_mode_ == 1);
|
||||
op->set_attr_align_corners(resize_parameter_->coordinate_transform_mode_ ==
|
||||
schema::CoordinateTransformMode_ALIGN_CORNERS);
|
||||
op->set_input_x(*npu_inputs[0]);
|
||||
op->set_input_size(*out_size);
|
||||
op->set_attr_half_pixel_centers(resize_parameter_->preserve_aspect_ratio_);
|
||||
|
@ -61,7 +62,8 @@ int ResizeNPUKernel::SetNPUInputs(const std::vector<lite::Tensor *> &inputs, con
|
|||
MS_LOG(ERROR) << " op is nullptr.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
op->set_attr_align_corners(resize_parameter_->coordinate_transform_mode_ == 1);
|
||||
op->set_attr_align_corners(resize_parameter_->coordinate_transform_mode_ ==
|
||||
schema::CoordinateTransformMode_ALIGN_CORNERS);
|
||||
op->set_input_x(*npu_inputs[0]);
|
||||
op->set_input_size(*out_size);
|
||||
op_ = op;
|
||||
|
|
|
@ -37,3 +37,4 @@ adversarial_pruning.onnx
|
|||
residual_distill_res34_cifar10_bs_1_update.onnx
|
||||
residual_distill_res50_cifar10_bs_1_update.onnx
|
||||
encoder.onnx;1,32,83
|
||||
gts_text_detection.onnx;1,224,224,3
|
||||
|
|
|
@ -41,7 +41,7 @@ lite::PrimitiveC *OnnxResizeParser::ParseLitePrimitive(const onnx::GraphProto &o
|
|||
{"pytorch_half_pixel", schema::CoordinateTransformMode_HALF_PIXEL},
|
||||
{"align_corners", schema::CoordinateTransformMode_ALIGN_CORNERS},
|
||||
{"asymmetric", schema::CoordinateTransformMode_ASYMMETRIC},
|
||||
{"tf_crop_and_resize", schema::CoordinateTransformMode_CROP_AND_RESIZE},
|
||||
{"tf_crop_and_resize", schema::CoordinateTransformMode_TF_CROP_AND_RESIZE},
|
||||
};
|
||||
if (transform_map.find(onnx_node_attr.s()) != transform_map.end()) {
|
||||
attr->coordinateTransformMode = transform_map[onnx_node_attr.s()];
|
||||
|
|
|
@ -44,7 +44,7 @@ STATUS TFCropAndResizeParser::Parse(const tensorflow::NodeDef &tf_op,
|
|||
tensorflow::AttrValue attr_value;
|
||||
attr->format = schema::Format_NHWC;
|
||||
|
||||
attr->coordinateTransformMode = schema::CoordinateTransformMode_CROP_AND_RESIZE;
|
||||
attr->coordinateTransformMode = schema::CoordinateTransformMode_TF_CROP_AND_RESIZE;
|
||||
|
||||
// align_corners
|
||||
if (TensorFlowUtils::FindAttrValue(tf_op, "align_corners", &attr_value)) {
|
||||
|
|
|
@ -326,7 +326,8 @@ STATUS OnnxInputAdjustOpPass::AdjustResize(const CNodePtr &cnode) {
|
|||
return lite::RET_ERROR;
|
||||
}
|
||||
auto attr = reinterpret_cast<schema::ResizeT *>(value);
|
||||
if (cnode->inputs().size() > 3 && attr->coordinateTransformMode == schema::CoordinateTransformMode_CROP_AND_RESIZE) {
|
||||
if (cnode->inputs().size() > 3 &&
|
||||
attr->coordinateTransformMode == schema::CoordinateTransformMode_TF_CROP_AND_RESIZE) {
|
||||
auto new_resize_inputs = cnode->inputs();
|
||||
new_resize_inputs.erase(new_resize_inputs.begin() + 1);
|
||||
cnode->set_inputs(new_resize_inputs);
|
||||
|
|
Loading…
Reference in New Issue