Unverified Commit 05f4f731 authored by Shucai Xiao's avatar Shucai Xiao Committed by GitHub
Browse files

Add cont before reshape in parsing resize (#792)

* add a contiguous check before the reshape in parsing resize

* clang format

* add a unit test to the fix in parse_resize

* clang format
parent abe4ec3e
...@@ -189,8 +189,9 @@ struct parse_resize : op_parser<parse_resize> ...@@ -189,8 +189,9 @@ struct parse_resize : op_parser<parse_resize>
// reshape input to one-dimension // reshape input to one-dimension
std::vector<int64_t> rsp_lens = {static_cast<int64_t>(in_s.elements())}; std::vector<int64_t> rsp_lens = {static_cast<int64_t>(in_s.elements())};
shape ind_s{shape::int32_type, out_lens}; shape ind_s{shape::int32_type, out_lens};
auto rsp = info.add_instruction(make_op("reshape", {{"dims", rsp_lens}}), args[0]); auto arg_cont = info.make_contiguous(args[0]);
auto ins_ind = info.add_literal(literal(ind_s, ind)); auto rsp = info.add_instruction(make_op("reshape", {{"dims", rsp_lens}}), arg_cont);
auto ins_ind = info.add_literal(literal(ind_s, ind));
return info.add_instruction(make_op("gather", {{"axis", 0}}), rsp, ins_ind); return info.add_instruction(make_op("gather", {{"axis", 0}}), rsp, ins_ind);
} }
}; };
......
...@@ -3069,6 +3069,32 @@ def resize_downsample_c_test(): ...@@ -3069,6 +3069,32 @@ def resize_downsample_c_test():
return ([node], [X], [Y], [scale_tensor]) return ([node], [X], [Y], [scale_tensor])
@onnx_test
def resize_nonstd_input_test():
scales = np.array([1.0, 1.0, 0.6, 0.6], dtype=np.float32)
scale_tensor = helper.make_tensor(name='scales',
data_type=TensorProto.FLOAT,
dims=scales.shape,
vals=scales.flatten().astype(np.float32))
X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 1, 4, 2])
Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 1, 1, 2])
trn = onnx.helper.make_node('Transpose',
inputs=['X'],
outputs=['TX'],
perm=[0, 1, 3, 2])
node = onnx.helper.make_node('Resize',
inputs=['TX', '', 'scales'],
outputs=['Y'],
coordinate_transformation_mode='asymmetric',
mode='nearest',
nearest_mode='ceil')
return ([trn, node], [X], [Y], [scale_tensor])
@onnx_test @onnx_test
def resize_outsize_test(): def resize_outsize_test():
out_lens = np.array([1, 1, 4, 6], dtype=np.int64) out_lens = np.array([1, 1, 4, 6], dtype=np.int64)
......
...@@ -2690,6 +2690,35 @@ TEST_CASE(resize_outsize_test) ...@@ -2690,6 +2690,35 @@ TEST_CASE(resize_outsize_test)
EXPECT(p == prog); EXPECT(p == prog);
} }
TEST_CASE(resize_nonstd_input_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<float> ds = {1.0f, 1.0f, 0.6f, 0.6f};
migraphx::shape ss{migraphx::shape::float_type, {4}};
mm->add_literal(migraphx::literal{ss, ds});
migraphx::shape sx{migraphx::shape::float_type, {1, 1, 4, 2}};
auto inx = mm->add_parameter("X", sx);
migraphx::shape si{migraphx::shape::int32_type, {1, 1, 1, 2}};
std::vector<int> ind = {0, 4};
auto li = mm->add_literal(migraphx::literal(si, ind));
auto tx = mm->add_instruction(migraphx::make_op("transpose", {{"dims", {0, 1, 3, 2}}}), inx);
mm->add_instruction(migraphx::make_op("undefined"));
auto tx_cont = mm->add_instruction(migraphx::make_op("contiguous"), tx);
auto lrsp = mm->add_instruction(migraphx::make_op("reshape", {{"dims", {8}}}), tx_cont);
auto r = mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), lrsp, li);
mm->add_return({r});
auto prog = migraphx::parse_onnx("resize_nonstd_input_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(resize_upsample_pc_test) TEST_CASE(resize_upsample_pc_test)
{ {
migraphx::program p; migraphx::program p;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment