Reference Implementation for RegionYolo operator (#2474)

This commit is contained in:
Gabriele Galiero Casay
2020-10-15 22:30:12 +02:00
committed by GitHub
parent db85069713
commit c9b16a79f5
16 changed files with 475 additions and 4 deletions

View File

@@ -325,6 +325,7 @@ set(MULTI_TEST_SRC
backend/reduce_min.in.cpp
backend/reduce_prod.in.cpp
backend/reduce_sum.in.cpp
backend/region_yolo.in.cpp
backend/relu.in.cpp
backend/reorg_yolo.in.cpp
backend/replace_slice.in.cpp

View File

@@ -787,7 +787,7 @@ TEST(attributes, reduce_sum_op)
TEST(attributes, region_yolo_op)
{
FactoryRegistry<Node>::get().register_factory<opset1::RegionYolo>();
auto data = make_shared<op::Parameter>(element::i64, Shape{1, 255, 26, 26});
auto data = make_shared<op::Parameter>(element::f32, Shape{1, 255, 26, 26});
size_t num_coords = 4;
size_t num_classes = 1;

View File

@@ -0,0 +1,86 @@
//*****************************************************************************
// Copyright 2017-2020 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 <fstream>
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, region_yolo_v2_caffe)
{
const size_t num = 5;
const size_t coords = 4;
const size_t classes = 20;
const size_t batch = 1;
const size_t channels = 125;
const size_t width = 13;
const size_t height = 13;
const size_t count = width * height * channels;
const std::vector<int64_t> mask{0, 1, 2};
Shape input_shape{batch, channels, height, width};
Shape output_shape{batch, channels * height * width};
auto A = make_shared<op::Parameter>(element::f32, input_shape);
auto R = make_shared<op::v0::RegionYolo>(A, coords, classes, num, true, mask, 1, 3);
auto f = make_shared<Function>(R, ParameterVector{A});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input_from_file<float>(input_shape, TEST_FILES, "region_in_yolov2_caffe.data");
test_case.add_expected_output_from_file<float>(
output_shape, TEST_FILES, "region_out_yolov2_caffe.data");
test_case.run_with_tolerance_as_fp(1.0e-4f);
}
NGRAPH_TEST(${BACKEND_NAME}, region_yolo_v3_mxnet)
{
const size_t num = 9;
const size_t coords = 4;
const size_t classes = 20;
const size_t batch = 1;
const size_t channels = 75;
const size_t width = 32;
const size_t height = 32;
const std::vector<int64_t> mask{0, 1, 2};
Shape shape{batch, channels, height, width};
const auto count = shape_size(shape);
const auto A = make_shared<op::Parameter>(element::f32, shape);
const auto R = make_shared<op::v0::RegionYolo>(A, coords, classes, num, false, mask, 1, 3);
const auto f = make_shared<Function>(R, ParameterVector{A});
EXPECT_EQ(R->get_output_shape(0), shape);
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input_from_file<float>(shape, TEST_FILES, "region_in_yolov3_mxnet.data");
test_case.add_expected_output_from_file<float>(
shape, TEST_FILES, "region_out_yolov3_mxnet.data");
test_case.run_with_tolerance_as_fp(1.0e-4f);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1466,6 +1466,8 @@ IE_GPU.matmul_2x2_2x2
IE_GPU.matmul_2x3_3x3
IE_GPU.matmul_3x2_3x3_transpose
IE_GPU.matmul_3x2_2x3_transpose
IE_GPU.region_yolo_v2_caffe
IE_GPU.region_yolo_v3_mxnet
# Unsupported collapse op with dynamic shape
IE_GPU.builder_opset1_collapse_dyn_shape

View File

@@ -77,6 +77,7 @@
#include "ngraph/runtime/reference/prior_box.hpp"
#include "ngraph/runtime/reference/product.hpp"
#include "ngraph/runtime/reference/quantize.hpp"
#include "ngraph/runtime/reference/region_yolo.hpp"
#include "ngraph/runtime/reference/relu.hpp"
#include "ngraph/runtime/reference/reorg_yolo.hpp"
#include "ngraph/runtime/reference/replace_slice.hpp"
@@ -1187,6 +1188,19 @@ protected:
break;
}
case OP_TYPEID::RegionYolo_v0:
{
const op::RegionYolo* region_yolo = static_cast<const op::RegionYolo*>(&node);
reference::region_yolo<T>(args[0]->get_data_ptr<const T>(),
out[0]->get_data_ptr<T>(),
args[0]->get_shape(),
region_yolo->get_num_coords(),
region_yolo->get_num_classes(),
region_yolo->get_num_regions(),
region_yolo->get_do_softmax(),
region_yolo->get_mask());
break;
}
case OP_TYPEID::Relu:
{
size_t element_count = shape_size(node.get_output_shape(0));

View File

@@ -21,6 +21,7 @@
#define ID_SUFFIX(NAME) NAME##_v0
NGRAPH_OP(CTCGreedyDecoder, ngraph::op::v0)
NGRAPH_OP(DetectionOutput, op::v0)
NGRAPH_OP(RegionYolo, op::v0)
NGRAPH_OP(ReorgYolo, op::v0)
NGRAPH_OP(RNNCell, op::v0)
#undef ID_SUFFIX