Implement ExperimentalDetectronTopKROIs and ExperimentalDetectronGenerateProposalsSingleImage operations as nGraph operations (#3680)
* Commit. * Written the header file for the nGraph operation ExperimentalDetectronTopKROIs. * Written an implementation file of the nGraph operation ExperimentalDetectronTopKROIs. * Small fix. * Added the nGraph operation ExperimentalDetectronTopKROIs into the table of ops of opset6. * Written the header file for the nGraph operation ExperimentalDetectronGenerateProposalsSingleImage. * Code style fix. * Written cpp-file of the nGraph operation ExperimentalDetectronGenerateProposalsSingleImage. * Now the operation ExperimentalDetectronGenerateProposalsSingleImage is read as nGraph operation. * Code style fix. * Fix in ngraph/ops.hpp * Added NGRAPH_OP_SCOPE to the nGraph class ExperimentalDetectronGenerateProposalsSingleImage. * Added NGRAPH_OP_SCOPE to the nGraph class ExperimentalDetectronTopKROIs. * Code style fix. * Small fix. * Added NGraphReshapeTests of ExperimentalDetectronGenerateProposalsSingleImage when ExperimentalDetectronGenerateProposalsSingleImage is considered as opset6 operation. * Changed copyright year to 2021. * Deleted the method ExperimentalDetectronTopKROIs::set_max_rois. * Deleted redundant virtual. * Now ExperimentalDetectronTopKROIs::validate_and_infer_types() handles all cases when input 0 and input 1 have static/dynamic rank independently. * Code style fix. * Small fix. * Started to write shape infer tests for the nGraph operation ExperimentalDetectronTopKROIs. * Written shape infer tests for the nGraph operation ExperimentalDetectronTopKROIs. * Code style fix. * Added checks of input shapes into ExperimentalDetectronGenerateProposalsSingleImage::validate_and_infer_types(). Started to write tests for ExperimentalDetectronGenerateProposalsSingleImage::validate_and_infer_types(). * Small fix. * Fixes in ExperimentalDetectronGenerateProposalsSingleImage::validate_and_infer_types(). Written draft tests for ExperimentalDetectronGenerateProposalsSingleImage::validate_and_infer_types(). * Code style fix. * Fixes in reshape tests for ExperimentalDetectronGenerateProposalsSingleImage. * Added Doxygen documentation to the nGraph operation class ExperimentalDetectronGenerateProposalsSingleImage. * Deleted methods validate_scores_shape and validate_deltas_shape of op::v6::ExperimentalDetectronGenerateProposalsSingleImage. * Deleted methods validate_input_rois_shape and validate_rois_probs_shape of op::v6::ExperimentalDetectronTopKROIs. * Added class descriftion for nGraph operations ExperimentalDetectronTopKROIs and ExperimentalDetectronGenerateProposalsSingleImage.
This commit is contained in:
parent
bacb8420f0
commit
31dec9addf
@ -7,12 +7,10 @@
|
||||
#include <string>
|
||||
|
||||
#include "shape_infer/ie_built_in_holder.hpp"
|
||||
#include "shape_infer/ie_proposal_onnx_shape_infer.hpp"
|
||||
#include "shape_infer/ie_proposal_shape_infer.hpp"
|
||||
#include "shape_infer/ie_rnn_cell_shape_infer.hpp"
|
||||
#include "shape_infer/ie_simpler_nms_shape_infer.hpp"
|
||||
#include "shape_infer/ie_sparse_to_dense_shape_infer.hpp"
|
||||
#include "shape_infer/ie_topkrois_onnx_shape_infer.hpp"
|
||||
#include "shape_infer/ie_unique_shape_infer.hpp"
|
||||
#include "shape_infer/ie_sparse_to_dense_shape_infer.hpp"
|
||||
|
||||
@ -65,8 +63,6 @@ public:
|
||||
#define REG_SHAPE_INFER_FOR_TYPE(__prim, __type) \
|
||||
static ImplRegisterBase<__prim> __bi_reg__##__type(#__type)
|
||||
|
||||
REG_SHAPE_INFER_FOR_TYPE(ExperimentalDetectronGenerateProposalsSingleImageShapeProp, ExperimentalDetectronGenerateProposalsSingleImage);
|
||||
REG_SHAPE_INFER_FOR_TYPE(ExperimentalDetectronTopKROIsShapeProp, ExperimentalDetectronTopKROIs);
|
||||
REG_SHAPE_INFER_FOR_TYPE(SimplerNMSShapeProp, SimplerNMS);
|
||||
REG_SHAPE_INFER_FOR_TYPE(SparseToDenseShapeProp, SparseToDense);
|
||||
REG_SHAPE_INFER_FOR_TYPE(ProposalShapeProp, Proposal);
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ie_built_in_impl.hpp"
|
||||
|
||||
namespace InferenceEngine {
|
||||
namespace ShapeInfer {
|
||||
|
||||
/**
|
||||
* @brief Implementation of Shape inference for ExperimentalDetectronGenerateProposalsSingleImage layer
|
||||
*/
|
||||
class ExperimentalDetectronGenerateProposalsSingleImageShapeProp : public BuiltInShapeInferImpl {
|
||||
public:
|
||||
explicit ExperimentalDetectronGenerateProposalsSingleImageShapeProp(const std::string& type): BuiltInShapeInferImpl(type) {}
|
||||
|
||||
void inferShapesImpl(const std::vector<Blob::CPtr>& inBlobs, const std::map<std::string, std::string>& params,
|
||||
const std::map<std::string, Blob::Ptr>& blobs, std::vector<SizeVector>& outShapes) override {
|
||||
auto post_nms_count = GetParamAsUInt("post_nms_count", params);
|
||||
outShapes.push_back({post_nms_count, 4});
|
||||
outShapes.push_back({post_nms_count, });
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ShapeInfer
|
||||
} // namespace InferenceEngine
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <description_buffer.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "shape_infer/ie_built_in_impl.hpp"
|
||||
|
||||
namespace InferenceEngine {
|
||||
namespace ShapeInfer {
|
||||
|
||||
/**
|
||||
* @brief Implementation of Shape inference for ExperimentalDetectronTopKROIs layer
|
||||
*/
|
||||
class ExperimentalDetectronTopKROIsShapeProp : public BuiltInShapeInferImpl {
|
||||
public:
|
||||
explicit ExperimentalDetectronTopKROIsShapeProp(const std::string& type): BuiltInShapeInferImpl(type) {}
|
||||
|
||||
void inferShapesImpl(const std::vector<Blob::CPtr>& inBlobs, const std::map<std::string, std::string>& params,
|
||||
const std::map<std::string, Blob::Ptr>& blobs, std::vector<SizeVector>& outShapes) override {
|
||||
const auto max_rois = GetParamAsUInt("max_rois", params);
|
||||
outShapes.push_back({max_rois, 4});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ShapeInfer
|
||||
} // namespace InferenceEngine
|
@ -680,8 +680,11 @@ std::shared_ptr<ngraph::Node> V10Parser::XmlDeserializer::createNode(
|
||||
// Try to create operation from loaded opsets
|
||||
auto version = params.version;
|
||||
static const std::unordered_set<std::string> experimental_detectrons = {"ExperimentalDetectronDetectionOutput",
|
||||
"ExperimentalDetectronGenerateProposalsSingleImage",
|
||||
"ExperimentalDetectronPriorGridGenerator",
|
||||
"ExperimentalDetectronROIFeatureExtractor"};
|
||||
"ExperimentalDetectronROIFeatureExtractor",
|
||||
"ExperimentalDetectronTopKROIs"};
|
||||
|
||||
if (experimental_detectrons.count(params.type)) {
|
||||
version = "opset6";
|
||||
}
|
||||
|
@ -753,7 +753,7 @@ TEST_F(NGraphReshapeTests, ReshapeEDGenerateProposalsSingleImage) {
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="in1" type="Parameter" id="1" version="opset1">
|
||||
<data shape="1201600000,4" element_type="f32"/>
|
||||
<data shape="201600,4" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>201600</dim>
|
||||
@ -772,7 +772,7 @@ TEST_F(NGraphReshapeTests, ReshapeEDGenerateProposalsSingleImage) {
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="in3" type="Parameter" id="3" version="opset1">
|
||||
<data shape="1,3" element_type="f32"/>
|
||||
<data shape="3,200,336" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>3</dim>
|
||||
@ -847,6 +847,113 @@ TEST_F(NGraphReshapeTests, ReshapeEDGenerateProposalsSingleImage) {
|
||||
ASSERT_NO_THROW(network.reshape(newShapes));
|
||||
}
|
||||
|
||||
TEST_F(NGraphReshapeTests, ReshapeEDGenerateProposalsSingleImage_opset6) {
|
||||
std::string model = R"V0G0N(
|
||||
<net name="GenerateProposalsSingleImage" version="10">
|
||||
<layers>
|
||||
<layer name="in0" type="Parameter" id="0" version="opset1">
|
||||
<data shape="3" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>3</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="in1" type="Parameter" id="1" version="opset1">
|
||||
<data shape="201600,4" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>201600</dim>
|
||||
<dim>4</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="in2" type="Parameter" id="2" version="opset1">
|
||||
<data shape="12,200,336" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>12</dim>
|
||||
<dim>200</dim>
|
||||
<dim>336</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="in3" type="Parameter" id="3" version="opset1">
|
||||
<data shape="3,200,336" element_type="f32"/>
|
||||
<output>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>3</dim>
|
||||
<dim>200</dim>
|
||||
<dim>336</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer id="4" name="1133" type="ExperimentalDetectronGenerateProposalsSingleImage" version="opset6">
|
||||
<data min_size="0.0" nms_threshold="0.699999988079071" post_nms_count="1000" pre_nms_count="1000"/>
|
||||
<input>
|
||||
<port id="0">
|
||||
<dim>3</dim>
|
||||
</port>
|
||||
<port id="1">
|
||||
<dim>201600</dim>
|
||||
<dim>4</dim>
|
||||
</port>
|
||||
<port id="2">
|
||||
<dim>12</dim>
|
||||
<dim>200</dim>
|
||||
<dim>336</dim>
|
||||
</port>
|
||||
<port id="3">
|
||||
<dim>3</dim>
|
||||
<dim>200</dim>
|
||||
<dim>336</dim>
|
||||
</port>
|
||||
</input>
|
||||
<output>
|
||||
<port id="4" precision="FP32">
|
||||
<dim>1000</dim>
|
||||
<dim>4</dim>
|
||||
</port>
|
||||
<port id="5" precision="FP32">
|
||||
<dim>1000</dim>
|
||||
</port>
|
||||
</output>
|
||||
</layer>
|
||||
<layer name="out_0" type="Result" id="5" version="opset1">
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1000</dim>
|
||||
<dim>4</dim>
|
||||
</port>
|
||||
</input>
|
||||
</layer>
|
||||
<layer name="out_1" type="Result" id="6" version="opset1">
|
||||
<input>
|
||||
<port id="0" precision="FP32">
|
||||
<dim>1000</dim>
|
||||
</port>
|
||||
</input>
|
||||
</layer>
|
||||
</layers>
|
||||
<edges>
|
||||
<edge from-layer="0" from-port="0" to-layer="4" to-port="0"/>
|
||||
<edge from-layer="1" from-port="0" to-layer="4" to-port="1"/>
|
||||
<edge from-layer="2" from-port="0" to-layer="4" to-port="2"/>
|
||||
<edge from-layer="3" from-port="0" to-layer="4" to-port="3"/>
|
||||
<edge from-layer="4" from-port="4" to-layer="5" to-port="0"/>
|
||||
<edge from-layer="4" from-port="5" to-layer="6" to-port="0"/>
|
||||
</edges>
|
||||
</net>
|
||||
)V0G0N";
|
||||
InferenceEngine::Core ie;
|
||||
Blob::Ptr weights;
|
||||
auto network = ie.ReadNetwork(model, weights);
|
||||
InferenceEngine::ICNNNetwork::InputShapes newShapes;
|
||||
newShapes["in2"] = {12, 200, 300};
|
||||
newShapes["in3"] = {2, 200, 300};
|
||||
ASSERT_NO_THROW(network.reshape(newShapes));
|
||||
}
|
||||
|
||||
TEST_F(NGraphReshapeTests, ReshapeEDROIFeatureExtractor) {
|
||||
std::string model = R"V0G0N(
|
||||
<net name="ExperimentalDetectronROIFeatureExtractor" version="10">
|
||||
|
@ -0,0 +1,79 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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.
|
||||
//*****************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "ngraph/attribute_adapter.hpp"
|
||||
#include "ngraph/op/op.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
|
||||
namespace ngraph
|
||||
{
|
||||
namespace op
|
||||
{
|
||||
namespace v6
|
||||
{
|
||||
/// \brief An operation ExperimentalDetectronGenerateProposalsSingleImage, according to
|
||||
/// the repository https://github.com/openvinotoolkit/training_extensions
|
||||
/// (see pytorch_toolkit/instance_segmentation/segmentoly/rcnn/proposal.py).
|
||||
class NGRAPH_API ExperimentalDetectronGenerateProposalsSingleImage : public Op
|
||||
{
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
|
||||
/// \brief Structure that specifies attributes of the operation
|
||||
struct Attributes
|
||||
{
|
||||
// minimum box width & height
|
||||
float min_size;
|
||||
// specifies NMS threshold
|
||||
float nms_threshold;
|
||||
// number of top-n proposals after NMS
|
||||
int64_t post_nms_count;
|
||||
// number of top-n proposals before NMS
|
||||
int64_t pre_nms_count;
|
||||
};
|
||||
|
||||
ExperimentalDetectronGenerateProposalsSingleImage() = default;
|
||||
/// \brief Constructs a ExperimentalDetectronGenerateProposalsSingleImage operation.
|
||||
///
|
||||
/// \param im_info Input image info
|
||||
/// \param anchors Input anchors
|
||||
/// \param deltas Input deltas
|
||||
/// \param scores Input scores
|
||||
/// \param attrs Operation attributes
|
||||
ExperimentalDetectronGenerateProposalsSingleImage(const Output<Node>& im_info,
|
||||
const Output<Node>& anchors,
|
||||
const Output<Node>& deltas,
|
||||
const Output<Node>& scores,
|
||||
const Attributes& attrs);
|
||||
|
||||
bool visit_attributes(AttributeVisitor& visitor) override;
|
||||
|
||||
void validate_and_infer_types() override;
|
||||
|
||||
std::shared_ptr<Node>
|
||||
clone_with_new_inputs(const OutputVector& new_args) const override;
|
||||
|
||||
const Attributes& get_attrs() const { return m_attrs; }
|
||||
private:
|
||||
Attributes m_attrs;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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.
|
||||
//*****************************************************************************
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include "ngraph/attribute_adapter.hpp"
|
||||
#include "ngraph/op/op.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
|
||||
namespace ngraph
|
||||
{
|
||||
namespace op
|
||||
{
|
||||
namespace v6
|
||||
{
|
||||
/// \brief An operation ExperimentalDetectronTopKROIs, according to the repository
|
||||
/// https://github.com/openvinotoolkit/training_extensions (see
|
||||
/// pytorch_toolkit/instance_segmentation/segmentoly/rcnn/roi_feature_extractor.py).
|
||||
class NGRAPH_API ExperimentalDetectronTopKROIs : public Op
|
||||
{
|
||||
public:
|
||||
NGRAPH_RTTI_DECLARATION;
|
||||
|
||||
ExperimentalDetectronTopKROIs() = default;
|
||||
/// \brief Constructs a ExperimentalDetectronTopKROIs operation.
|
||||
///
|
||||
/// \param input_rois Input rois
|
||||
/// \param rois_probs Probabilities for input rois
|
||||
/// \param max_rois Maximal numbers of output rois
|
||||
ExperimentalDetectronTopKROIs(const Output<Node>& input_rois,
|
||||
const Output<Node>& rois_probs,
|
||||
size_t max_rois = 0);
|
||||
|
||||
void validate_and_infer_types() override;
|
||||
bool visit_attributes(AttributeVisitor& visitor) override;
|
||||
|
||||
std::shared_ptr<Node>
|
||||
clone_with_new_inputs(const OutputVector& new_args) const override;
|
||||
|
||||
size_t get_max_rois() const { return m_max_rois; }
|
||||
private:
|
||||
size_t m_max_rois;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -60,8 +60,10 @@
|
||||
#include "ngraph/op/erf.hpp"
|
||||
#include "ngraph/op/exp.hpp"
|
||||
#include "ngraph/op/experimental_detectron_detection_output.hpp"
|
||||
#include "ngraph/op/experimental_detectron_generate_proposals.hpp"
|
||||
#include "ngraph/op/experimental_detectron_prior_grid_generator.hpp"
|
||||
#include "ngraph/op/experimental_detectron_roi_feature.hpp"
|
||||
#include "ngraph/op/experimental_detectron_topkrois.hpp"
|
||||
#include "ngraph/op/extractimagepatches.hpp"
|
||||
#include "ngraph/op/fake_quantize.hpp"
|
||||
#include "ngraph/op/floor.hpp"
|
||||
|
@ -175,7 +175,9 @@ NGRAPH_OP(Round, ngraph::op::v5)
|
||||
// New operations added in opset6
|
||||
NGRAPH_OP(CTCGreedyDecoderSeqLen, ngraph::op::v6)
|
||||
NGRAPH_OP(ExperimentalDetectronDetectionOutput, ngraph::op::v6)
|
||||
NGRAPH_OP(ExperimentalDetectronGenerateProposalsSingleImage, ngraph::op::v6)
|
||||
NGRAPH_OP(ExperimentalDetectronPriorGridGenerator, ngraph::op::v6)
|
||||
NGRAPH_OP(ExperimentalDetectronROIFeatureExtractor, ngraph::op::v6)
|
||||
NGRAPH_OP(ExperimentalDetectronTopKROIs, ngraph::op::v6)
|
||||
NGRAPH_OP(GatherElements, ngraph::op::v6)
|
||||
NGRAPH_OP(MVN, ngraph::op::v6)
|
||||
|
132
ngraph/core/src/op/experimental_detectron_generate_proposals.cpp
Normal file
132
ngraph/core/src/op/experimental_detectron_generate_proposals.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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 "ngraph/op/experimental_detectron_generate_proposals.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/attribute_visitor.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/validation_util.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(op::v6::ExperimentalDetectronGenerateProposalsSingleImage,
|
||||
"ExperimentalDetectronGenerateProposalsSingleImage",
|
||||
6);
|
||||
|
||||
op::v6::ExperimentalDetectronGenerateProposalsSingleImage::
|
||||
ExperimentalDetectronGenerateProposalsSingleImage(const Output<Node>& im_info,
|
||||
const Output<Node>& anchors,
|
||||
const Output<Node>& deltas,
|
||||
const Output<Node>& scores,
|
||||
const Attributes& attrs)
|
||||
: Op({im_info, anchors, deltas, scores})
|
||||
, m_attrs(attrs)
|
||||
{
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
shared_ptr<Node> op::v6::ExperimentalDetectronGenerateProposalsSingleImage::clone_with_new_inputs(
|
||||
const OutputVector& new_args) const
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronGenerateProposalsSingleImage_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return make_shared<op::v6::ExperimentalDetectronGenerateProposalsSingleImage>(
|
||||
new_args.at(0), new_args.at(1), new_args.at(2), new_args.at(3), m_attrs);
|
||||
}
|
||||
|
||||
bool op::v6::ExperimentalDetectronGenerateProposalsSingleImage::visit_attributes(
|
||||
AttributeVisitor& visitor)
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronGenerateProposalsSingleImage_visit_attributes);
|
||||
visitor.on_attribute("min_size", m_attrs.min_size);
|
||||
visitor.on_attribute("nms_threshold", m_attrs.nms_threshold);
|
||||
visitor.on_attribute("post_nms_count", m_attrs.post_nms_count);
|
||||
visitor.on_attribute("pre_nms_count", m_attrs.pre_nms_count);
|
||||
return true;
|
||||
}
|
||||
|
||||
void op::v6::ExperimentalDetectronGenerateProposalsSingleImage::validate_and_infer_types()
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronGenerateProposalsSingleImage_validate_and_infer_types);
|
||||
size_t post_nms_count = static_cast<size_t>(m_attrs.post_nms_count);
|
||||
auto input_et = get_input_element_type(0);
|
||||
|
||||
set_output_type(0, input_et, Shape{post_nms_count, 4});
|
||||
set_output_type(1, input_et, Shape{post_nms_count});
|
||||
|
||||
auto im_info_shape = get_input_partial_shape(0);
|
||||
auto anchors_shape = get_input_partial_shape(1);
|
||||
auto deltas_shape = get_input_partial_shape(2);
|
||||
auto scores_shape = get_input_partial_shape(3);
|
||||
|
||||
if (im_info_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
im_info_shape.rank().get_length() == 1,
|
||||
"The 'input_im_info' input is expected to be a 1D. Got: ",
|
||||
im_info_shape);
|
||||
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
im_info_shape[0] == 3,
|
||||
"The 'input_im_info' shape is expected to be a [3]. Got: ",
|
||||
im_info_shape);
|
||||
}
|
||||
|
||||
if (anchors_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
anchors_shape.rank().get_length() == 2,
|
||||
"The 'input_anchors' input is expected to be a 2D. Got: ",
|
||||
anchors_shape);
|
||||
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
anchors_shape[1] == 4,
|
||||
"The second dimension of 'input_anchors' should be 4. Got: ",
|
||||
anchors_shape[1]);
|
||||
}
|
||||
|
||||
if (deltas_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
deltas_shape.rank().get_length() == 3,
|
||||
"The 'input_deltas' input is expected to be a 3D. Got: ",
|
||||
deltas_shape);
|
||||
}
|
||||
if (scores_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
scores_shape.rank().get_length() == 3,
|
||||
"The 'input_scores' input is expected to be a 3D. Got: ",
|
||||
scores_shape);
|
||||
}
|
||||
if (deltas_shape.rank().is_static() && scores_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
deltas_shape[1] == scores_shape[1],
|
||||
"Heights for inputs 'input_deltas' and 'input_scores' should be "
|
||||
"equal. Got: ",
|
||||
deltas_shape[1],
|
||||
scores_shape[1]);
|
||||
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
deltas_shape[2] == scores_shape[2],
|
||||
"Width for inputs 'input_deltas' and 'input_scores' should be "
|
||||
"equal. Got: ",
|
||||
deltas_shape[2],
|
||||
scores_shape[2]);
|
||||
}
|
||||
}
|
88
ngraph/core/src/op/experimental_detectron_topkrois.cpp
Normal file
88
ngraph/core/src/op/experimental_detectron_topkrois.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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 "ngraph/op/experimental_detectron_topkrois.hpp"
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/attribute_visitor.hpp"
|
||||
#include "ngraph/op/util/op_types.hpp"
|
||||
#include "ngraph/validation_util.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
NGRAPH_RTTI_DEFINITION(op::v6::ExperimentalDetectronTopKROIs, "ExperimentalDetectronTopKROIs", 6);
|
||||
|
||||
op::v6::ExperimentalDetectronTopKROIs::ExperimentalDetectronTopKROIs(const Output<Node>& input_rois,
|
||||
const Output<Node>& rois_probs,
|
||||
size_t max_rois)
|
||||
: Op({input_rois, rois_probs})
|
||||
, m_max_rois(max_rois)
|
||||
{
|
||||
constructor_validate_and_infer_types();
|
||||
}
|
||||
|
||||
bool op::v6::ExperimentalDetectronTopKROIs::visit_attributes(AttributeVisitor& visitor)
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronTopKROIs_visit_attributes);
|
||||
visitor.on_attribute("max_rois", m_max_rois);
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_ptr<Node>
|
||||
op::v6::ExperimentalDetectronTopKROIs::clone_with_new_inputs(const OutputVector& new_args) const
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronTopKROIs_clone_with_new_inputs);
|
||||
check_new_args_count(this, new_args);
|
||||
return make_shared<op::v6::ExperimentalDetectronTopKROIs>(
|
||||
new_args.at(0), new_args.at(1), m_max_rois);
|
||||
}
|
||||
|
||||
void op::v6::ExperimentalDetectronTopKROIs::validate_and_infer_types()
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v6_ExperimentalDetectronTopKROIs_validate_and_infer_types);
|
||||
const auto input_rois_shape = get_input_partial_shape(0);
|
||||
const auto rois_probs_shape = get_input_partial_shape(1);
|
||||
|
||||
set_output_type(0, get_input_element_type(0), Shape{m_max_rois, 4});
|
||||
|
||||
if (input_rois_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
input_rois_shape.rank().get_length() == 2,
|
||||
"The 'input_rois' input is expected to be a 2D. Got: ",
|
||||
input_rois_shape);
|
||||
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
input_rois_shape[1] == 4,
|
||||
"The second dimension of 'input_rois' should be 4. Got: ",
|
||||
input_rois_shape[1]);
|
||||
}
|
||||
if (rois_probs_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
rois_probs_shape.rank().get_length() == 1,
|
||||
"The 'rois_probs' input is expected to be a 1D. Got: ",
|
||||
rois_probs_shape);
|
||||
}
|
||||
if (input_rois_shape.rank().is_static() && rois_probs_shape.rank().is_static())
|
||||
{
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
input_rois_shape[0] == rois_probs_shape[0],
|
||||
"Number of rois and number of probabilities should be equal. Got: ",
|
||||
input_rois_shape[0],
|
||||
rois_probs_shape[0]);
|
||||
}
|
||||
}
|
@ -126,7 +126,9 @@ set(SRC
|
||||
type_prop/detection_output.cpp
|
||||
type_prop/depth_to_space.cpp
|
||||
type_prop/dyn_reshape.cpp
|
||||
type_prop/experimental_detectron_generate_proposals.cpp
|
||||
type_prop/experimental_detectron_roi_feature_extractor.cpp
|
||||
type_prop/experimental_detectron_topkrois.cpp
|
||||
type_prop/strided_slice.cpp
|
||||
type_prop/elu.cpp
|
||||
type_prop/embeddingbag_offsetssum.cpp
|
||||
|
@ -0,0 +1,116 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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 <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
|
||||
using ExperimentalProposals = op::v6::ExperimentalDetectronGenerateProposalsSingleImage;
|
||||
using Attrs = op::v6::ExperimentalDetectronGenerateProposalsSingleImage::Attributes;
|
||||
|
||||
TEST(type_prop, detectron_proposals)
|
||||
{
|
||||
Attrs attrs;
|
||||
attrs.min_size = 0.0f;
|
||||
attrs.nms_threshold = 0.699999988079071f;
|
||||
attrs.post_nms_count = 1000;
|
||||
attrs.pre_nms_count = 1000;
|
||||
|
||||
size_t post_nms_count = 1000;
|
||||
|
||||
auto im_info = std::make_shared<op::Parameter>(element::f32, Shape{3});
|
||||
auto anchors = std::make_shared<op::Parameter>(element::f32, Shape{201600, 4});
|
||||
auto deltas = std::make_shared<op::Parameter>(element::f32, Shape{12, 200, 336});
|
||||
auto scores = std::make_shared<op::Parameter>(element::f32, Shape{3, 200, 336});
|
||||
|
||||
auto proposals =
|
||||
std::make_shared<ExperimentalProposals>(im_info, anchors, deltas, scores, attrs);
|
||||
|
||||
ASSERT_EQ(proposals->get_output_element_type(0), element::f32);
|
||||
ASSERT_EQ(proposals->get_output_element_type(1), element::f32);
|
||||
EXPECT_EQ(proposals->get_output_shape(0), (Shape{post_nms_count, 4}));
|
||||
EXPECT_EQ(proposals->get_output_shape(1), (Shape{post_nms_count}));
|
||||
}
|
||||
|
||||
TEST(type_prop, detectron_proposals_dynamic)
|
||||
{
|
||||
struct ShapesAndAttrs
|
||||
{
|
||||
PartialShape im_info_shape;
|
||||
PartialShape anchors_shape;
|
||||
PartialShape deltas_shape;
|
||||
PartialShape scores_shape;
|
||||
size_t post_nms_count;
|
||||
};
|
||||
|
||||
const auto dyn_dim = Dimension::dynamic();
|
||||
const auto dyn_shape = PartialShape::dynamic();
|
||||
|
||||
std::vector<ShapesAndAttrs> shapes = {
|
||||
{{3}, {201600, 4}, {12, 200, 336}, {3, 200, 336}, 1000},
|
||||
{{3}, {201600, 4}, {12, 200, 336}, dyn_shape, 500},
|
||||
{{3}, {201600, 4}, dyn_shape, {3, 200, 336}, 700},
|
||||
{{3}, {201600, 4}, dyn_shape, dyn_shape, 300},
|
||||
{{3}, dyn_shape, {12, 200, 336}, {3, 200, 336}, 200},
|
||||
{{3}, dyn_shape, {12, 200, 336}, dyn_shape, 40},
|
||||
{{3}, dyn_shape, dyn_shape, {3, 200, 336}, 70},
|
||||
{{3}, dyn_shape, dyn_shape, dyn_shape, 60},
|
||||
{dyn_shape, {201600, 4}, {12, 200, 336}, {3, 200, 336}, 500},
|
||||
{dyn_shape, {201600, 4}, {12, 200, 336}, dyn_shape, 400},
|
||||
{dyn_shape, {201600, 4}, dyn_shape, {3, 200, 336}, 350},
|
||||
{dyn_shape, {201600, 4}, dyn_shape, dyn_shape, 440},
|
||||
{dyn_shape, dyn_shape, {12, 200, 336}, {3, 200, 336}, 315},
|
||||
{dyn_shape, dyn_shape, {12, 200, 336}, dyn_shape, 130},
|
||||
{dyn_shape, dyn_shape, dyn_shape, {3, 200, 336}, 1000},
|
||||
{dyn_shape, dyn_shape, dyn_shape, dyn_shape, 700},
|
||||
{{3}, {dyn_dim, 4}, {12, 200, 336}, {3, 200, 336}, 540},
|
||||
{{3}, {dyn_dim, 4}, {12, 200, 336}, {dyn_dim, 200, 336}, 600},
|
||||
{{3}, {dyn_dim, 4}, {dyn_dim, 200, 336}, {3, 200, 336}, 75},
|
||||
{{3}, {dyn_dim, 4}, {dyn_dim, 200, 336}, {dyn_dim, 200, 336}, 80},
|
||||
{{3}, {201600, 4}, {12, 200, dyn_dim}, {3, 200, dyn_dim}, 430},
|
||||
{{3}, {201600, 4}, {12, dyn_dim, 336}, {3, dyn_dim, 336}, 180},
|
||||
{{3}, {201600, 4}, {12, dyn_dim, dyn_dim}, {3, dyn_dim, dyn_dim}, 170},
|
||||
{{3}, {dyn_dim, 4}, {12, 200, dyn_dim}, {3, 200, dyn_dim}, 200},
|
||||
{{3}, {dyn_dim, 4}, {12, dyn_dim, 336}, {3, dyn_dim, 336}, 800},
|
||||
{{3}, {dyn_dim, 4}, {12, dyn_dim, dyn_dim}, {3, dyn_dim, dyn_dim}, 560},
|
||||
};
|
||||
|
||||
for (const auto& s : shapes)
|
||||
{
|
||||
Attrs attrs;
|
||||
attrs.min_size = 0.0f;
|
||||
attrs.nms_threshold = 0.699999988079071f;
|
||||
attrs.post_nms_count = static_cast<int64_t>(s.post_nms_count);
|
||||
attrs.pre_nms_count = 1000;
|
||||
|
||||
auto im_info = std::make_shared<op::Parameter>(element::f32, s.im_info_shape);
|
||||
auto anchors = std::make_shared<op::Parameter>(element::f32, s.anchors_shape);
|
||||
auto deltas = std::make_shared<op::Parameter>(element::f32, s.deltas_shape);
|
||||
auto scores = std::make_shared<op::Parameter>(element::f32, s.scores_shape);
|
||||
|
||||
auto proposals =
|
||||
std::make_shared<ExperimentalProposals>(im_info, anchors, deltas, scores, attrs);
|
||||
|
||||
ASSERT_EQ(proposals->get_output_element_type(0), element::f32);
|
||||
ASSERT_EQ(proposals->get_output_element_type(1), element::f32);
|
||||
EXPECT_EQ(proposals->get_output_shape(0), (Shape{s.post_nms_count, 4}));
|
||||
EXPECT_EQ(proposals->get_output_shape(1), (Shape{s.post_nms_count}));
|
||||
}
|
||||
}
|
68
ngraph/test/type_prop/experimental_detectron_topkrois.cpp
Normal file
68
ngraph/test/type_prop/experimental_detectron_topkrois.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
//*****************************************************************************
|
||||
// Copyright 2017-2021 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 <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
|
||||
using ExperimentalTopKROIs = op::v6::ExperimentalDetectronTopKROIs;
|
||||
|
||||
TEST(type_prop, detectron_topk_rois)
|
||||
{
|
||||
auto input_rois = std::make_shared<op::Parameter>(element::f32, Shape{5000, 4});
|
||||
auto rois_probs = std::make_shared<op::Parameter>(element::f32, Shape{5000});
|
||||
size_t max_rois = 1000;
|
||||
auto topk_rois = std::make_shared<ExperimentalTopKROIs>(input_rois, rois_probs, max_rois);
|
||||
|
||||
ASSERT_EQ(topk_rois->get_output_element_type(0), element::f32);
|
||||
EXPECT_EQ(topk_rois->get_output_shape(0), (Shape{max_rois, 4}));
|
||||
}
|
||||
|
||||
TEST(type_prop, detectron_topk_rois_dynamic)
|
||||
{
|
||||
struct ShapesAndMaxROIs
|
||||
{
|
||||
PartialShape input_rois_shape;
|
||||
PartialShape rois_probs_shape;
|
||||
size_t max_rois;
|
||||
};
|
||||
|
||||
const auto dyn_dim = Dimension::dynamic();
|
||||
const auto dyn_shape = PartialShape::dynamic();
|
||||
|
||||
std::vector<ShapesAndMaxROIs> shapes_and_attrs = {{{3000, 4}, dyn_shape, 700},
|
||||
{dyn_shape, {4000}, 600},
|
||||
{dyn_shape, dyn_shape, 500},
|
||||
{{dyn_dim, 4}, dyn_shape, 700},
|
||||
{dyn_shape, {dyn_dim}, 600},
|
||||
{dyn_shape, dyn_shape, 500},
|
||||
{{dyn_dim, 4}, {dyn_dim}, 700}};
|
||||
|
||||
for (const auto& s : shapes_and_attrs)
|
||||
{
|
||||
auto input_rois = std::make_shared<op::Parameter>(element::f32, s.input_rois_shape);
|
||||
auto rois_probs = std::make_shared<op::Parameter>(element::f32, s.rois_probs_shape);
|
||||
size_t max_rois = s.max_rois;
|
||||
auto topk_rois = std::make_shared<ExperimentalTopKROIs>(input_rois, rois_probs, max_rois);
|
||||
|
||||
ASSERT_EQ(topk_rois->get_output_element_type(0), element::f32);
|
||||
EXPECT_EQ(topk_rois->get_output_shape(0), (Shape{max_rois, 4}));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user