diff --git a/bazel/ngraph.BUILD b/bazel/ngraph.BUILD index 5ac313c8a..7e3af362a 100644 --- a/bazel/ngraph.BUILD +++ b/bazel/ngraph.BUILD @@ -166,6 +166,7 @@ cc_library( "src/ngraph/runtime/cpu/builder/convert.cpp", "src/ngraph/runtime/cpu/builder/convert_layout.cpp", "src/ngraph/runtime/cpu/builder/convolution.cpp", + "src/ngraph/runtime/cpu/builder/cum_sum.cpp", "src/ngraph/runtime/cpu/builder/dot.cpp", "src/ngraph/runtime/cpu/builder/dropout.cpp", "src/ngraph/runtime/cpu/builder/embedding_lookup.cpp", diff --git a/ngraph_bridge/ngraph_builder.cc b/ngraph_bridge/ngraph_builder.cc index 89b3271e3..fce3509da 100644 --- a/ngraph_bridge/ngraph_builder.cc +++ b/ngraph_bridge/ngraph_builder.cc @@ -27,6 +27,7 @@ #include "ngraph/builder/quantize_builder.hpp" #include "ngraph/op/argmax.hpp" #include "ngraph/op/argmin.hpp" +#include "ngraph/op/experimental/layers/interpolate.hpp" #include "ngraph/op/util/logical_reduction.hpp" #include "ngraph/slice_plan.hpp" @@ -1630,6 +1631,56 @@ static Status TranslateConv3DOp(const Node* op, return Status::OK(); } +// Translate TranslateCropAndResizeOp op +static Status TranslateCropAndResizeOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { + shared_ptr image, boxes, box_ind, crop_size; + TF_RETURN_IF_ERROR( + GetInputNodes(ng_op_map, op, &image, &boxes, &box_ind, &crop_size)); + + // Get the attributes + float extrapolation_value; + std::string method; + TF_RETURN_IF_ERROR( + GetNodeAttr(op->attrs(), "extrapolation_value", &extrapolation_value)); + TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "method", &method)); + + ng::op::CropAndResize::ResizeMethod ng_method = + ng::op::CropAndResize::ResizeMethod::unspecified; + if (method == "bilinear") { + ng_method = ng::op::CropAndResize::ResizeMethod::bilinear; + } else if (method == "nearest") { + ng_method = ng::op::CropAndResize::ResizeMethod::nearest; + } else { + return errors::Internal( + "Expected crop and resize's interpolation mode to be bilinear or " + "nearest, but got ", + extrapolation_value, " in op ", op->name()); + } + + SaveNgOp(ng_op_map, op->name(), + ConstructNgNode(op->name(), image, boxes, + box_ind, crop_size, ng_method, + extrapolation_value)); + return Status::OK(); +} + +static Status TranslateCumsumOp(const Node* op, + const std::vector&, + Builder::OpMap& ng_op_map) { + shared_ptr ng_x, ng_axis; + TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &ng_x, &ng_axis)); + bool exclusive, reverse; + TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "exclusive", &exclusive)); + TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "reverse", &reverse)); + + SaveNgOp(ng_op_map, op->name(), + ConstructNgNode(op->name(), ng_x, ng_axis, exclusive, + reverse)); + return Status::OK(); +} + // Translate DepthToSpace op static Status TranslateDepthToSpaceOp(const Node* op, const std::vector&, @@ -3763,6 +3814,33 @@ static Status TranslateReshapeOp( return Status::OK(); } +static Status TranslateResizeBilinearOp( + const Node* op, const std::vector& static_input_map, + Builder::OpMap& ng_op_map) { + shared_ptr images, size; + TF_RETURN_IF_ERROR(GetInputNodes(ng_op_map, op, &images, &size)); + + bool align_corners; + TF_RETURN_IF_ERROR(GetNodeAttr(op->attrs(), "align_corners", &align_corners)); + + ngraph::op::InterpolateAttrs attrs; + attrs.align_corners = align_corners; + attrs.mode = "linear"; + attrs.antialias = false; + // The TF "images" is has dimensions [batch, height, width, channels]. + // So 1 and 2 are the spatial axes + // TODO check this parameter + attrs.axes = {1, 2}; + // TODO: pads_begin and pads_end are not populated. Check correctness + + auto size_int64 = + ConstructNgNode(op->name(), size, ngraph::element::i64); + SaveNgOp(ng_op_map, op->name(), ConstructNgNode( + op->name(), images, size_int64, attrs)); + + return Status::OK(); +} + static Status TranslateRsqrtOp( const Node* op, const std::vector& static_input_map, Builder::OpMap& ng_op_map) { @@ -3781,6 +3859,34 @@ static Status TranslateRsqrtOp( }); } +static Status TranslateScatterNdOp( + const Node* op, const std::vector& static_input_map, + Builder::OpMap& ng_op_map) { + shared_ptr ng_indices; + shared_ptr ng_updates; + TF_RETURN_IF_ERROR( + GetInputNodes(ng_op_map, op, &ng_indices, &ng_updates, nullptr)); + + std::vector ng_shape; + TF_RETURN_IF_ERROR(GetStaticInputVector(op, 2, static_input_map, &ng_shape)); + // Copy the int vector to a size_t vector, because that is what ng::Shape + // accepts + std::vector ng_shape_size_t(ng_shape.begin(), ng_shape.end()); + + // Create a tensor and populate the tensor with "0" to Add to ScatterNd + auto et = ng_updates->get_element_type(); + std::vector constant_values(ng::shape_size(ng_shape_size_t), + "0"); + auto ng_inputs = ConstructNgNode( + op->name(), et, ng::Shape(ng_shape_size_t), constant_values); + + SaveNgOp(ng_op_map, op->name(), + ConstructNgNode(op->name(), ng_inputs, + ng_indices, ng_updates)); + + return Status::OK(); +} + static Status TranslateRsqrtGradOp(const Node* op, const std::vector&, Builder::OpMap& ng_op_map) { @@ -5005,6 +5111,7 @@ const static std::map< {"All", TranslateDirectReduceOp}, {"ArgMax", TranslateArgMinMaxOp}, {"ArgMin", TranslateArgMinMaxOp}, + {"Atan2", TranslateBinaryOp}, {"AvgPool", TranslateAvgPoolOp}, {"AvgPoolGrad", TranslateAvgPoolGradOp}, {"BatchMatMul", TranslateBatchMatMulOp}, {"BatchMatMulV2", TranslateBatchMatMulV2Op}, @@ -5016,7 +5123,8 @@ const static std::map< {"Conv2DBackpropFilter", TranslateConv2DBackpropFilterOp}, {"Conv2DBackpropInput", TranslateConv2DBackpropInputOp}, {"Conv3D", TranslateConv3DOp}, {"Cos", TranslateUnaryOp}, - {"DepthToSpace", TranslateDepthToSpaceOp}, + {"CropAndResize", TranslateCropAndResizeOp}, + {"Cumsum", TranslateCumsumOp}, {"DepthToSpace", TranslateDepthToSpaceOp}, {"DepthwiseConv2dNative", TranslateDepthwiseConv2dNativeOp}, {"Dequantize", TranslateDequantizeOp}, {"Equal", TranslateBinaryOp}, @@ -5085,9 +5193,11 @@ const static std::map< {"Reciprocal", TranslateReciprocalOp}, {"Relu", TranslateUnaryOp}, {"Relu6", TranslateRelu6Op}, {"ReluGrad", TranslateReluGradOp}, {"Reshape", TranslateReshapeOp}, + {"ResizeBilinear", TranslateResizeBilinearOp}, {"Rsqrt", TranslateRsqrtOp}, {"RsqrtGrad", TranslateRsqrtGradOp}, - {"Select", TranslateSelectOp}, {"Shape", TranslateShapeOp}, - {"Sigmoid", TranslateSigmoidOp}, {"SigmoidGrad", TranslateSigmoidGradOp}, + {"ScatterNd", TranslateScatterNdOp}, {"Select", TranslateSelectOp}, + {"Shape", TranslateShapeOp}, {"Sigmoid", TranslateSigmoidOp}, + {"SigmoidGrad", TranslateSigmoidGradOp}, {"Sin", TranslateUnaryOp}, {"Size", TranslateSizeOp}, {"Sign", TranslateUnaryOp}, {"Slice", TranslateSliceOp}, {"Snapshot", TranslateIdentityOp}, {"Softmax", TranslateSoftmaxOp}, diff --git a/ngraph_bridge/ngraph_mark_for_clustering.cc b/ngraph_bridge/ngraph_mark_for_clustering.cc index b4aec04fc..6c6d1d338 100644 --- a/ngraph_bridge/ngraph_mark_for_clustering.cc +++ b/ngraph_bridge/ngraph_mark_for_clustering.cc @@ -241,6 +241,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, {"All", {std::make_shared()}}, {"ArgMax", {std::make_shared()}}, {"ArgMin", {std::make_shared()}}, + {"Atan2", {std::make_shared()}}, {"AvgPool", {std::make_shared()}}, {"AvgPoolGrad", {std::make_shared()}}, {"BatchMatMul", @@ -275,6 +276,8 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, {std::make_shared(), std::make_shared()}}, {"Cos", {std::make_shared()}}, + {"CropAndResize", {std::make_shared()}}, + {"Cumsum", {std::make_shared()}}, {"DepthToSpace", {std::make_shared()}}, {"DepthwiseConv2dNative", {std::make_shared(), @@ -481,7 +484,10 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, {constant, std::make_shared(), std::make_shared()}}, {"ReluGrad", {relu}}, - {"Reshape", {std::make_shared()}}, + // TODO: remove Convert later + {"ResizeBilinear", + {std::make_shared(), + std::make_shared()}}, {"Rsqrt", {constant, std::make_shared()}}, {"RsqrtGrad", {constant, std::make_shared(), @@ -491,6 +497,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, std::make_shared(), std::make_shared()}}, {"Reshape", {constant}}, + {"ScatterNd", {constant, std::make_shared()}}, {"Shape", {constant}}, {"Sigmoid", {constant, std::make_shared(), @@ -608,6 +615,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, confirmation_function_map["All"] = SimpleConfirmationFunction(); confirmation_function_map["ArgMax"] = SimpleConfirmationFunction(); confirmation_function_map["ArgMin"] = SimpleConfirmationFunction(); + confirmation_function_map["Atan2"] = SimpleConfirmationFunction(); confirmation_function_map["AvgPool"] = SimpleConfirmationFunction(); confirmation_function_map["AvgPoolGrad"] = SimpleConfirmationFunction(); confirmation_function_map["BatchMatMul"] = SimpleConfirmationFunction(); @@ -623,7 +631,9 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, confirmation_function_map["Conv2DBackpropInput"] = SimpleConfirmationFunction(); confirmation_function_map["Conv3D"] = SimpleConfirmationFunction(); + confirmation_function_map["CropAndResize"] = SimpleConfirmationFunction(); confirmation_function_map["Cos"] = SimpleConfirmationFunction(); + confirmation_function_map["Cumsum"] = SimpleConfirmationFunction(); confirmation_function_map["DepthwiseConv2dNative"] = SimpleConfirmationFunction(); confirmation_function_map["DepthToSpace"] = [](Node* n, bool* result) { @@ -747,8 +757,11 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, confirmation_function_map["Relu6"] = SimpleConfirmationFunction(); confirmation_function_map["ReluGrad"] = SimpleConfirmationFunction(); confirmation_function_map["Reshape"] = SimpleConfirmationFunction(); + confirmation_function_map["ResizeBilinear"] = + SimpleConfirmationFunction(); confirmation_function_map["Rsqrt"] = SimpleConfirmationFunction(); confirmation_function_map["RsqrtGrad"] = SimpleConfirmationFunction(); + confirmation_function_map["ScatterNd"] = SimpleConfirmationFunction(); confirmation_function_map["Select"] = SimpleConfirmationFunction(); confirmation_function_map["Shape"] = SimpleConfirmationFunction(); confirmation_function_map["Sigmoid"] = SimpleConfirmationFunction(); @@ -808,6 +821,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, type_constraint_map["ArgMax"]["Tidx"] = NGraphIndexDTypes(); type_constraint_map["ArgMin"]["T"] = NGraphNumericDTypes(); type_constraint_map["ArgMin"]["Tidx"] = NGraphIndexDTypes(); + type_constraint_map["Atan2"]["T"] = NGraphRealDTypes(); type_constraint_map["AvgPool"]["T"] = NGraphNumericDTypes(); type_constraint_map["AvgPoolGrad"]["T"] = NGraphNumericDTypes(); type_constraint_map["BatchMatMul"]["T"] = NGraphNumericDTypes(); @@ -822,7 +836,10 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, type_constraint_map["Conv2D"]["T"] = NGraphNumericDTypes(); type_constraint_map["Conv2DBackpropInput"]["T"] = NGraphNumericDTypes(); type_constraint_map["Conv3D"]["T"] = NGraphNumericDTypes(); + type_constraint_map["CropAndResize"]["T"] = NGraphNumericDTypes(); type_constraint_map["Cos"]["T"] = NGraphRealDTypes(); + type_constraint_map["Cumsum"]["T"] = NGraphNumericDTypes(); + type_constraint_map["Cumsum"]["Tidx"] = NGraphIndexDTypes(); type_constraint_map["DepthToSpace"]["T"] = NGraphDTypes(); type_constraint_map["DepthwiseConv2dNative"]["T"] = NGraphNumericDTypes(); type_constraint_map["Dequantize"]["T"] = NGraphSupportedQuantizedDTypes(); @@ -939,8 +956,11 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, type_constraint_map["ReluGrad"]["T"] = NGraphNumericDTypes(); type_constraint_map["Reshape"]["T"] = NGraphDTypes(); type_constraint_map["Reshape"]["Tshape"] = NGraphIndexDTypes(); + type_constraint_map["ResizeBilinear"]["T"] = NGraphNumericDTypes(); type_constraint_map["Rsqrt"]["T"] = NGraphDTypes(); type_constraint_map["RsqrtGrad"]["T"] = NGraphRealDTypes(); + type_constraint_map["ScatterNd"]["T"] = NGraphDTypes(); + type_constraint_map["ScatterNd"]["Tindices"] = NGraphIndexDTypes(); type_constraint_map["Select"]["T"] = NGraphDTypes(); type_constraint_map["Shape"]["T"] = NGraphDTypes(); type_constraint_map["Shape"]["out_type"] = NGraphIndexDTypes(); @@ -1035,6 +1055,7 @@ Status MarkForClustering(Graph* graph, const std::set skip_these_nodes, }; set_attributes_map["RandomUniform"] = SetStaticInputs({0}); set_attributes_map["Reshape"] = SetStaticInputs({1}); + set_attributes_map["ScatterNd"] = SetStaticInputs({2}); set_attributes_map["Slice"] = SetStaticInputs({1, 2}); set_attributes_map["Split"] = SetStaticInputs({0}); set_attributes_map["SplitV"] = SetStaticInputs({1, 2}); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7648216ed..b85acb356 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC test_index_library.cpp test_ngraph_data_cache.cpp test_utilities.cpp + test_image_ops.cpp test_math_ops.cpp test_nn_ops.cpp test_array_ops.cpp diff --git a/test/python/tensorflow/python_tests_list.txt b/test/python/tensorflow/python_tests_list.txt index 0c3cded52..f894ac8ba 100644 --- a/test/python/tensorflow/python_tests_list.txt +++ b/test/python/tensorflow/python_tests_list.txt @@ -398,6 +398,92 @@ relu_op_test.ReluTest.testGradientFloat32 relu_op_test.ReluTest.testGradientFloat64 relu_op_test.ReluTest.testGradientScalar +scan_ops_test.CumsumTest.test1D +scan_ops_test.CumsumTest.test2D +scan_ops_test.CumsumTest.test3D +scan_ops_test.CumsumTest.test6D +scan_ops_test.CumsumTest.testAxisType +scan_ops_test.CumsumTest.testEmpty +scan_ops_test.CumsumTest.testGradient +scan_ops_test.CumsumTest.testGradient2D +scan_ops_test.CumsumTest.testGradientExclusive +scan_ops_test.CumsumTest.testGradientExclusiveReverse +scan_ops_test.CumsumTest.testGradientReverse +#This test fails due to error string matching issue +#scan_ops_test.CumsumTest.testInvalidAxis +scan_ops_test.CumsumTest.testLarge +scan_ops_test.CumsumTest.test_session + +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testBool +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape3 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testInvalidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testString +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.test_session +scatter_nd_ops_test.ScatterNdTensorTest.testTensorScatterUpdateWithForwarding +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSub +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSubGradients +scatter_nd_ops_test.ScatterNdTensorTest.test_session +# This test fails on CPU backend on char (and maybe other data types) +# scatter_nd_ops_test.ScatterNdTest.testBool +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape1 +# TODO: Test failing due to incorrect error message +# scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape3 +# This test fails on CPU backend on some unsupported data types +# scatter_nd_ops_test.ScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testInvalidShape +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testString +scatter_nd_ops_test.ScatterNdTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdTest.test_session +scatter_nd_ops_test.StatefulScatterNdTest.testConcurrentUpdates +scatter_nd_ops_test.StatefulScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.StatefulScatterNdTest.testResVarInvalidOutputShape +scatter_nd_ops_test.StatefulScatterNdTest.testScatterOutOfRangeCpu +#scatter_nd_ops_test.StatefulScatterNdTest.testScatterRepeatIndices +scatter_nd_ops_test.StatefulScatterNdTest.testSimple +scatter_nd_ops_test.StatefulScatterNdTest.testSimple2 +scatter_nd_ops_test.StatefulScatterNdTest.testSimple3 +scatter_nd_ops_test.StatefulScatterNdTest.testSimpleResource +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankAdd +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankSub +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankUpdate +scatter_nd_ops_test.StatefulScatterNdTest.test_session + slice_op_test.SliceTest.testComplex slice_op_test.SliceTest.testEmpty slice_op_test.SliceTest.testGradientsAll diff --git a/test/python/tensorflow/python_tests_list_gpu.txt b/test/python/tensorflow/python_tests_list_gpu.txt index 4e779fa33..80729e7cb 100644 --- a/test/python/tensorflow/python_tests_list_gpu.txt +++ b/test/python/tensorflow/python_tests_list_gpu.txt @@ -390,6 +390,89 @@ relu_op_test.ReluTest.testGradientFloat32 relu_op_test.ReluTest.testGradientScalar relu_op_test.ReluTest.testNumbers +scan_ops_test.CumsumTest.test1D +scan_ops_test.CumsumTest.test2D +scan_ops_test.CumsumTest.test3D +scan_ops_test.CumsumTest.test6D +scan_ops_test.CumsumTest.testAxisType +scan_ops_test.CumsumTest.testEmpty +scan_ops_test.CumsumTest.testGradient +scan_ops_test.CumsumTest.testGradient2D +scan_ops_test.CumsumTest.testGradientExclusive +scan_ops_test.CumsumTest.testGradientExclusiveReverse +scan_ops_test.CumsumTest.testGradientReverse +#This test fails due to error string matching issue +#scan_ops_test.CumsumTest.testInvalidAxis +scan_ops_test.CumsumTest.testLarge +scan_ops_test.CumsumTest.test_session + +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testBool +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape3 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testInvalidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testString +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.test_session +scatter_nd_ops_test.ScatterNdTensorTest.testTensorScatterUpdateWithForwarding +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSub +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSubGradients +scatter_nd_ops_test.ScatterNdTensorTest.test_session +scatter_nd_ops_test.ScatterNdTest.testBool +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape1 +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape3 +scatter_nd_ops_test.ScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testInvalidShape +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testString +scatter_nd_ops_test.ScatterNdTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdTest.test_session +scatter_nd_ops_test.StatefulScatterNdTest.testConcurrentUpdates +scatter_nd_ops_test.StatefulScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.StatefulScatterNdTest.testResVarInvalidOutputShape +scatter_nd_ops_test.StatefulScatterNdTest.testScatterOutOfRangeCpu +#scatter_nd_ops_test.StatefulScatterNdTest.testScatterRepeatIndices +scatter_nd_ops_test.StatefulScatterNdTest.testSimple +scatter_nd_ops_test.StatefulScatterNdTest.testSimple2 +scatter_nd_ops_test.StatefulScatterNdTest.testSimple3 +scatter_nd_ops_test.StatefulScatterNdTest.testSimpleResource +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankAdd +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankSub +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankUpdate +scatter_nd_ops_test.StatefulScatterNdTest.test_session + slice_op_test.SliceTest.testComplex slice_op_test.SliceTest.testEmpty slice_op_test.SliceTest.testGradientsAll diff --git a/test/python/tensorflow/python_tests_list_mac.txt b/test/python/tensorflow/python_tests_list_mac.txt index 4c4f078a0..863446129 100644 --- a/test/python/tensorflow/python_tests_list_mac.txt +++ b/test/python/tensorflow/python_tests_list_mac.txt @@ -398,6 +398,90 @@ relu_op_test.ReluTest.testGradientFloat32 relu_op_test.ReluTest.testGradientFloat64 relu_op_test.ReluTest.testGradientScalar +scan_ops_test.CumsumTest.test1D +scan_ops_test.CumsumTest.test2D +scan_ops_test.CumsumTest.test3D +scan_ops_test.CumsumTest.test6D +scan_ops_test.CumsumTest.testAxisType +scan_ops_test.CumsumTest.testEmpty +scan_ops_test.CumsumTest.testGradient +scan_ops_test.CumsumTest.testGradient2D +scan_ops_test.CumsumTest.testGradientExclusive +scan_ops_test.CumsumTest.testGradientExclusiveReverse +scan_ops_test.CumsumTest.testGradientReverse +#This test fails due to error string matching issue +#scan_ops_test.CumsumTest.testInvalidAxis +scan_ops_test.CumsumTest.testLarge +scan_ops_test.CumsumTest.test_session + +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testBool +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testEmptyOutputShape3 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testInvalidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testString +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdNonAliasingAddTest.test_session +scatter_nd_ops_test.ScatterNdTensorTest.testTensorScatterUpdateWithForwarding +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSub +scatter_nd_ops_test.ScatterNdTensorTest.testUpdateAddSubGradients +scatter_nd_ops_test.ScatterNdTensorTest.test_session +# scatter_nd_ops_test.ScatterNdTest.testBool +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape1 +# scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape2 +scatter_nd_ops_test.ScatterNdTest.testEmptyOutputShape3 +# scatter_nd_ops_test.ScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2ElementUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank2SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank3SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testGradientsRank7SliceUpdate +scatter_nd_ops_test.ScatterNdTest.testInvalidShape +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.ScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.ScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.ScatterNdTest.testScatterNdRepatedIndicesAdd +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch1DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim2 +scatter_nd_ops_test.ScatterNdTest.testSmokeScatterNdBatch2DSliceDim3ShapeRank7 +scatter_nd_ops_test.ScatterNdTest.testString +scatter_nd_ops_test.ScatterNdTest.testUndefinedIndicesShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedOutputShape +scatter_nd_ops_test.ScatterNdTest.testUndefinedUpdatesShape +scatter_nd_ops_test.ScatterNdTest.test_session +scatter_nd_ops_test.StatefulScatterNdTest.testConcurrentUpdates +scatter_nd_ops_test.StatefulScatterNdTest.testExtraIndicesDimensions +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape1 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3InvalidShape2 +scatter_nd_ops_test.StatefulScatterNdTest.testRank3ValidShape +scatter_nd_ops_test.StatefulScatterNdTest.testResVarInvalidOutputShape +scatter_nd_ops_test.StatefulScatterNdTest.testScatterOutOfRangeCpu +#scatter_nd_ops_test.StatefulScatterNdTest.testScatterRepeatIndices +scatter_nd_ops_test.StatefulScatterNdTest.testSimple +scatter_nd_ops_test.StatefulScatterNdTest.testSimple2 +scatter_nd_ops_test.StatefulScatterNdTest.testSimple3 +scatter_nd_ops_test.StatefulScatterNdTest.testSimpleResource +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankAdd +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankSub +#scatter_nd_ops_test.StatefulScatterNdTest.testVariableRankUpdate +scatter_nd_ops_test.StatefulScatterNdTest.test_session + + slice_op_test.SliceTest.testComplex slice_op_test.SliceTest.testEmpty slice_op_test.SliceTest.testGradientsAll diff --git a/test/test_array_ops.cpp b/test/test_array_ops.cpp index 4e4638a05..c2c85353f 100644 --- a/test/test_array_ops.cpp +++ b/test/test_array_ops.cpp @@ -948,6 +948,94 @@ TEST(ArrayOps, Rank) { opexecuter.RunTest(); } // end of RankOp +// Test op: ScatterNd Op +TEST(ArrayOps, ScatterNd1D) { + Tensor indices(DT_INT32, TensorShape({4, 1})); + Tensor updates(DT_FLOAT, TensorShape({4})); + + AssignInputValues(indices, {{2}, {3}, {1}, {7}}); + AssignInputValues(updates, {9.1, 10.2, -11.3, 12.4}); + + vector static_input_indexes = {2}; + + vector output_datatypes = {DT_FLOAT}; + + Scope root = Scope::NewRootScope(); + auto R = ops::ScatterNd(root, indices, updates, {8}); + std::vector sess_run_fetchoutputs = {R}; + + OpExecuter opexecuter(root, "ScatterNd", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + + opexecuter.RunTest(); +} + +TEST(ArrayOps, ScatterNdRepeatIndices) { + Tensor indices(DT_INT32, TensorShape({4, 1})); + Tensor updates(DT_FLOAT, TensorShape({4})); + + // the index "2" appears twice + AssignInputValues(indices, {{2}, {3}, {2}, {7}}); + AssignInputValues(updates, {9.1, 10.2, -11.3, 12.4}); + + vector static_input_indexes = {2}; + + vector output_datatypes = {DT_FLOAT}; + + Scope root = Scope::NewRootScope(); + auto R = ops::ScatterNd(root, indices, updates, {10}); + std::vector sess_run_fetchoutputs = {R}; + + OpExecuter opexecuter(root, "ScatterNd", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + + opexecuter.RunTest(); +} + +TEST(ArrayOps, ScatterNdComplex) { + // indices.shape[-1] <= shape.rank + // updates.shape = indices.shape[:-1] + shape[indices.shape[-1]:] + // shape must be rank 1 + Tensor indices(DT_INT32, TensorShape({2, 2, 2})); + Tensor updates(DT_FLOAT, TensorShape({2, 2, 2})); + + AssignInputValuesRandom(indices, 0, 1); + AssignInputValuesRandom(updates, -10.0, 20.0f); + + vector static_input_indexes = {2}; + + vector output_datatypes = {DT_FLOAT}; + + Scope root = Scope::NewRootScope(); + auto R = ops::ScatterNd(root, indices, updates, {2, 2, 2}); + std::vector sess_run_fetchoutputs = {R}; + + OpExecuter opexecuter(root, "ScatterNd", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + opexecuter.RunTest(); +} + +TEST(ArrayOps, ScatterNd3D) { + Tensor indices(DT_INT32, TensorShape({2, 1})); + Tensor updates(DT_FLOAT, TensorShape({2, 4, 4})); + + AssignInputValues(indices, {{0}, {2}}); + AssignInputValuesRandom(updates, -10.0, 20.0f); + + vector static_input_indexes = {2}; + + vector output_datatypes = {DT_FLOAT}; + + Scope root = Scope::NewRootScope(); + auto R = ops::ScatterNd(root, indices, updates, {4, 4, 4}); + std::vector sess_run_fetchoutputs = {R}; + + OpExecuter opexecuter(root, "ScatterNd", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + + opexecuter.RunTest(); +} // end of test op ScatterNd + // Test op: Shape, outputs the shape of a tensor TEST(ArrayOps, Shape2D) { Scope root = Scope::NewRootScope(); diff --git a/test/test_image_ops.cpp b/test/test_image_ops.cpp new file mode 100644 index 000000000..ab652abd2 --- /dev/null +++ b/test/test_image_ops.cpp @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright 2017-2019 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ + +#include "test/opexecuter.h" + +using namespace std; +namespace ng = ngraph; + +namespace tensorflow { + +namespace ngraph_bridge { + +namespace testing { + +// Test op: CropAndResize +// Disabled till a backend starts supporting it +// Add more tests when backend starts supporting + +TEST(ImageOps, DISABLED_CropAndResize) { + Scope root = Scope::NewRootScope(); + + // TODO check if assigning random values is ok, + // or we should probably assign some known in-range values + // Fix and enable this test when a backend supports CropAndResize + + // [batch, height, width, channels] + Tensor image(DT_FLOAT, TensorShape({4, 64, 64, 3})); + AssignInputValuesRandom(image); + + int num_boxes = 5; + // [num_boxes, 4] + Tensor boxes(DT_FLOAT, TensorShape({num_boxes, 4})); + AssignInputValuesRandom(boxes); + + // [num_boxes] + Tensor box_ind(DT_INT32, TensorShape({num_boxes})); + AssignInputValuesRandom(box_ind); + + // [crop_height, crop_width] + Tensor crop_size(DT_INT32, TensorShape({6, 5})); + AssignInputValuesRandom(crop_size); + + // TODO check with non-zero extrapolation value and method="nearest" + auto attr = + ops::CropAndResize::Attrs().ExtrapolationValue(0.0).Method("bilinear"); + + vector static_input_indexes = {}; + auto R = ops::CropAndResize(root, image, boxes, box_ind, crop_size, attr); + vector output_datatypes = {DT_FLOAT}; + + std::vector sess_run_fetchoutputs = {R}; + OpExecuter opexecuter(root, "CropAndResize", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + + opexecuter.RunTest(); +} + +// Test op: ResizeBilinear +// Disabled till a backend starts supporting it +TEST(ImageOps, DISABLED_ResizeBilinear) { + for (auto align : {true, false}) { + Scope root = Scope::NewRootScope(); + // [batch, height, width, channels] + Tensor images(DT_FLOAT, TensorShape({4, 64, 64, 3})); + AssignInputValuesRandom(images); + + // Todo: test by changing align_corners + + // new_height, new_width + Tensor size(DT_INT32, TensorShape({2})); + vector new_dims = {93, 27}; + // TODO loop and do multiple sizes, larger + // and smaller than original + AssignInputValues(size, new_dims); + + auto attr = ops::ResizeBilinear::Attrs().AlignCorners(align); + + vector static_input_indexes = {}; + auto R = ops::ResizeBilinear(root, images, size, attr); + vector output_datatypes = {DT_FLOAT}; + + std::vector sess_run_fetchoutputs = {R}; + OpExecuter opexecuter(root, "ResizeBilinear", static_input_indexes, + output_datatypes, sess_run_fetchoutputs); + + opexecuter.RunTest(); + } +} +} +} +} diff --git a/test/test_math_ops.cpp b/test/test_math_ops.cpp index 5e1c686f1..036a3fcdb 100644 --- a/test/test_math_ops.cpp +++ b/test/test_math_ops.cpp @@ -335,6 +335,31 @@ TEST(MathOps, AllPositiveAxis) { opexecuter.RunTest(); } // end of test op All +// Test op: Cumsum +TEST(MathOps, Cumsum) { + Scope root = Scope::NewRootScope(); + int dim1 = 2; + int dim2 = 2; + + Tensor A(DT_FLOAT, TensorShape({dim1, dim2})); + Tensor B(DT_INT32, TensorShape({})); + + AssignInputValues(A, 2.1f); + AssignInputValues(B, 0); + + vector static_input_indexes = {}; + auto attrs = ops::Cumsum::Attrs(); + attrs.exclusive_ = true; + attrs.reverse_ = true; + auto R = ops::Cumsum(root, A, B, attrs); + + vector output_datatypes = {DT_FLOAT}; + std::vector sess_run_fetchoutputs = {R}; + OpExecuter opexecuter(root, "Cumsum", static_input_indexes, output_datatypes, + sess_run_fetchoutputs); + opexecuter.RunTest(); +} // end of test op Cumsum + // Test op: Sum with & without keep dims & with both positive & negative axis TEST(MathOps, Sum) { int dim1 = 2; @@ -526,6 +551,29 @@ TEST(MathOps, ArgMinPos) { opexecuter.RunTest(); } // end of test op ArgMin +// Test op: Atan2 +TEST(MathOps, Atan2) { + Scope root = Scope::NewRootScope(); + int dim1 = 2; + int dim2 = 5; + + Tensor A(DT_FLOAT, TensorShape({dim1, dim2})); + Tensor B(DT_FLOAT, TensorShape({dim1, dim2})); + + AssignInputValues(A, {0, -0, 3, -3.5, 1.2, 3, 5, -4.5, 1.0, -7.0}); + AssignInputValues(B, {0, -0, 3, 2.5, -0.7, 2, 3.4, -5.6, 30, 0.06}); + + vector static_input_indexes = {}; + auto R = ops::Atan2(root, A, B); + + vector output_datatypes = {DT_FLOAT}; + std::vector sess_run_fetchoutputs = {R}; + OpExecuter opexecuter(root, "Atan2", static_input_indexes, output_datatypes, + sess_run_fetchoutputs); + + opexecuter.RunTest(); +} // end of test op Atan2 + // Test op: BatchMatMul // BatchMatMul2D // AdjX = false