From 4486c66ed49fffbe2f76d7829e02b069874dda21 Mon Sep 17 00:00:00 2001 From: Ashwini Khade Date: Mon, 15 Jun 2020 13:38:32 -0700 Subject: [PATCH] enable conv transpose 3D (#4218) * enable convtranspose 3D * test fix --- .../cpu/nn/conv_transpose_attributes.h | 8 -- onnxruntime/test/onnx/main.cc | 6 +- .../cpu/nn/conv_transpose_op_test.cc | 134 ++++++++++++++++++ 3 files changed, 139 insertions(+), 9 deletions(-) diff --git a/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h b/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h index 10e93e6a46..0bf249d40e 100644 --- a/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h +++ b/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h @@ -61,14 +61,6 @@ struct ConvTransposeAttributes : public ConvAttributes { " group: ", group); } - if (X->Shape().NumDimensions() > 4) { - // This condition is not true for 1 test in ONNX tests series: - // test_convtranspose_3d_cpu. - // TODO: the error message should tell which operator raises it. - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Only 1D and 2D ConvTranspose is supported.", - " X: ", X->Shape().ToString().c_str()); - } - if (X->Shape().NumDimensions() != F->Shape().NumDimensions()) { return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "X num_dims does not match W num_dims.", " X: ", X->Shape().ToString().c_str(), diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 188ad834b3..9b01374a56 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -491,7 +491,6 @@ int real_main(int argc, char* argv[], Ort::Env& env) { {"BERT_Squad", "test data bug"}, {"constantofshape_float_ones", "test data bug", {"onnx141", "onnx150"}}, {"constantofshape_int_zeros", "test data bug", {"onnx141", "onnx150"}}, - {"convtranspose_3d", "3d convtranspose not supported yet"}, {"cast_STRING_to_FLOAT", "Linux CI has old ONNX python package with bad test data", {"onnx141"}}, // Numpy float to string has unexpected rounding for some results given numpy default precision is meant to be 8. // "e.g. 0.296140194 -> '0.2961402' not '0.29614019'. ORT produces the latter with precision set to 8, @@ -553,6 +552,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"tf_mobilenet_v2_1.0_224", "Results mismatch"}); broken_tests.insert({"tf_mobilenet_v2_1.4_224", "Results mismatch"}); broken_tests.insert({"convtranspose_1d", "1d convtranspose not supported yet"}); + broken_tests.insert({"convtranspose_3d", "3d convtranspose not supported yet"}); } if (enable_openvino) { @@ -588,6 +588,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"maxpool_2d_dilations", "maxpool dilations not supported"}); broken_tests.insert({"mlperf_ssd_resnet34_1200", "test pass on dev box but fails on CI build"}); broken_tests.insert({"convtranspose_1d", "1d convtranspose not supported yet"}); + broken_tests.insert({"convtranspose_3d", "3d convtranspose not supported yet"}); broken_tests.insert({"maxpool_2d_uint8", "Does not work on DNNL, NNAPI"}); } @@ -602,6 +603,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"range_float_type_positive_delta_expanded", "Temporarily disabled pending investigation"}); broken_tests.insert({"range_int32_type_negative_delta_expanded", "Temporarily disabled pending investigation"}); broken_tests.insert({"convtranspose_1d", "1d convtranspose not supported yet"}); + broken_tests.insert({"convtranspose_3d", "3d convtranspose not supported yet"}); broken_tests.insert({"maxpool_2d_uint8", "result mismatch"}); broken_tests.insert({"negative_log_likelihood_loss_input_shape_is_NC_expanded", "shape mismatch"}); broken_tests.insert({"negative_log_likelihood_loss_input_shape_is_NCd1d2_expanded", "shape mismatch"}); @@ -725,6 +727,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"tf_resnet_v2_152", "TRT Engine couldn't be created"}); broken_tests.insert({"tf_resnet_v2_50", "TRT Engine couldn't be created"}); broken_tests.insert({"convtranspose_1d", "1d convtranspose not supported yet"}); + broken_tests.insert({"convtranspose_3d", "3d convtranspose not supported yet"}); } if (enable_cuda) { @@ -735,6 +738,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"tf_inception_v1", "flaky test"}); //TODO: Investigate cause for flakiness broken_tests.insert({"faster_rcnn", "Linux: faster_rcnn:output=6383:shape mismatch, expect {77} got {57}"}); broken_tests.insert({"split_zero_size_splits", "alloc failed"}); + broken_tests.insert({"convtranspose_3d", "3d convtranspose not supported yet"}); } if (enable_dml) { diff --git a/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc b/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc index 30d53336a9..1c47cb38b5 100644 --- a/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc +++ b/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc @@ -576,5 +576,139 @@ TEST(ConvTransposeTest, DimWithZero) { {kTensorrtExecutionProvider, kNGraphExecutionProvider, kAclExecutionProvider}); } +TEST(ConvTransposeTest, ConvTranspose_3D) { + ConvTransposeOpAttributes attrs = { + vector{3, 3, 3}, // kernel_shape + {}, // output_padding + {}, // output_shape + vector{0, 0, 0, 0, 0, 0}, // pads + vector{1, 1, 1}, // strides + vector{1, 1, 1}, // dilations + 1 // group + }; + + vector X = {0.82670355f, -0.041401573f, 0.026631273f, -0.9765811f, -0.1628872f, + 0.6781846f, 0.38049284f, 0.5573809f, -0.56348205f, 0.6192993f, + -1.3645133f, -0.025706587f, 0.3444407f, 1.6839422f, 0.44769225f, + -0.94038606f, 0.1865747f, 0.22024752f, -1.3399711f, 0.48898873f, + + 1.3871458f, -0.4798906f, -1.3498452f, 1.9507161f, -0.36717513f, + -1.3160661f, 0.04001215f, -1.6359671f, -0.27051282f, 1.3602601f, + -0.6915065f, -1.480801f, 0.008796313f, -0.42371505f, 0.2846156f, + -0.041113783f, -0.8274711f, 1.649845f, -1.4032182f, 0.9754836f, + + -1.061012f, 1.9735539f, 1.5394408f, 0.46846536f, 1.5393354f, + -0.10323338f, -0.25534126f, 0.03429055f, 0.3142054f, -0.4348722f, + -1.399293f, 0.8268838f, 0.061832584f, 1.32346f, 1.326872f, + 0.015338173f, -0.7772104f, 0.82150716f, -0.8285072f, -0.745792f}; + + vector X_shape = {1, 1, 3, 4, 5}; + + vector W = {0.042848215f, 0.063926056f, -0.01786653f, + -0.007932588f, -0.06435914f, 0.045959294f, + -0.03683681f, 0.076584175f, -0.083441734f, + + -0.08745442f, -0.053135775f, -0.07282642f, + -0.11123853f, -0.114605635f, 0.050257847f, + 0.03769763f, 0.008607149f, -2.6613474e-05f, + + -0.06418988f, 0.11692271f, 0.12203565f, + 0.042627826f, 0.098034576f, -0.010402724f, + -0.12522504f, -0.10751359f, 0.12747335f, + + -0.056666218f, -0.02816818f, -0.00018641353f, + -0.053967796f, 0.08958836f, -0.060138382f, + -0.108521f, -0.12912428f, 0.05260901f, + + 0.1330998f, -0.09916313f, -0.12123653f, + 0.022630543f, -0.018046886f, 0.08967489f, + -0.033889048f, -0.006379664f, 0.059431687f, + + 0.04010451f, 0.103126734f, 0.0036035478f, + 0.030677304f, 0.017750308f, 0.012351051f, + 0.017721564f, -0.013308428f, -0.011259012f,}; + + vector W_shape = {1, 2, 3, 3, 3}; + + vector B_shape = {2}; + vector B = {-0.11784090101718903f, -0.060990236699581146f}; + + + vector Y_shape = {1, 2, 5, 6, 7}; + auto expected_vals = {-0.08241813f, -0.06676699f, -0.13411677f, -0.15724352f, -0.18772511f, -0.11080553f, -0.114930674f, + -0.0953398f, -0.111061305f, -0.0413035f, -0.10902196f, -0.071916685f, -0.102583766f, -0.13639182f, + -0.21214074f, -0.18799849f, -0.15122052f, 0.00434383f, -0.011207409f, -0.11604968f, -0.08378546f, + -0.1722928f, -0.044016793f, -0.1914465f, -0.16952308f, -0.39505655f, 0.080385f, -0.15767722f, + -0.060116887f, -0.16235165f, -0.075614765f, -0.14631891f, 0.05837299f, -0.31712085f, -0.13272354f, + -0.08320008f, -0.1967324f, -0.033198006f, -0.06718128f, -0.2568521f, 0.0314174f, -0.15864298f, + + -0.13070306f, -0.09003539f, -0.29147533f, -0.024966106f, 0.079442084f, -0.096389435f, -0.09941827f, + -0.3365072f, -0.4451772f, -0.13154466f, -0.08992967f, -0.16572365f, 0.06494926f, -0.21230686f, + -0.11307171f, -0.056943115f, -0.35291147f, -0.317253f, -0.070464894f, -0.6300395f, -0.031246513f, + 0.19395588f, 0.011135533f, 0.096916616f, -0.3942836f, -0.29872403f, 0.16881491f, -0.24881886f, + -0.038873613f, -0.032735735f, -0.21593677f, 0.088557824f, 0.13849314f, -0.30753696f, -0.07219358f, + -0.15177673f, -0.09156879f, -0.2286228f, 0.080623806f, -0.39201033f, 0.07819712f, -0.19924995f, + + -0.3376814f, -0.033524483f, 0.230105f, -0.0377952f, -0.12315659f, -0.28858358f, -0.13848148f, + -0.16134796f, 0.012239918f, 0.27276647f, 0.020731017f, -0.4651906f, -0.14341736f, -0.07956973f, + 0.1342433f, -0.16956037f, 0.310399f, 0.34338957f, -0.040192716f, 0.12504166f, -0.21490449f, + -0.15410437f, -0.1338158f, -0.39244395f, 0.29117042f, -0.26415867f, -0.4450379f, 0.0699404f, + 0.042872816f, -0.14961651f, -0.17582522f, -0.6919577f, -0.13723494f, -0.0681901f, -0.16183335f, + -0.0021959245f, -0.0418434f, -0.32134426f, 0.16967098f, -0.08680786f, -0.32077473f, 0.0066963434f, + + -0.114091426f, -0.041066267f, -0.080250874f, -0.72594404f, -0.30254412f, -0.03862554f, -0.27475363f, + 0.15282185f, -0.22887689f, -0.72043663f, -0.47111863f, -0.3755179f, -0.20074406f, 0.16101281f, + -0.20939936f, -0.21245953f, 0.11726546f, -0.8030824f, -0.5866715f, 0.20001571f, -0.26259118f, + 0.17054747f, 0.061063558f, -0.6348493f, 0.2620284f, -0.782919f, -0.31278569f, 0.2926497f, + -0.08745579f, 0.20646049f, -0.050303012f, -0.13460274f, 0.060659587f, -0.037006564f, -0.1292249f, + -0.11211421f, -0.038967483f, -0.21644044f, -0.24912538f, 0.08591288f, -0.40798867f, 0.006527111f, + + -0.049734667f, -0.3685795f, -0.11538547f, 0.27292788f, 0.025990233f, 0.119311824f, 0.0700129f, + -0.156443f, -0.13340846f, 0.10764159f, -0.014803357f, 0.046525866f, 0.015691683f, -0.1869241f, + 0.1004442f, -0.4885978f, -0.7585998f, -0.047841772f, -0.07570776f, 0.0471261f, 0.24483289f, + -0.16554686f, -0.1250152f, -0.15132052f, -0.08515984f, 0.14412321f, -0.1030291f, -0.2780918f, + 0.05803944f, -0.10257156f, -0.4341917f, -0.13150966f, -0.53996617f, -0.15628646f, 0.059058204f, + -0.11976162f, -0.022163756f, -0.13519828f, -0.20148787f, 0.16934697f, -0.14327072f, -0.2129095f, + + -0.107836396f, -0.0819309f, -0.06148723f, -0.0063935146f, -0.02425649f, -0.056219954f, -0.06095987f, + -0.14403576f, -0.025357183f, -0.15828207f, 0.012748428f, -0.16061643f, -0.03419252f, -0.05130991f, + -0.109983265f, -0.08312916f, -0.07035978f, -0.008285124f, -0.10610263f, -0.01489019f, -0.106886685f, + -0.007659614f, -0.2947925f, -0.09132287f, -0.040577132f, 0.089866154f, -0.24528673f, -0.055424154f, + 0.13783869f, 0.023674607f, -0.10545369f, -0.20873478f, -0.4685722f, 0.09418375f, -0.06684458f, + 0.0410614f, 0.04018917f, -0.15845582f, 0.06580096f, 0.070554025f, -0.19462511f, -0.03526502f, + + -0.02956047f, -0.16035908f, -0.0638171f, -0.261022f, -0.022948403f, 0.08353848f, -0.041173913f, + 0.04770004f, 0.091520615f, 0.006987013f, -0.39962748f, 0.23266485f, -0.32719564f, -0.12885109f, + -0.29559937f, -0.08031146f, 0.76168066f, 0.0009028502f, -0.4091536f, -0.14801738f, -0.17058557f, + -0.05754847f, 0.2955231f, -0.089874476f, 0.17254886f, -0.13203058f, -0.007648442f, 0.010943003f, + 0.04123217f, 0.26074114f, -0.24313056f, 0.1008903f, -0.26472318f, 0.01998391f, -0.03422378f, + -0.024659738f, 0.033793047f, -0.1998924f, -0.110185415f, 0.10620246f, -0.3435271f, 0.019390412f, + + 0.21691665f, -0.26076952f, -0.5040901f, 0.28383943f, -0.34750903f, -0.32484284f, -0.01734912f, + -0.08909689f, -0.0466362f, 0.21648785f, 0.06733417f, 0.009496197f, 0.18728223f, -0.35110205f, + -0.04908372f, -0.36729553f, -0.346236f, -0.13589534f, -0.16435221f, -0.16853788f, 0.12264759f, + -0.019215636f, -0.38316554f, 0.35669535f, -0.56980205f, -0.059346225f, 0.15008381f, -0.1751053f, + 0.059508912f, 0.116622455f, -0.32607535f, -0.22282779f, -0.29149055f, -0.3829086f, 0.15905643f, + -0.077926554f, 0.06549884f, -0.09004557f, -0.15897253f, 0.26810864f, -0.08931713f, -0.047756508f, + + -0.14657992f, 0.43070868f, -0.021787114f, -0.4532621f, 0.092385404f, -0.30126676f, -0.24893704f, + -0.10896815f, -0.14514503f, -0.21353528f, 0.018723361f, 0.037694372f, 0.11514955f, 0.13013864f, + -0.25713888f, -0.056000195f, -0.3505367f, 0.0836427f, -0.032017898f, -0.26742116f, -0.14740711f, + -0.13330215f, -0.18958306f, -0.08968873f, 0.014723815f, -0.20343366f, 0.3098968f, 0.114284225f, + -0.026738256f, -0.14110464f, -0.054464605f, -0.17529932f, -0.0030034669f, -0.050670102f, -0.04016705f, + -0.062238634f, -0.04886609f, -0.042247344f, -0.12185234f, 0.0357792f, -0.10265522f, -0.116296895f, + + -0.1035416f, -0.09126053f, 0.20045105f, 0.12366664f, 0.05460281f, 0.09944453f, -0.055443168f, + -0.09767935f, -0.040166672f, -0.01716708f, 0.020299219f, 0.02864775f, -0.07159522f, -0.04354491f, + -0.1390779f, -0.13270372f, 0.02992779f, -0.025869183f, 0.12530258f, 0.05101595f, -0.07891131f, + -0.1051311f, -0.093200594f, -0.10368025f, 0.047598884f, -0.12069465f, -0.098738566f, -0.042393237f, + -0.08531736f, -0.051284637f, -0.04354899f, -0.06810297f, -0.083224006f, -0.11702064f, -0.08514082f, + -0.06071842f, -0.07496775f, -0.03626109f, -0.07785503f, -0.07243007f, -0.041736744f, -0.052593358f}; + + TestConvTransposeOp(attrs, {X, W, B}, {X_shape, W_shape, B_shape}, expected_vals, Y_shape, + OpTester::ExpectResult::kExpectSuccess, "", + {kTensorrtExecutionProvider, kCudaExecutionProvider}); +} + } // namespace test } // namespace onnxruntime