Migrate Sequence (CTCGreedyDecoder-1, CTCGreedyDecoderSeqLen-6, GRUCell-3, LSTMCell-4, OneHot-1, RNNCell-1) and Sort (ExperimentalDetectronTopKROIs-6) (#8314)
This commit is contained in:
parent
4edb7c6f34
commit
90094e8a8a
@ -0,0 +1,132 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/ctc_greedy_decoder.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct CTCGreedyDecoderParams {
|
||||
CTCGreedyDecoderParams(
|
||||
const Tensor& dataTensor, const Tensor& masksTensor, int64_t ctcMergedRepeat,
|
||||
const Tensor& expectedTensor, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), masksTensor(masksTensor), ctcMergedRepeat(ctcMergedRepeat),
|
||||
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
Tensor masksTensor;
|
||||
bool ctcMergedRepeat;
|
||||
Tensor expectedTensor;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceCTCGreedyDecoderTest : public testing::TestWithParam<CTCGreedyDecoderParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.dataTensor.data, params.masksTensor.data};
|
||||
refOutData = {params.expectedTensor.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<CTCGreedyDecoderParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_aType=" << param.masksTensor.type;
|
||||
result << "_aShape=" << param.masksTensor.shape;
|
||||
result << "_bDims=" << param.ctcMergedRepeat;
|
||||
result << "_eType=" << param.expectedTensor.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const CTCGreedyDecoderParams& params) {
|
||||
std::shared_ptr<Function> function;
|
||||
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto indices = std::make_shared<op::v0::Parameter>(params.masksTensor.type, params.masksTensor.shape);
|
||||
const auto decoder = std::make_shared<op::v0::CTCGreedyDecoder>(data, indices, params.ctcMergedRepeat);
|
||||
function = std::make_shared<ov::Function>(NodeVector{decoder}, ParameterVector{data, indices});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceCTCGreedyDecoderTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IN_ET>
|
||||
std::vector<CTCGreedyDecoderParams> generateParams() {
|
||||
using T = typename element_type_traits<IN_ET>::value_type;
|
||||
std::vector<CTCGreedyDecoderParams> params {
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {3, 1, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f}),
|
||||
Tensor(IN_ET, {3, 1}, std::vector<T>{1.0f, 1.0f, 1.0f}),
|
||||
false,
|
||||
Tensor(IN_ET, {1, 3, 1, 1}, std::vector<T>{1.0f, 0.0f, 1.0f}),
|
||||
"ctc_greedy_decoder"),
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {3, 2, 3}, std::vector<T>{
|
||||
0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f, 0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f}),
|
||||
Tensor(IN_ET, {3, 2}, std::vector<T>{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}),
|
||||
false,
|
||||
Tensor(IN_ET, {2, 3, 1, 1}, std::vector<T>{1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}),
|
||||
"ctc_greedy_decoder_multiple_batches"),
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {3, 1, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f}),
|
||||
Tensor(IN_ET, {3, 1}, std::vector<T>{1.0f, 1.0f, 0.0f}),
|
||||
false,
|
||||
Tensor(IN_ET, {1, 3, 1, 1}, std::vector<T>{1.0f, 0.0f, -1.0f}),
|
||||
"ctc_greedy_decoder_single_batch_short_sequence"),
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {3, 1, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.3f, 0.4f, 0.f, 0.6f, 0.5f, 0.f}),
|
||||
Tensor(IN_ET, {3, 1}, std::vector<T>{1.0f, 1.0f, 1.0f}),
|
||||
true,
|
||||
Tensor(IN_ET, {1, 3, 1, 1}, std::vector<T>{1.0f, 0.0f, -1.0f}),
|
||||
"ctc_greedy_decoder_merge"),
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {3, 1, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.3f, 0.4f, 0.f, 0.6f, 0.5f, 0.f}),
|
||||
Tensor(IN_ET, {3, 1}, std::vector<T>{1.0f, 1.0f, 1.0f}),
|
||||
false,
|
||||
Tensor(IN_ET, {1, 3, 1, 1}, std::vector<T>{1.0f, 1.0f, 0.0f}),
|
||||
"ctc_greedy_decoder_single_no_merge"),
|
||||
CTCGreedyDecoderParams(
|
||||
Tensor(IN_ET, {2, 2, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f, 0.7f, 0.8f, 0.f}),
|
||||
Tensor(IN_ET, {2, 2}, std::vector<T>{1.0f, 1.0f, 1.0f, 0.0f}),
|
||||
false,
|
||||
Tensor(IN_ET, {2, 2, 1, 1}, std::vector<T>{1.0f, 1.0f, 0.0f, -1.0f}),
|
||||
"ctc_greedy_decoder_multiple_sequences"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<CTCGreedyDecoderParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<CTCGreedyDecoderParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<CTCGreedyDecoderParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_CTCGreedyDecoder_With_Hardcoded_Refs, ReferenceCTCGreedyDecoderTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceCTCGreedyDecoderTest::getTestCaseName);
|
||||
} // namespace
|
@ -0,0 +1,228 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/ctc_greedy_decoder_seq_len.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct CTCGreedyDecoderSeqLenParams {
|
||||
CTCGreedyDecoderSeqLenParams(
|
||||
const Tensor& dataTensor, const Tensor& seqLenTensor, const Tensor& blankIndexTensor, int64_t mergeRepeated,
|
||||
const Tensor& expectedTensor, const Tensor& expectedTensor2, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), seqLenTensor(seqLenTensor), blankIndexTensor(blankIndexTensor), mergeRepeated(mergeRepeated),
|
||||
expectedTensor(expectedTensor), expectedTensor2(expectedTensor2), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
Tensor seqLenTensor;
|
||||
Tensor blankIndexTensor;
|
||||
bool mergeRepeated;
|
||||
Tensor expectedTensor;
|
||||
Tensor expectedTensor2;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
struct CTCGreedyDecoderSeqLenParamsNoOptionalInput {
|
||||
CTCGreedyDecoderSeqLenParamsNoOptionalInput(
|
||||
const Tensor& dataTensor, const Tensor& seqLenTensor, int64_t mergeRepeated,
|
||||
const Tensor& expectedTensor, const Tensor& expectedTensor2, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), seqLenTensor(seqLenTensor), mergeRepeated(mergeRepeated),
|
||||
expectedTensor(expectedTensor), expectedTensor2(expectedTensor2), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
Tensor seqLenTensor;
|
||||
bool mergeRepeated;
|
||||
Tensor expectedTensor;
|
||||
Tensor expectedTensor2;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceCTCGreedyDecoderSeqLenTest : public testing::TestWithParam<CTCGreedyDecoderSeqLenParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.dataTensor.data, params.seqLenTensor.data};
|
||||
refOutData = {params.expectedTensor.data, params.expectedTensor2.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<CTCGreedyDecoderSeqLenParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_sType=" << param.seqLenTensor.type;
|
||||
result << "_sShape=" << param.seqLenTensor.shape;
|
||||
result << "_bType=" << param.blankIndexTensor.type;
|
||||
result << "_bShape=" << param.blankIndexTensor.shape;
|
||||
result << "_mRepeated=" << param.mergeRepeated;
|
||||
result << "_eType=" << param.expectedTensor.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const CTCGreedyDecoderSeqLenParams& params) {
|
||||
std::shared_ptr<Function> function;
|
||||
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto seq_len = std::make_shared<op::v0::Parameter>(params.seqLenTensor.type, params.seqLenTensor.shape);
|
||||
auto blank_index = std::make_shared<op::v0::Constant>(params.blankIndexTensor.type, params.blankIndexTensor.shape,
|
||||
params.blankIndexTensor.data.data());
|
||||
const auto decoder = std::make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, params.mergeRepeated);
|
||||
function = std::make_shared<ov::Function>(decoder->outputs(), ParameterVector{data, seq_len});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceCTCGreedyDecoderSeqLenTestNoOptionalInput :
|
||||
public testing::TestWithParam<CTCGreedyDecoderSeqLenParamsNoOptionalInput>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.dataTensor.data, params.seqLenTensor.data};
|
||||
refOutData = {params.expectedTensor.data, params.expectedTensor2.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<CTCGreedyDecoderSeqLenParamsNoOptionalInput>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_sType=" << param.seqLenTensor.type;
|
||||
result << "_sShape=" << param.seqLenTensor.shape;
|
||||
result << "_mRepeated=" << param.mergeRepeated;
|
||||
result << "_eType=" << param.expectedTensor.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const CTCGreedyDecoderSeqLenParamsNoOptionalInput& params) {
|
||||
std::shared_ptr<Function> function;
|
||||
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto seq_len = std::make_shared<op::v0::Parameter>(params.seqLenTensor.type, params.seqLenTensor.shape);
|
||||
const auto decoder = std::make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, params.mergeRepeated);
|
||||
function = std::make_shared<ov::Function>(decoder->outputs(), ParameterVector{data, seq_len});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceCTCGreedyDecoderSeqLenTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceCTCGreedyDecoderSeqLenTestNoOptionalInput, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<CTCGreedyDecoderSeqLenParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<CTCGreedyDecoderSeqLenParams> params {
|
||||
CTCGreedyDecoderSeqLenParams(
|
||||
Tensor(ET, {1, 3, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
Tensor(element::i32, {}, std::vector<int32_t>{2}),
|
||||
false,
|
||||
Tensor(element::i32, {1, 3}, std::vector<int32_t>{1, 0, -1}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
"evaluate_ctc_greedy_decoder_seq_len"),
|
||||
CTCGreedyDecoderSeqLenParams(
|
||||
Tensor(ET, {1, 3, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
Tensor(element::i32, {}, std::vector<int32_t>{2}),
|
||||
true,
|
||||
Tensor(element::i32, {1, 3}, std::vector<int32_t>{1, 0, -1}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
"evaluate_ctc_greedy_decoder_seq_len_merge"),
|
||||
CTCGreedyDecoderSeqLenParams(
|
||||
Tensor(ET, {2, 3, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f,
|
||||
0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f}),
|
||||
Tensor(element::i32, {2}, std::vector<int32_t>{1, 1}),
|
||||
Tensor(element::i32, {}, std::vector<int32_t>{2}),
|
||||
false,
|
||||
Tensor(element::i32, {2, 3}, std::vector<int32_t>{1, -1, -1, 0, -1, -1}),
|
||||
Tensor(element::i32, {2}, std::vector<int32_t>{1, 1}),
|
||||
"evaluate_ctc_greedy_decoder_seq_len_multiple_batches"),
|
||||
CTCGreedyDecoderSeqLenParams(
|
||||
Tensor(ET, {3, 3, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f,
|
||||
0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f,
|
||||
0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f}),
|
||||
Tensor(element::i32, {3}, std::vector<int32_t>{2, 3, 1}),
|
||||
Tensor(element::i32, {}, std::vector<int32_t>{2}),
|
||||
false,
|
||||
Tensor(element::i32, {3, 3}, std::vector<int32_t>{1, 1, -1, 0, 1, 1, 1, -1, -1}),
|
||||
Tensor(element::i32, {3}, std::vector<int32_t>{2, 3, 1}),
|
||||
"evaluate_ctc_greedy_decoder_seq_len_multiple_batches2"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<CTCGreedyDecoderSeqLenParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<CTCGreedyDecoderSeqLenParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<CTCGreedyDecoderSeqLenParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<CTCGreedyDecoderSeqLenParamsNoOptionalInput> generateParamsNoOptionalInput() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<CTCGreedyDecoderSeqLenParamsNoOptionalInput> params {
|
||||
CTCGreedyDecoderSeqLenParamsNoOptionalInput(
|
||||
Tensor(ET, {1, 3, 3}, std::vector<T>{0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
false,
|
||||
Tensor(element::i32, {1, 3}, std::vector<int32_t>{1, 0, -1}),
|
||||
Tensor(element::i32, {1}, std::vector<int32_t>{2}),
|
||||
"evaluate_ctc_greedy_decoder_seq_len_no_optional_input"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<CTCGreedyDecoderSeqLenParamsNoOptionalInput> generateCombinedParamsNoOptionalInput() {
|
||||
const std::vector<std::vector<CTCGreedyDecoderSeqLenParamsNoOptionalInput>> generatedParams {
|
||||
generateParamsNoOptionalInput<element::Type_t::bf16>(),
|
||||
generateParamsNoOptionalInput<element::Type_t::f16>(),
|
||||
generateParamsNoOptionalInput<element::Type_t::f32>(),
|
||||
generateParamsNoOptionalInput<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<CTCGreedyDecoderSeqLenParamsNoOptionalInput> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_CTCGreedyDecoderSeqLen_With_Hardcoded_Refs, ReferenceCTCGreedyDecoderSeqLenTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceCTCGreedyDecoderSeqLenTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_CTCGreedyDecoderSeqLen_With_Hardcoded_Refs, ReferenceCTCGreedyDecoderSeqLenTestNoOptionalInput,
|
||||
testing::ValuesIn(generateCombinedParamsNoOptionalInput()), ReferenceCTCGreedyDecoderSeqLenTestNoOptionalInput::getTestCaseName);
|
||||
} // namespace
|
@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/experimental_detectron_topkrois.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct ExperimentalDetectronTopKROIsParams {
|
||||
ExperimentalDetectronTopKROIsParams(
|
||||
const Tensor& dataTensor, const Tensor& probsTensor, const int32_t numRois,
|
||||
const Tensor& expectedTensor, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), probsTensor(probsTensor), numRois(numRois),
|
||||
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
Tensor probsTensor;
|
||||
int32_t numRois;
|
||||
Tensor expectedTensor;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceExperimentalDetectronTopKROIsTest : public testing::TestWithParam<ExperimentalDetectronTopKROIsParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.dataTensor.data, params.probsTensor.data};
|
||||
refOutData = {params.expectedTensor.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ExperimentalDetectronTopKROIsParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_pType=" << param.probsTensor.type;
|
||||
result << "_pShape=" << param.probsTensor.shape;
|
||||
result << "_numRois=" << param.numRois;
|
||||
result << "_eType=" << param.expectedTensor.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const ExperimentalDetectronTopKROIsParams& params) {
|
||||
std::shared_ptr<Function> function;
|
||||
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto probs = std::make_shared<op::v0::Parameter>(params.probsTensor.type, params.probsTensor.shape);
|
||||
const auto topkRois = std::make_shared<op::v6::ExperimentalDetectronTopKROIs>(data, probs, params.numRois);
|
||||
function = std::make_shared<ov::Function>(topkRois, ParameterVector{data, probs});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceExperimentalDetectronTopKROIsTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<ExperimentalDetectronTopKROIsParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<ExperimentalDetectronTopKROIsParams> params {
|
||||
ExperimentalDetectronTopKROIsParams(
|
||||
Tensor(ET, {2, 4}, std::vector<T>{1.0f, 1.0f, 3.0f, 4.0f, 2.0f, 1.0f, 5.0f, 7.0f}),
|
||||
Tensor(ET, {2}, std::vector<T>{0.5f, 0.3f}),
|
||||
1,
|
||||
Tensor(ET, {1, 4}, std::vector<T>{1.0, 1.0, 3.0, 4.0}),
|
||||
"experimental_detectron_topk_rois_eval"),
|
||||
ExperimentalDetectronTopKROIsParams(
|
||||
Tensor(ET, {4, 4}, std::vector<T>{1.0f, 1.0f, 4.0f, 5.0f, 3.0f, 2.0f, 7.0f, 9.0f,
|
||||
10.0f, 15.0f, 13.0f, 17.0f, 13.0f, 10.0f, 18.0f, 15.0f}),
|
||||
Tensor(ET, {4}, std::vector<T>{0.1f, 0.7f, 0.5f, 0.9f}),
|
||||
2,
|
||||
Tensor(ET, {2, 4}, std::vector<T>{13.0f, 10.0f, 18.0f, 15.0f, 3.0f, 2.0f, 7.0f, 9.0f}),
|
||||
"experimental_detectron_topk_rois_eval"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<ExperimentalDetectronTopKROIsParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<ExperimentalDetectronTopKROIsParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<ExperimentalDetectronTopKROIsParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_ExperimentalDetectronTopKROIs_With_Hardcoded_Refs, ReferenceExperimentalDetectronTopKROIsTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceExperimentalDetectronTopKROIsTest::getTestCaseName);
|
||||
} // namespace
|
294
docs/template_plugin/tests/functional/op_reference/gru_cell.cpp
Normal file
294
docs/template_plugin/tests/functional/op_reference/gru_cell.cpp
Normal file
@ -0,0 +1,294 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/gru_cell.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct GRUCellParams {
|
||||
GRUCellParams(
|
||||
const int32_t batchSize, const int32_t inputSize, const int32_t hiddenSize, const int32_t gatesCount, const bool linearBeforeReset,
|
||||
const Tensor& X, const Tensor& H_t, const Tensor& W, const Tensor& R, const Tensor& B,
|
||||
const Tensor& Ho, const std::string& testcaseName = "") :
|
||||
batchSize(batchSize), inputSize(inputSize), hiddenSize(hiddenSize), gatesCount(gatesCount), linearBeforeReset(linearBeforeReset),
|
||||
X(X), H_t(H_t), W(W), R(R), B(B), Ho(Ho), testcaseName(testcaseName) {}
|
||||
|
||||
int32_t batchSize;
|
||||
int32_t inputSize;
|
||||
int32_t hiddenSize;
|
||||
int32_t gatesCount;
|
||||
bool linearBeforeReset;
|
||||
Tensor X;
|
||||
Tensor H_t;
|
||||
Tensor W;
|
||||
Tensor R;
|
||||
Tensor B;
|
||||
Tensor Ho;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceGRUCellTest : public testing::TestWithParam<GRUCellParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<GRUCellParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "bSize=" << param.batchSize;
|
||||
result << "_iSize=" << param.inputSize;
|
||||
result << "_hSize=" << param.hiddenSize;
|
||||
result << "_gCount=" << param.gatesCount;
|
||||
result << "_lbReset=" << param.linearBeforeReset;
|
||||
result << "_xType=" << param.X.type;
|
||||
result << "_xShape=" << param.X.shape;
|
||||
result << "_htType=" << param.H_t.type;
|
||||
result << "_htShape=" << param.H_t.shape;
|
||||
result << "_wType=" << param.W.type;
|
||||
result << "_wShape=" << param.W.shape;
|
||||
result << "_rType=" << param.R.type;
|
||||
result << "_rShape=" << param.R.shape;
|
||||
result << "_hoType=" << param.Ho.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_hoShape=" << param.Ho.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_hoShape=" << param.Ho.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const GRUCellParams& params) {
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto gru_cell = std::make_shared<op::v3::GRUCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
params.hiddenSize,
|
||||
std::vector<std::string>{"sigmoid", "tanh"},
|
||||
std::vector<float>{},
|
||||
std::vector<float>{},
|
||||
clip,
|
||||
params.linearBeforeReset);
|
||||
|
||||
auto function = std::make_shared<Function>(NodeVector{gru_cell}, ParameterVector{X, H_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
// Hard Sigmoid activation function is unsupprted with v3::GRUCell
|
||||
class ReferenceGRUCellTestHardsigmoidActivationFunction : public ReferenceGRUCellTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
threshold = 1e-1f;
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data};
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const GRUCellParams& params) {
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto gru_cell = std::make_shared<op::v3::GRUCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
params.hiddenSize,
|
||||
std::vector<std::string>{"hardsigmoid", "hardsigmoid"},
|
||||
std::vector<float>{1.8345f, 1.8345f},
|
||||
std::vector<float>{3.05f, 3.05f},
|
||||
clip,
|
||||
params.linearBeforeReset);
|
||||
|
||||
auto function = std::make_shared<Function>(NodeVector{gru_cell}, ParameterVector{X, H_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceGRUCellTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceGRUCellTestHardsigmoidActivationFunction, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<GRUCellParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<GRUCellParams> params {
|
||||
GRUCellParams(
|
||||
2, 3, 3, 3, false,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.52421564f, 0.78845507f, 0.9372873f, 0.59783894f, 0.18278378f, 0.2084126f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.45738035f, 0.996877f, 0.82882977f, 0.47492632f, 0.88471466f, 0.57833236f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.5815369f, 0.16559383f, 0.08464007f, 0.843122f, 0.73968244f, 0.11359601f,
|
||||
0.8295078f, 0.9240567f, 0.10007995f, 0.20573162f, 0.09002485f, 0.2839569f,
|
||||
0.3096991f, 0.5638341f, 0.5787327f, 0.84552664f, 0.16263747f, 0.7243242f,
|
||||
0.8049057f, 0.43966424f, 0.46294412f, 0.9833361f, 0.31369713f, 0.1719934f,
|
||||
0.4937093f, 0.6353004f, 0.77982515f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.16510165f, 0.52435565f, 0.2788478f, 0.99427545f, 0.1623331f, 0.01389796f,
|
||||
0.99669236f, 0.53901845f, 0.8737506f, 0.9254788f, 0.21172932f, 0.11634306f,
|
||||
0.40111724f, 0.37497616f, 0.2903471f, 0.6796794f, 0.65131867f, 0.78163475f,
|
||||
0.12058706f, 0.45591718f, 0.791677f, 0.76497287f, 0.9895242f, 0.7845312f,
|
||||
0.51267904f, 0.49030215f, 0.08498167f}),
|
||||
Tensor(ET, {3 * 3}, std::vector<T>{
|
||||
0.8286678f + 0.9175602f,
|
||||
0.9153158f + 0.14958014f,
|
||||
0.9581612f + 0.49230585f,
|
||||
0.6639213f + 0.63162816f,
|
||||
0.84239805f + 0.4161903f,
|
||||
0.5282445f + 0.22148274f,
|
||||
0.14153397f + 0.50496656f,
|
||||
0.22404431f + 0.34798595f,
|
||||
0.6549655f + 0.6699164f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.48588726f, 0.99670005f, 0.83759373f, 0.5023099f, 0.89410484f, 0.60011315f}),
|
||||
"gru_cell_bias_clip"),
|
||||
GRUCellParams(
|
||||
2, 3, 3, 3, true,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.12249453f, 0.6127907f, 0.5001741f, 0.5124603f, 0.04329684f, 0.023834f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.72259396f, 0.11561195f, 0.9457856f, 0.19037509f, 0.6964006f, 0.33459795f,
|
||||
0.5468904f, 0.85646594f, 0.5101311f, 0.9712257f, 0.3687071f, 0.60280246f,
|
||||
0.56943774f, 0.7475505f, 0.2490578f, 0.86977345f, 0.85542053f, 0.29660386f,
|
||||
0.49717373f, 0.7473479f, 0.53454477f, 0.15974349f, 0.5804805f, 0.14303213f,
|
||||
0.07514781f, 0.5865731f, 0.76409274f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.91382647f, 0.41527033f, 0.28040004f, 0.23601337f, 0.04471736f, 0.03888785f,
|
||||
0.06308217f, 0.44844428f, 0.29384327f, 0.49037653f, 0.50421673f, 0.7366393f,
|
||||
0.63143945f, 0.00277612f, 0.37198433f, 0.06966069f, 0.4613444f, 0.10999731f,
|
||||
0.78273284f, 0.21453214f, 0.10751773f, 0.18332677f, 0.1326976f, 0.9998985f,
|
||||
0.19263928f, 0.10979804f, 0.52575564f}),
|
||||
Tensor(ET, {(3 + 1) * 3}, std::vector<T>{
|
||||
0.61395123f, // 0.09875853f + 0.5151927f,
|
||||
1.08667738f, // 0.37801138f + 0.708666f,
|
||||
1.32600244f, // 0.7729636f + 0.55303884f,
|
||||
0.81917698f, // 0.78493553f + 0.03424145f,
|
||||
1.37736335f, // 0.5662702f + 0.81109315f,
|
||||
0.42931147f, // 0.12406381f + 0.30524766f,
|
||||
0.66729516f,
|
||||
0.7752771f,
|
||||
0.78819966f,
|
||||
0.6606634f,
|
||||
0.99040645f,
|
||||
0.21112025f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8709214f, 0.48411977f, 0.74495184f, 0.6074972f, 0.44572943f, 0.1467715f}),
|
||||
"gru_cell_linear_before_reset"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<GRUCellParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<GRUCellParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<GRUCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<GRUCellParams> generateParamsHardsigmoidActivationFunction() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<GRUCellParams> params {
|
||||
GRUCellParams(
|
||||
2, 3, 3, 3, true,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.12249453f, 0.6127907f, 0.5001741f, 0.5124603f, 0.04329684f, 0.023834f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.72259396f, 0.11561195f, 0.9457856f, 0.19037509f, 0.6964006f, 0.33459795f,
|
||||
0.5468904f, 0.85646594f, 0.5101311f, 0.9712257f, 0.3687071f, 0.60280246f,
|
||||
0.56943774f, 0.7475505f, 0.2490578f, 0.86977345f, 0.85542053f, 0.29660386f,
|
||||
0.49717373f, 0.7473479f, 0.53454477f, 0.15974349f, 0.5804805f, 0.14303213f,
|
||||
0.07514781f, 0.5865731f, 0.76409274f}),
|
||||
Tensor(ET, {3 * 3, 3}, std::vector<T>{
|
||||
0.91382647f, 0.41527033f, 0.28040004f, 0.23601337f, 0.04471736f, 0.03888785f,
|
||||
0.06308217f, 0.44844428f, 0.29384327f, 0.49037653f, 0.50421673f, 0.7366393f,
|
||||
0.63143945f, 0.00277612f, 0.37198433f, 0.06966069f, 0.4613444f, 0.10999731f,
|
||||
0.78273284f, 0.21453214f, 0.10751773f, 0.18332677f, 0.1326976f, 0.9998985f,
|
||||
0.19263928f, 0.10979804f, 0.52575564f}),
|
||||
Tensor(ET, {(3 + 1) * 3}, std::vector<T>{
|
||||
0.09875853f + 0.5151927f,
|
||||
0.37801138f + 0.708666f,
|
||||
0.7729636f + 0.55303884f,
|
||||
0.78493553f + 0.03424145f,
|
||||
0.5662702f + 0.81109315f,
|
||||
0.12406381f + 0.30524766f,
|
||||
0.66729516f,
|
||||
0.7752771f,
|
||||
0.78819966f,
|
||||
0.6606634f,
|
||||
0.99040645f,
|
||||
0.21112025f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f}),
|
||||
"gru_cell_hardsigmoid_activation_function"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<GRUCellParams> generateCombinedParamsHardsigmoidActivationFunction() {
|
||||
const std::vector<std::vector<GRUCellParams>> generatedParams {
|
||||
generateParamsHardsigmoidActivationFunction<element::Type_t::bf16>(),
|
||||
generateParamsHardsigmoidActivationFunction<element::Type_t::f16>(),
|
||||
generateParamsHardsigmoidActivationFunction<element::Type_t::f32>(),
|
||||
generateParamsHardsigmoidActivationFunction<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<GRUCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_GRUCell_With_Hardcoded_Refs, ReferenceGRUCellTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceGRUCellTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_GRUCell_With_Hardcoded_Refs, ReferenceGRUCellTestHardsigmoidActivationFunction,
|
||||
testing::ValuesIn(generateCombinedParamsHardsigmoidActivationFunction()), ReferenceGRUCellTest::getTestCaseName);
|
||||
} // namespace
|
379
docs/template_plugin/tests/functional/op_reference/lstm_cell.cpp
Normal file
379
docs/template_plugin/tests/functional/op_reference/lstm_cell.cpp
Normal file
@ -0,0 +1,379 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/lstm_cell.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct LSTMCellParams {
|
||||
LSTMCellParams(
|
||||
int32_t batchSize, int32_t inputSize, int32_t hiddenSize, int32_t gatesCount,
|
||||
const Tensor& X, const Tensor& W, const Tensor& R, const Tensor& H_t, const Tensor& C_t, const Tensor& B,
|
||||
const Tensor& Ho, const Tensor& Co, const std::string& testcaseName = "") :
|
||||
batchSize(batchSize), inputSize(inputSize), hiddenSize(hiddenSize), gatesCount(gatesCount),
|
||||
X(X), W(W), R(R), H_t(H_t), C_t(C_t), B(B), Ho(Ho), Co(Co), testcaseName(testcaseName) {}
|
||||
|
||||
int32_t batchSize;
|
||||
int32_t inputSize;
|
||||
int32_t hiddenSize;
|
||||
int32_t gatesCount;
|
||||
Tensor X;
|
||||
Tensor W;
|
||||
Tensor R;
|
||||
Tensor H_t;
|
||||
Tensor C_t;
|
||||
Tensor B;
|
||||
Tensor Ho;
|
||||
Tensor Co;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceLSTMCellTest : public testing::TestWithParam<LSTMCellParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.C_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data, params.Co.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<LSTMCellParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "bSize=" << param.batchSize;
|
||||
result << "_iSize=" << param.inputSize;
|
||||
result << "_hSize=" << param.hiddenSize;
|
||||
result << "_gCount=" << param.gatesCount;
|
||||
result << "_xType=" << param.X.type;
|
||||
result << "_xShape=" << param.X.shape;
|
||||
result << "_wType=" << param.W.type;
|
||||
result << "_wShape=" << param.W.shape;
|
||||
result << "_rType=" << param.R.type;
|
||||
result << "_rShape=" << param.R.shape;
|
||||
result << "_htType=" << param.H_t.type;
|
||||
result << "_htShape=" << param.H_t.shape;
|
||||
result << "_ctType=" << param.C_t.type;
|
||||
result << "_ctShape=" << param.C_t.shape;
|
||||
result << "_hoType=" << param.Ho.type;
|
||||
result << "_hoShape=" << param.Ho.shape;
|
||||
result << "_coType=" << param.Co.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_coShape=" << param.Co.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_coShape=" << param.Co.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const LSTMCellParams& params) {
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto C_t = std::make_shared<op::v0::Parameter>(params.C_t.type, params.C_t.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto lstm_cell =
|
||||
std::make_shared<op::v4::LSTMCell>(X,
|
||||
H_t,
|
||||
C_t,
|
||||
op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(R, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(B, op::util::LSTMWeightsFormat::IOFC),
|
||||
params.hiddenSize);
|
||||
|
||||
auto function = std::make_shared<Function>(lstm_cell->outputs(), ParameterVector{X, H_t, C_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceLSTMCellTestBiasDefaultAttrs : public ReferenceLSTMCellTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
threshold = 1e-1f;
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.C_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data, params.Co.data};
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const LSTMCellParams& params) {
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto C_t = std::make_shared<op::v0::Parameter>(params.C_t.type, params.C_t.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto lstm_cell =
|
||||
std::make_shared<op::v4::LSTMCell>(X,
|
||||
H_t,
|
||||
C_t,
|
||||
op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(R, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(B, op::util::LSTMWeightsFormat::IOFC),
|
||||
params.hiddenSize);
|
||||
|
||||
auto function = std::make_shared<Function>(lstm_cell->outputs(), ParameterVector{X, H_t, C_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceLSTMCellTestBiasClip : public ReferenceLSTMCellTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
threshold = 1e-1f;
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.C_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data, params.Co.data};
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const LSTMCellParams& params) {
|
||||
const float clip_threshold = 3.5f;
|
||||
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto C_t = std::make_shared<op::v0::Parameter>(params.C_t.type, params.C_t.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto lstm_cell =
|
||||
std::make_shared<op::v4::LSTMCell>(X,
|
||||
H_t,
|
||||
C_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
params.hiddenSize,
|
||||
std::vector<std::string>{"sigmoid", "tanh", "tanh"},
|
||||
std::vector<float>{},
|
||||
std::vector<float>{},
|
||||
clip_threshold);
|
||||
|
||||
auto function = std::make_shared<Function>(lstm_cell->outputs(), ParameterVector{X, H_t, C_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceLSTMCellTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceLSTMCellTestBiasDefaultAttrs, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceLSTMCellTestBiasClip, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<LSTMCellParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<LSTMCellParams> params {
|
||||
LSTMCellParams(
|
||||
2, 3, 3, 4,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f}),
|
||||
Tensor(ET, {4 * 3}, std::vector<T>(4 * 3, 0.f)),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.81457126f, 0.61109227f, 0.769522f, 0.52239674f, 0.4324641f, 0.63183f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{1.4444952f, 0.9635685f, 1.2875274f, 0.8053419f, 0.7184521f, 0.95803297f}),
|
||||
"lstm_cell_zero_bias_default_attrs"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<LSTMCellParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<LSTMCellParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<LSTMCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<LSTMCellParams> generateParamsBiasDefaultAttrs() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<LSTMCellParams> params {
|
||||
LSTMCellParams(
|
||||
2, 3, 3, 4,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f}),
|
||||
Tensor(ET, {4 * 3}, std::vector<T>{1.07393714f,
|
||||
1.15248052f,
|
||||
1.16671345f,
|
||||
0.21450312f,
|
||||
1.2380678f,
|
||||
1.51688835f,
|
||||
0.46718366f,
|
||||
0.91810346f,
|
||||
1.1274234f,
|
||||
0.51022074f,
|
||||
1.11389844f,
|
||||
0.74174305f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.81014400720596313,
|
||||
0.76665538549423218,
|
||||
0.82509011030197144,
|
||||
0.6479143500328064,
|
||||
0.66586339473724365,
|
||||
0.74838578701019287}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{1.6800162792205811,
|
||||
1.1150213479995728,
|
||||
1.4578367471694946,
|
||||
1.0649888515472412,
|
||||
0.93761754035949707,
|
||||
1.3659683465957642}),
|
||||
"lstm_cell_bias_default_attrs"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<LSTMCellParams> generateCombinedParamsBiasDefaultAttrs() {
|
||||
const std::vector<std::vector<LSTMCellParams>> generatedParams {
|
||||
generateParamsBiasDefaultAttrs<element::Type_t::bf16>(),
|
||||
generateParamsBiasDefaultAttrs<element::Type_t::f16>(),
|
||||
generateParamsBiasDefaultAttrs<element::Type_t::f32>(),
|
||||
generateParamsBiasDefaultAttrs<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<LSTMCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<LSTMCellParams> generateParamsBiasClip() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<LSTMCellParams> params {
|
||||
LSTMCellParams(
|
||||
2, 3, 3, 4,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f}),
|
||||
Tensor(ET, {4 * 3, 3}, std::vector<T>{
|
||||
0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f}),
|
||||
Tensor(ET, {4 * 3}, std::vector<T>{1.07393714f,
|
||||
1.15248052f,
|
||||
1.16671345f,
|
||||
0.21450312f,
|
||||
1.2380678f,
|
||||
1.51688835f,
|
||||
0.46718366f,
|
||||
0.91810346f,
|
||||
1.1274234f,
|
||||
0.51022074f,
|
||||
1.11389844f,
|
||||
0.74174305f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.81014400720596313,
|
||||
0.76665538549423218,
|
||||
0.82387429475784302,
|
||||
0.6479143500328064,
|
||||
0.66586339473724365,
|
||||
0.74838578701019287}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{1.6800162792205811,
|
||||
1.1150213479995728,
|
||||
1.4510968923568726,
|
||||
1.0649888515472412,
|
||||
0.93761754035949707,
|
||||
1.3659683465957642}),
|
||||
"lstm_cell_bias_clip"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<LSTMCellParams> generateCombinedParamsBiasClip() {
|
||||
const std::vector<std::vector<LSTMCellParams>> generatedParams {
|
||||
generateParamsBiasClip<element::Type_t::bf16>(),
|
||||
generateParamsBiasClip<element::Type_t::f16>(),
|
||||
generateParamsBiasClip<element::Type_t::f32>(),
|
||||
generateParamsBiasClip<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<LSTMCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LSTMCell_With_Hardcoded_Refs, ReferenceLSTMCellTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceLSTMCellTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LSTMCell_With_Hardcoded_Refs, ReferenceLSTMCellTestBiasDefaultAttrs,
|
||||
testing::ValuesIn(generateCombinedParamsBiasDefaultAttrs()), ReferenceLSTMCellTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LSTMCell_With_Hardcoded_Refs, ReferenceLSTMCellTestBiasClip,
|
||||
testing::ValuesIn(generateCombinedParamsBiasClip()), ReferenceLSTMCellTest::getTestCaseName);
|
||||
} // namespace
|
226
docs/template_plugin/tests/functional/op_reference/one_hot.cpp
Normal file
226
docs/template_plugin/tests/functional/op_reference/one_hot.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/one_hot.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct OneHotParams {
|
||||
OneHotParams(
|
||||
const Tensor& dataTensor, const int32_t axis,
|
||||
const Tensor& depthTensor, const Tensor& onValueTensor, const Tensor& offValueTensor,
|
||||
const Tensor& expectedTensor, const std::string& testcaseName = "") :
|
||||
dataTensor(dataTensor), axis(axis),
|
||||
depthTensor(depthTensor), onValueTensor(onValueTensor), offValueTensor(offValueTensor),
|
||||
expectedTensor(expectedTensor), testcaseName(testcaseName) {}
|
||||
|
||||
Tensor dataTensor;
|
||||
int32_t axis;
|
||||
Tensor depthTensor;
|
||||
Tensor onValueTensor;
|
||||
Tensor offValueTensor;
|
||||
Tensor expectedTensor;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceOneHotTest : public testing::TestWithParam<OneHotParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.dataTensor.data};
|
||||
refOutData = {params.expectedTensor.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<OneHotParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dType=" << param.dataTensor.type;
|
||||
result << "_dShape=" << param.dataTensor.shape;
|
||||
result << "_axis=" << param.axis;
|
||||
result << "_deType=" << param.depthTensor.type;
|
||||
result << "_deShape=" << param.depthTensor.shape;
|
||||
result << "_onType=" << param.onValueTensor.type;
|
||||
result << "_onShape=" << param.onValueTensor.shape;
|
||||
result << "_offType=" << param.offValueTensor.type;
|
||||
result << "_offShape=" << param.offValueTensor.shape;
|
||||
result << "_eType=" << param.expectedTensor.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_eShape=" << param.expectedTensor.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const OneHotParams& params) {
|
||||
std::shared_ptr<Function> function;
|
||||
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type, params.dataTensor.shape);
|
||||
const auto depth = std::make_shared<op::v0::Constant>(params.depthTensor.type, params.depthTensor.shape,
|
||||
params.depthTensor.data.data());
|
||||
const auto onValue = std::make_shared<op::v0::Constant>(params.onValueTensor.type, params.onValueTensor.shape,
|
||||
params.onValueTensor.data.data());
|
||||
const auto offValue = std::make_shared<op::v0::Constant>(params.offValueTensor.type, params.offValueTensor.shape,
|
||||
params.offValueTensor.data.data());
|
||||
const auto oneHot = std::make_shared<op::v1::OneHot>(data, depth, onValue, offValue, params.axis);
|
||||
function = std::make_shared<ov::Function>(oneHot, ParameterVector{data});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceOneHotTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> generateExpectedValues(const Shape& input_shape, std::vector<T> input, uint32_t category_count) {
|
||||
// std::vector<T> input{0, 11, 101, 1001, 10001, static_cast<int32_t>(category_count - 1)};
|
||||
std::vector<T> output(shape_size(input_shape), 0);
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
output[i * category_count + input[i]] = 1;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
template <element::Type_t ET1, element::Type_t ET2>
|
||||
std::vector<OneHotParams> generateParams() {
|
||||
using T1 = typename element_type_traits<ET1>::value_type;
|
||||
using T2 = typename element_type_traits<ET2>::value_type;
|
||||
std::vector<OneHotParams> params {
|
||||
OneHotParams(
|
||||
Tensor(ET1, {}, std::vector<T1>{2}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {3}, std::vector<T2>{0, 0, 1}),
|
||||
"one_hot_scalar_2_in_3"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {}, std::vector<T1>{1}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {3}, std::vector<T2>{0, 1, 0}),
|
||||
"one_hot_scalar_1_in_3"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {}, std::vector<T1>{0}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {3}, std::vector<T2>{1, 0, 0}),
|
||||
"one_hot_scalar_0_in_3"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {8}, std::vector<T1>{2, 1, 0, 0, 2, 2, 1, 0}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {3, 8}, std::vector<T2>{0, 0, 1, 1, 0, 0, 0, 1,
|
||||
0, 1, 0, 0, 0, 0, 1, 0,
|
||||
1, 0, 0, 0, 1, 1, 0, 0}),
|
||||
"one_hot_vector_0"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {8}, std::vector<T1>{2, 1, 0, 0, 2, 2, 1, 0}),
|
||||
1,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {8, 3}, std::vector<T2>{0, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 0, 0, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 0}),
|
||||
"one_hot_vector_1"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {8}, std::vector<T1>{2, 1, 0, 0, 3, 2, 1, 0}),
|
||||
1,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {8, 3}, std::vector<T2>{0, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 0}),
|
||||
"one_hot_vector_1_barely_oob"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {3, 3}, std::vector<T1>{0, 1, 1, 2, 1, 0, 0, 2, 1}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {3, 3, 3}, std::vector<T2>{1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,
|
||||
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0}),
|
||||
"one_hot_matrix_0"),
|
||||
OneHotParams(
|
||||
Tensor(ET1, {6}, std::vector<T1>{0, 11, 101, 1001, 10001, 19999}),
|
||||
1,
|
||||
Tensor(ET1, {}, std::vector<T1>{20000}),
|
||||
Tensor(ET2, {}, std::vector<T2>{1}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0}),
|
||||
Tensor(ET2, {6, 20000}, generateExpectedValues({6, 20000},
|
||||
std::vector<T2>{0, 11, 101, 1001, 10001, 19999},
|
||||
20000)),
|
||||
"one_hot_vector_many_categories"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t ET1, element::Type_t ET2>
|
||||
std::vector<OneHotParams> generateParamsFloat() {
|
||||
using T1 = typename element_type_traits<ET1>::value_type;
|
||||
using T2 = typename element_type_traits<ET2>::value_type;
|
||||
std::vector<OneHotParams> params {
|
||||
OneHotParams(
|
||||
Tensor(ET1, {3, 3}, std::vector<T1>{0, 1, 1, 2, 1, 0, 0, 2, 1}),
|
||||
0,
|
||||
Tensor(ET1, {}, std::vector<T1>{3}),
|
||||
Tensor(ET2, {}, std::vector<T2>{2.5}),
|
||||
Tensor(ET2, {}, std::vector<T2>{0.5}),
|
||||
Tensor(ET2, {3, 3, 3}, std::vector<T2>{
|
||||
2.5, 0.5, 0.5, 0.5, 0.5, 2.5, 2.5, 0.5, 0.5, 0.5, 2.5, 2.5, 0.5, 2.5,
|
||||
0.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 2.5, 0.5}),
|
||||
"one_hot_on_off_float"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<OneHotParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<OneHotParams>> generatedParams {
|
||||
generateParams<element::Type_t::i32, element::Type_t::i16>(),
|
||||
generateParams<element::Type_t::i32, element::Type_t::i32>(),
|
||||
generateParams<element::Type_t::i32, element::Type_t::i64>(),
|
||||
generateParams<element::Type_t::i32, element::Type_t::u16>(),
|
||||
generateParams<element::Type_t::i32, element::Type_t::u32>(),
|
||||
generateParams<element::Type_t::i32, element::Type_t::u64>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::i16>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::i64>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::u16>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::u32>(),
|
||||
generateParams<element::Type_t::i64, element::Type_t::u64>(),
|
||||
generateParamsFloat<element::Type_t::i32, element::Type_t::bf16>(),
|
||||
generateParamsFloat<element::Type_t::i32, element::Type_t::f16>(),
|
||||
generateParamsFloat<element::Type_t::i32, element::Type_t::f32>(),
|
||||
generateParamsFloat<element::Type_t::i32, element::Type_t::f64>(),
|
||||
generateParamsFloat<element::Type_t::i64, element::Type_t::f32>(),
|
||||
generateParamsFloat<element::Type_t::i64, element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<OneHotParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_OneHot_With_Hardcoded_Refs, ReferenceOneHotTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceOneHotTest::getTestCaseName);
|
||||
} // namespace
|
304
docs/template_plugin/tests/functional/op_reference/rnn_cell.cpp
Normal file
304
docs/template_plugin/tests/functional/op_reference/rnn_cell.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/rnn_cell.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct RNNCellParams {
|
||||
RNNCellParams(
|
||||
int32_t batchSize, int32_t inputSize, int32_t hiddenSize,
|
||||
const Tensor& X, const Tensor& H_t, const Tensor& W, const Tensor& R, const Tensor& B,
|
||||
const Tensor& Ho, const std::string& testcaseName = "") :
|
||||
batchSize(batchSize), inputSize(inputSize), hiddenSize(hiddenSize),
|
||||
X(X), H_t(H_t), W(W), R(R), B(B), Ho(Ho), testcaseName(testcaseName) {}
|
||||
|
||||
int32_t batchSize;
|
||||
int32_t inputSize;
|
||||
int32_t hiddenSize;
|
||||
Tensor X;
|
||||
Tensor H_t;
|
||||
Tensor W;
|
||||
Tensor R;
|
||||
Tensor B;
|
||||
Tensor Ho;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceRNNCellTest : public testing::TestWithParam<RNNCellParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<RNNCellParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "bSize=" << param.batchSize;
|
||||
result << "_iSize=" << param.inputSize;
|
||||
result << "_hSize=" << param.hiddenSize;
|
||||
result << "_xType=" << param.X.type;
|
||||
result << "_xShape=" << param.X.shape;
|
||||
result << "_htType=" << param.H_t.type;
|
||||
result << "_htShape=" << param.H_t.shape;
|
||||
result << "_wType=" << param.W.type;
|
||||
result << "_wShape=" << param.W.shape;
|
||||
result << "_rType=" << param.R.type;
|
||||
result << "_rShape=" << param.R.shape;
|
||||
result << "_hoType=" << param.Ho.type;
|
||||
if (param.testcaseName != "") {
|
||||
result << "_hoShape=" << param.Ho.shape;
|
||||
result << "_=" << param.testcaseName;
|
||||
} else {
|
||||
result << "_hoShape=" << param.Ho.shape;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const RNNCellParams& params) {
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto rnn_cell = std::make_shared<op::v0::RNNCell>(X, H_t, W, R, B, params.hiddenSize);
|
||||
auto function = std::make_shared<Function>(NodeVector{rnn_cell}, ParameterVector{X, H_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceRNNCellTestBiasClip : public ReferenceRNNCellTest {
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const RNNCellParams& params) {
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto rnn_cell = std::make_shared<op::v0::RNNCell>(
|
||||
X, H_t, W, R, B, params.hiddenSize,
|
||||
std::vector<std::string>{"tanh"}, std::vector<float>{}, std::vector<float>{}, clip);
|
||||
auto function = std::make_shared<Function>(NodeVector{rnn_cell}, ParameterVector{X, H_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceRNNCellTestSigmoidActivationFunction : public ReferenceRNNCellTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.X.data, params.H_t.data, params.W.data, params.R.data, params.B.data};
|
||||
refOutData = {params.Ho.data};
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const RNNCellParams& params) {
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = std::make_shared<op::v0::Parameter>(params.X.type, params.X.shape);
|
||||
const auto H_t = std::make_shared<op::v0::Parameter>(params.H_t.type, params.H_t.shape);
|
||||
const auto W = std::make_shared<op::v0::Parameter>(params.W.type, params.W.shape);
|
||||
const auto R = std::make_shared<op::v0::Parameter>(params.R.type, params.R.shape);
|
||||
const auto B = std::make_shared<op::v0::Parameter>(params.B.type, params.B.shape);
|
||||
|
||||
const auto rnn_cell = std::make_shared<op::v0::RNNCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
params.hiddenSize,
|
||||
std::vector<std::string>{"sigmoid"},
|
||||
std::vector<float>{},
|
||||
std::vector<float>{},
|
||||
clip);
|
||||
auto function = std::make_shared<Function>(NodeVector{rnn_cell}, ParameterVector{X, H_t, W, R, B});
|
||||
return function;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceRNNCellTest, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceRNNCellTestBiasClip, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceRNNCellTestSigmoidActivationFunction, CompareWithRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<RNNCellParams> generateParams() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<RNNCellParams> params {
|
||||
RNNCellParams(
|
||||
2, 3, 3,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f}),
|
||||
Tensor(ET, {3}, std::vector<T>{0.0f, 0.0f, 0.0f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.9408395f, 0.53823817f, 0.84270686f, 0.98932856f, 0.768665f, 0.90461975f}),
|
||||
"rnn_cell_zero_bias_default_attrs"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<RNNCellParams> generateCombinedParams() {
|
||||
const std::vector<std::vector<RNNCellParams>> generatedParams {
|
||||
generateParams<element::Type_t::bf16>(),
|
||||
generateParams<element::Type_t::f16>(),
|
||||
generateParams<element::Type_t::f32>(),
|
||||
generateParams<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<RNNCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<RNNCellParams> generateParamsBiasClip() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<RNNCellParams> params {
|
||||
RNNCellParams(
|
||||
2, 3, 3,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f}),
|
||||
Tensor(ET, {3}, std::vector<T>{1.0289404f, 1.6362579f, 0.4370661f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.9922437f, 0.97749525f, 0.9312212f, 0.9937176f, 0.9901317f, 0.95906746f}),
|
||||
"rnn_cell_bias_clip"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<RNNCellParams> generateCombinedParamsBiasClip() {
|
||||
const std::vector<std::vector<RNNCellParams>> generatedParams {
|
||||
generateParamsBiasClip<element::Type_t::bf16>(),
|
||||
generateParamsBiasClip<element::Type_t::f16>(),
|
||||
generateParamsBiasClip<element::Type_t::f32>(),
|
||||
generateParamsBiasClip<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<RNNCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<RNNCellParams> generateParamsSigmoidActivationFunction() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
std::vector<RNNCellParams> params {
|
||||
RNNCellParams(
|
||||
2, 3, 3,
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{
|
||||
0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f}),
|
||||
Tensor(ET, {3, 3}, std::vector<T>{0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f}),
|
||||
Tensor(ET, {3}, std::vector<T>{1.0289404f, 1.6362579f, 0.4370661f}),
|
||||
Tensor(ET, {2, 3}, std::vector<T>{0.94126844f, 0.9036043f, 0.841243f, 0.9468489f, 0.934215f, 0.873708f}),
|
||||
"rnn_cell_sigmoid_activation_function"),
|
||||
};
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<RNNCellParams> generateCombinedParamsSigmoidActivationFunction() {
|
||||
const std::vector<std::vector<RNNCellParams>> generatedParams {
|
||||
generateParamsSigmoidActivationFunction<element::Type_t::bf16>(),
|
||||
generateParamsSigmoidActivationFunction<element::Type_t::f16>(),
|
||||
generateParamsSigmoidActivationFunction<element::Type_t::f32>(),
|
||||
generateParamsSigmoidActivationFunction<element::Type_t::f64>(),
|
||||
};
|
||||
std::vector<RNNCellParams> combinedParams;
|
||||
|
||||
for (const auto& params : generatedParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_RNNCell_With_Hardcoded_Refs, ReferenceRNNCellTest,
|
||||
testing::ValuesIn(generateCombinedParams()), ReferenceRNNCellTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_RNNCell_With_Hardcoded_Refs, ReferenceRNNCellTestBiasClip,
|
||||
testing::ValuesIn(generateCombinedParamsBiasClip()), ReferenceRNNCellTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_RNNCell_With_Hardcoded_Refs, ReferenceRNNCellTestSigmoidActivationFunction,
|
||||
testing::ValuesIn(generateCombinedParamsSigmoidActivationFunction()), ReferenceRNNCellTest::getTestCaseName);
|
||||
} // namespace
|
@ -86,6 +86,8 @@ std::vector<std::string> disabledTestPatterns() {
|
||||
// CVS-64050
|
||||
R"(.*ReferenceSpaceToBatchLayerTest.*dType=i4.*)",
|
||||
R"(.*ReferenceSpaceToBatchLayerTest.*dType=u4.*)",
|
||||
// CVS-64066
|
||||
R"(.*ReferenceGRUCellTestHardsigmoidActivationFunction.*gru_cell_hardsigmoid_activation_function)",
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -286,6 +286,8 @@ set(SRC
|
||||
visitors/op/convolution.cpp
|
||||
visitors/op/cos.cpp
|
||||
visitors/op/cosh.cpp
|
||||
visitors/op/ctc_greedy_decoder.cpp
|
||||
visitors/op/ctc_greedy_decoder_seq_len.cpp
|
||||
visitors/op/ctc_loss.cpp
|
||||
visitors/op/cum_sum.cpp
|
||||
visitors/op/deformable_convolution.cpp
|
||||
@ -304,6 +306,7 @@ set(SRC
|
||||
visitors/op/exp.cpp
|
||||
visitors/op/experimental_detectron_detection_output.cpp
|
||||
visitors/op/experimental_detectron_generate_proposals.cpp
|
||||
visitors/op/experimental_detectron_topkrois.cpp
|
||||
visitors/op/extractimagepatches.cpp
|
||||
visitors/op/fake_quantize.cpp
|
||||
visitors/op/floor_mod.cpp
|
||||
@ -482,10 +485,7 @@ set(MULTI_TEST_SRC
|
||||
backend/broadcast.in.cpp
|
||||
backend/builder_reduce_ops_opset1.in.cpp
|
||||
backend/concat.in.cpp
|
||||
backend/ctc_greedy_decoder.in.cpp
|
||||
backend/ctc_greedy_decoder_seq_len.in.cpp
|
||||
backend/dyn_reshape.in.cpp
|
||||
backend/experimental_detectron_topk_rois.in.cpp
|
||||
backend/dynamic.in.cpp
|
||||
backend/experimental_detectron_prior_grid.in.cpp
|
||||
backend/function_name.in.cpp
|
||||
@ -496,8 +496,6 @@ set(MULTI_TEST_SRC
|
||||
backend/multiple_result.in.cpp
|
||||
backend/node_name.in.cpp
|
||||
backend/non_max_suppression.in.cpp
|
||||
backend/one_hot.in.cpp
|
||||
backend/recurrent_cells.in.cpp
|
||||
backend/region_yolo.in.cpp
|
||||
backend/sqrt.in.cpp
|
||||
backend/tile.in.cpp
|
||||
|
@ -1,177 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
// clang-format off
|
||||
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#endif
|
||||
|
||||
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "engines_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}, ctc_greedy_decoder) {
|
||||
const int T = 3;
|
||||
const int N = 1;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<float>({1.0f, 1.0f, 1.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 0.0f, 1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_f16) {
|
||||
const int T = 3;
|
||||
const int N = 1;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f16, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f16, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float16>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<float16>({1.0f, 1.0f, 1.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float16>{1.0f, 0.0f, 1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_multiple_batches) {
|
||||
const int T = 3;
|
||||
const int N = 2;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>(
|
||||
{0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f, 0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f});
|
||||
|
||||
test_case.add_input<float>({1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f});
|
||||
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_single_batch_short_sequence) {
|
||||
const int T = 3;
|
||||
const int N = 1;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<float>({1.0f, 1.0f, 0.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 0.0f, -1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_merge) {
|
||||
const int T = 3;
|
||||
const int N = 1;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, true);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.3f, 0.4f, 0.f, 0.6f, 0.5f, 0.f});
|
||||
test_case.add_input<float>({1.0f, 1.0f, 1.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 0.0f, -1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_single_no_merge) {
|
||||
const int T = 3;
|
||||
const int N = 1;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.3f, 0.4f, 0.f, 0.6f, 0.5f, 0.f});
|
||||
test_case.add_input<float>({1.0f, 1.0f, 1.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 1.0f, 0.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, ctc_greedy_decoder_multiple_sequences) {
|
||||
const int T = 2;
|
||||
const int N = 2;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{T, N, C};
|
||||
const auto masks_shape = Shape{T, N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto masks = make_shared<op::Parameter>(element::f32, masks_shape);
|
||||
auto decoder = make_shared<op::CTCGreedyDecoder>(data, masks, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, masks});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f, 0.7f, 0.8f, 0.f});
|
||||
test_case.add_input<float>({1.0f, 1.0f, 1.0f, 0.0f});
|
||||
test_case.add_expected_output(Shape{N, T, 1, 1}, vector<float>{1.0f, 1.0f, 0.0f, -1.0f});
|
||||
|
||||
test_case.run_with_tolerance_as_fp(1.0e-4f);
|
||||
}
|
@ -1,172 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
// clang-format off
|
||||
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#endif
|
||||
|
||||
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "engines_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}, evaluate_ctc_greedy_decoder_seq_len) {
|
||||
const int N = 1;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<int32_t>({2});
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, 0, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{2});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, evaluate_ctc_greedy_decoder_seq_len_merge) {
|
||||
const int N = 1;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, true);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<int32_t>({2});
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, 0, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{2});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, evaluate_ctc_greedy_decoder_seq_len_f16) {
|
||||
const int N = 1;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f16, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, true);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float16>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<int32_t>({2});
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, 0, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{2});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, evaluate_ctc_greedy_decoder_seq_len_multiple_batches) {
|
||||
const int N = 2;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>(
|
||||
{0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f, 0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f});
|
||||
|
||||
test_case.add_input<int32_t>({1, 1});
|
||||
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, -1, -1, 0, -1, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{1, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, evaluate_ctc_greedy_decoder_seq_len_multiple_batches2) {
|
||||
const int N = 3;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f,
|
||||
0.45f, 0.35f, 0.f, 0.5f, 0.6f, 0.f, 0.55f, 0.65f, 0.f,
|
||||
0.1f, 0.2f, 0.f, 0.15f, 0.25f, 0.f, 0.4f, 0.3f, 0.f});
|
||||
|
||||
test_case.add_input<int32_t>({2, 3, 1});
|
||||
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, 1, -1, 0, 1, 1, 1, -1, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{2, 3, 1});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, evaluate_ctc_greedy_decoder_seq_len_no_optional_input) {
|
||||
const int N = 1;
|
||||
const int T = 3;
|
||||
const int C = 3;
|
||||
const auto data_shape = Shape{N, T, C};
|
||||
const auto seq_len_shape = Shape{N};
|
||||
|
||||
auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, seq_len_shape);
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, false);
|
||||
auto function = make_shared<Function>(decoder, ParameterVector{data, seq_len});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
test_case.add_input<float>({0.1f, 0.2f, 0.f, 0.4f, 0.3f, 0.f, 0.5f, 0.6f, 0.f});
|
||||
test_case.add_input<int32_t>({2});
|
||||
test_case.add_expected_output(Shape{N, T}, vector<int32_t>{1, 0, -1});
|
||||
test_case.add_expected_output(Shape{N}, vector<int32_t>{2});
|
||||
|
||||
test_case.run();
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "engines_util/test_case.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/runtime/tensor.hpp"
|
||||
#include "runtime/backend.hpp"
|
||||
#include "util/all_close.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/ndarray.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
using ExperimentalTopK = op::v6::ExperimentalDetectronTopKROIs;
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, experimental_detectron_topk_rois_eval) {
|
||||
size_t num_rois = 1;
|
||||
|
||||
const auto input_rois_shape = Shape{2, 4};
|
||||
const auto input_probs_shape = Shape{2};
|
||||
const auto output_shape = Shape{1, 4};
|
||||
|
||||
auto input_rois = std::make_shared<op::Parameter>(element::f32, input_rois_shape);
|
||||
auto input_probs = std::make_shared<op::Parameter>(element::f32, input_probs_shape);
|
||||
auto topk_rois = std::make_shared<ExperimentalTopK>(input_rois, input_probs, num_rois);
|
||||
auto f = std::make_shared<Function>(topk_rois, ParameterVector{input_rois, input_probs});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto topk_rois_output = backend->create_tensor(element::f32, output_shape);
|
||||
|
||||
std::vector<float> input_rois_data = {1.0f, 1.0f, 3.0f, 4.0f, 2.0f, 1.0f, 5.0f, 7.0f};
|
||||
std::vector<float> input_probs_data = {0.5f, 0.3f};
|
||||
std::vector<float> expected_result = {1.0, 1.0, 3.0, 4.0};
|
||||
|
||||
auto backend_input_rois_data = backend->create_tensor(element::f32, input_rois_shape);
|
||||
copy_data(backend_input_rois_data, input_rois_data);
|
||||
auto backend_input_probs_data = backend->create_tensor(element::f32, input_probs_shape);
|
||||
copy_data(backend_input_probs_data, input_probs_data);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call({topk_rois_output}, {backend_input_rois_data, backend_input_probs_data});
|
||||
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(topk_rois_output), expected_result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, experimental_detectron_topk_rois_eval_2) {
|
||||
size_t num_rois = 2;
|
||||
|
||||
const auto input_rois_shape = Shape{4, 4};
|
||||
const auto input_probs_shape = Shape{4};
|
||||
const auto output_shape = Shape{2, 4};
|
||||
|
||||
auto input_rois = std::make_shared<op::Parameter>(element::f32, input_rois_shape);
|
||||
auto input_probs = std::make_shared<op::Parameter>(element::f32, input_probs_shape);
|
||||
auto topk_rois = std::make_shared<ExperimentalTopK>(input_rois, input_probs, num_rois);
|
||||
auto f = std::make_shared<Function>(topk_rois, ParameterVector{input_rois, input_probs});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto topk_rois_output = backend->create_tensor(element::f32, output_shape);
|
||||
|
||||
std::vector<float> input_rois_data =
|
||||
{1.0f, 1.0f, 4.0f, 5.0f, 3.0f, 2.0f, 7.0f, 9.0f, 10.0f, 15.0f, 13.0f, 17.0f, 13.0f, 10.0f, 18.0f, 15.0f};
|
||||
std::vector<float> input_probs_data = {0.1f, 0.7f, 0.5f, 0.9f};
|
||||
std::vector<float> expected_result = {13.0f, 10.0f, 18.0f, 15.0f, 3.0f, 2.0f, 7.0f, 9.0f};
|
||||
|
||||
auto backend_input_rois_data = backend->create_tensor(element::f32, input_rois_shape);
|
||||
copy_data(backend_input_rois_data, input_rois_data);
|
||||
auto backend_input_probs_data = backend->create_tensor(element::f32, input_probs_shape);
|
||||
copy_data(backend_input_probs_data, input_probs_data);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call({topk_rois_output}, {backend_input_rois_data, backend_input_probs_data});
|
||||
|
||||
ASSERT_TRUE(test::all_close_f(read_vector<float>(topk_rois_output), expected_result));
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <string>
|
||||
|
||||
#include "engines_util/test_case.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_scalar_2_in_3) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
int axis = 0;
|
||||
Shape shape_r{3};
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({2});
|
||||
test_case.add_expected_output<int32_t>(shape_r, {0, 0, 1});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_scalar_1_in_3) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
int axis = 0;
|
||||
Shape shape_r{3};
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({1});
|
||||
test_case.add_expected_output<int32_t>(shape_r, {0, 1, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_scalar_0_in_3) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{3};
|
||||
int axis = 0;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({0});
|
||||
test_case.add_expected_output<int32_t>(shape_r, {1, 0, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_vector_0) {
|
||||
Shape shape_a{8};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{3, 8};
|
||||
int axis = 0;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({2, 1, 0, 0, 2, 2, 1, 0});
|
||||
test_case.add_expected_output<int32_t>(shape_r,
|
||||
{0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_vector_1) {
|
||||
Shape shape_a{8};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{8, 3};
|
||||
int axis = 1;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({2, 1, 0, 0, 2, 2, 1, 0});
|
||||
test_case.add_expected_output<int32_t>(shape_r,
|
||||
{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_vector_1_barely_oob) {
|
||||
Shape shape_a{8};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{8, 3};
|
||||
int axis = 1;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({2, 1, 0, 0, 3, 2, 1, 0});
|
||||
// elements 12, 13, 14 are zeroed as out of bound
|
||||
test_case.add_expected_output<int32_t>(shape_r,
|
||||
{0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_matrix_0) {
|
||||
Shape shape_a{3, 3};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{3, 3, 3};
|
||||
int axis = 0;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>({0, 1, 1, 2, 1, 0, 0, 2, 1});
|
||||
test_case.add_expected_output<int32_t>(shape_r, {1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1,
|
||||
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0});
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_vector_many_categories) {
|
||||
// Imagenet has roughly 20,000 categories
|
||||
constexpr uint32_t category_count = 20000;
|
||||
Shape shape_a{6};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{6, category_count};
|
||||
int axis = 1;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::i32, {}, {1});
|
||||
auto off_value = op::Constant::create(element::i32, {}, {0});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
vector<int32_t> input{0, 11, 101, 1001, 10001, static_cast<int32_t>(category_count - 1)};
|
||||
vector<int32_t> output(shape_size(shape_r), 0);
|
||||
for (size_t i = 0; i < input.size(); ++i) {
|
||||
output[i * category_count + input[i]] = 1;
|
||||
}
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>(input);
|
||||
test_case.add_expected_output<int32_t>(shape_r, output);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, one_hot_on_off_float) {
|
||||
Shape shape_a{3, 3};
|
||||
auto A = make_shared<op::Parameter>(element::i32, shape_a);
|
||||
Shape shape_r{3, 3, 3};
|
||||
int axis = 0;
|
||||
auto depth = op::Constant::create(element::i32, {}, {shape_r[axis]});
|
||||
auto on_value = op::Constant::create(element::f32, {}, {2.5});
|
||||
auto off_value = op::Constant::create(element::f32, {}, {0.5});
|
||||
auto r = make_shared<op::v1::OneHot>(A, depth, on_value, off_value, axis);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::i32, shape_a);
|
||||
copy_data(a, vector<int32_t>{0, 1, 1, 2, 1, 0, 0, 2, 1});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_EQ((vector<float>{2.5, 0.5, 0.5, 0.5, 0.5, 2.5, 2.5, 0.5, 0.5, 0.5, 2.5, 2.5, 0.5, 2.5,
|
||||
0.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 2.5, 0.5, 0.5, 0.5, 2.5, 0.5}),
|
||||
read_vector<float>(result));
|
||||
}
|
@ -1,603 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#include "engines_util/execute_tools.hpp"
|
||||
#include "engines_util/test_case.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/check.hpp"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/opsets/opset4.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, lstm_cell_zero_bias_default_attrs) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 4;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto C_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size});
|
||||
|
||||
const auto lstm_cell =
|
||||
make_shared<opset4::LSTMCell>(X,
|
||||
H_t,
|
||||
C_t,
|
||||
op::util::convert_lstm_node_format(W, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(R, op::util::LSTMWeightsFormat::IOFC),
|
||||
op::util::convert_lstm_node_format(B, op::util::LSTMWeightsFormat::IOFC),
|
||||
hidden_size);
|
||||
|
||||
auto ht_function = make_shared<Function>(OutputVector{lstm_cell->output(0)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ht_test_case = test::TestCase<TestEngine>(ht_function);
|
||||
|
||||
// X
|
||||
vector<float> in_X{0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f};
|
||||
// W
|
||||
vector<float> in_W{3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f};
|
||||
// R
|
||||
vector<float> in_R{0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f};
|
||||
// Ht
|
||||
vector<float> in_Ht{0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f};
|
||||
// Ct
|
||||
vector<float> in_Ct{0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f};
|
||||
// B
|
||||
vector<float> in_B(gates_count * hidden_size, 0.f);
|
||||
|
||||
ht_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ht_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.81457126f, 0.61109227f, 0.769522f, 0.52239674f, 0.4324641f, 0.63183f});
|
||||
ht_test_case.run();
|
||||
|
||||
auto ct_function = make_shared<Function>(OutputVector{lstm_cell->output(1)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ct_test_case = test::TestCase<TestEngine>(ct_function);
|
||||
ct_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ct_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{1.4444952f, 0.9635685f, 1.2875274f, 0.8053419f, 0.7184521f, 0.95803297f});
|
||||
ct_test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, lstm_cell_bias_default_attrs) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 4;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto C_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size});
|
||||
|
||||
const auto lstm_cell = make_shared<opset4::LSTMCell>(X, H_t, C_t, W, R, B, hidden_size);
|
||||
|
||||
auto ht_function = make_shared<Function>(OutputVector{lstm_cell->output(0)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ht_test_case = test::TestCase<TestEngine>(ht_function);
|
||||
|
||||
// X
|
||||
vector<float> in_X{0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f};
|
||||
// W
|
||||
vector<float> in_W{3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f};
|
||||
// R
|
||||
vector<float> in_R{0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f};
|
||||
// Ht
|
||||
vector<float> in_Ht{0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f};
|
||||
// Ct
|
||||
vector<float> in_Ct{0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f};
|
||||
// B
|
||||
vector<float> in_B{1.07393714f,
|
||||
1.15248052f,
|
||||
1.16671345f,
|
||||
0.21450312f,
|
||||
1.2380678f,
|
||||
1.51688835f,
|
||||
0.46718366f,
|
||||
0.91810346f,
|
||||
1.1274234f,
|
||||
0.51022074f,
|
||||
1.11389844f,
|
||||
0.74174305f};
|
||||
|
||||
ht_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ht_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.81014400720596313,
|
||||
0.76665538549423218,
|
||||
0.82509011030197144,
|
||||
0.6479143500328064,
|
||||
0.66586339473724365,
|
||||
0.74838578701019287});
|
||||
ht_test_case.run();
|
||||
|
||||
auto ct_function = make_shared<Function>(OutputVector{lstm_cell->output(1)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ct_test_case = test::TestCase<TestEngine>(ct_function);
|
||||
ct_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ct_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{1.6800162792205811,
|
||||
1.1150213479995728,
|
||||
1.4578367471694946,
|
||||
1.0649888515472412,
|
||||
0.93761754035949707,
|
||||
1.3659683465957642});
|
||||
ct_test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, lstm_cell_bias_clip) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 4;
|
||||
const float clip_threshold = 3.5f;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto C_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size});
|
||||
|
||||
const auto lstm_cell = make_shared<opset4::LSTMCell>(X,
|
||||
H_t,
|
||||
C_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
hidden_size,
|
||||
vector<string>{"sigmoid", "tanh", "tanh"},
|
||||
vector<float>{},
|
||||
vector<float>{},
|
||||
clip_threshold);
|
||||
auto ht_function = make_shared<Function>(OutputVector{lstm_cell->output(0)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ht_test_case = test::TestCase<TestEngine>(ht_function);
|
||||
|
||||
// X
|
||||
vector<float> in_X{0.81342685f, 0.84108883f, 0.8152282f, 0.46893653f, 0.0901856f, 0.37088776f};
|
||||
// W
|
||||
vector<float> in_W{3.3330739e-01f, 3.6229487e-04f, 4.6773660e-01f, 4.3046016e-01f, 7.3950343e-02f, 3.8063636e-01f,
|
||||
9.6921772e-01f, 9.6897459e-01f, 6.2964785e-01f, 3.1134409e-01f, 8.4709978e-01f, 9.4928098e-01f,
|
||||
6.1676943e-01f, 6.6020679e-01f, 1.9072217e-01f, 8.8032126e-02f, 4.0472135e-01f, 6.8342745e-01f,
|
||||
8.3432144e-01f, 4.4928190e-01f, 7.9524308e-01f, 5.3966165e-01f, 8.5936421e-01f, 8.3136767e-01f,
|
||||
5.5125546e-02f, 4.7791195e-01f, 3.5788772e-01f, 6.7507404e-01f, 2.1716513e-01f, 2.7473119e-01f,
|
||||
3.3999152e-02f, 9.6835363e-01f, 3.7581277e-01f, 2.4026000e-01f, 6.7418844e-01f, 3.4199652e-01f};
|
||||
// R
|
||||
vector<float> in_R{0.0987983f, 0.52032113f, 0.5848073f, 0.5356095f, 0.74497133f, 0.73260087f,
|
||||
0.1700787f, 0.45684233f, 0.1495722f, 0.42734373f, 0.4433832f, 0.25906256f,
|
||||
0.03854987f, 0.47480518f, 0.37215272f, 0.99890584f, 0.74019486f, 0.3518967f,
|
||||
0.6881257f, 0.8170279f, 0.54088944f, 0.81225616f, 0.14619833f, 0.42941234f,
|
||||
0.86843914f, 0.45967972f, 0.6237719f, 0.11074839f, 0.6029616f, 0.3149305f,
|
||||
0.46504205f, 0.5843412f, 0.8733427f, 0.7687243f, 0.07074859f, 0.39188156f};
|
||||
// Ht
|
||||
vector<float> in_Ht{0.77956f, 0.5331557f, 0.04297554f, 0.7962175f, 0.7635707f, 0.11989366f};
|
||||
// Ct
|
||||
vector<float> in_Ct{0.8488452f, 0.18851636f, 0.5020695f, 0.29716516f, 0.06740791f, 0.45384037f};
|
||||
// B
|
||||
vector<float> in_B{1.07393714f,
|
||||
1.15248052f,
|
||||
1.16671345f,
|
||||
0.21450312f,
|
||||
1.2380678f,
|
||||
1.51688835f,
|
||||
0.46718366f,
|
||||
0.91810346f,
|
||||
1.1274234f,
|
||||
0.51022074f,
|
||||
1.11389844f,
|
||||
0.74174305f};
|
||||
|
||||
ht_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ht_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.81014400720596313,
|
||||
0.76665538549423218,
|
||||
0.82387429475784302,
|
||||
0.6479143500328064,
|
||||
0.66586339473724365,
|
||||
0.74838578701019287});
|
||||
ht_test_case.run();
|
||||
|
||||
auto ct_function = make_shared<Function>(OutputVector{lstm_cell->output(1)}, ParameterVector{X, H_t, C_t, W, R, B});
|
||||
auto ct_test_case = test::TestCase<TestEngine>(ct_function);
|
||||
ct_test_case.add_multiple_inputs(vector<vector<float>>{in_X, in_Ht, in_Ct, in_W, in_R, in_B});
|
||||
ct_test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{1.6800162792205811,
|
||||
1.1150213479995728,
|
||||
1.4510968923568726,
|
||||
1.0649888515472412,
|
||||
0.93761754035949707,
|
||||
1.3659683465957642});
|
||||
ct_test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, rnn_cell_zero_bias_default_attrs) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{hidden_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{hidden_size});
|
||||
|
||||
const auto rnn_cell = make_shared<opset4::RNNCell>(X, H_t, W, R, B, hidden_size);
|
||||
auto function = make_shared<Function>(rnn_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f});
|
||||
// Ht
|
||||
test_case.add_input<float>({0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f});
|
||||
// W
|
||||
test_case.add_input<float>({0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f});
|
||||
// R
|
||||
test_case.add_input<float>({0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f});
|
||||
// B
|
||||
test_case.add_input<float>({0.0f, 0.0f, 0.0f});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.9408395f, 0.53823817f, 0.84270686f, 0.98932856f, 0.768665f, 0.90461975f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, rnn_cell_bias_clip) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{hidden_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{hidden_size});
|
||||
|
||||
const auto rnn_cell = make_shared<
|
||||
opset4::RNNCell>(X, H_t, W, R, B, hidden_size, vector<string>{"tanh"}, vector<float>{}, vector<float>{}, clip);
|
||||
auto function = make_shared<Function>(rnn_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f});
|
||||
// Ht
|
||||
test_case.add_input<float>({0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f});
|
||||
// W
|
||||
test_case.add_input<float>({0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f});
|
||||
// R
|
||||
test_case.add_input<float>({0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f});
|
||||
// B
|
||||
test_case.add_input<float>({1.0289404f, 1.6362579f, 0.4370661f});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.9922437f, 0.97749525f, 0.9312212f, 0.9937176f, 0.9901317f, 0.95906746f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, rnn_cell_sigmoid_activation_function) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
float clip = 2.88f;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{hidden_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{hidden_size});
|
||||
|
||||
const auto rnn_cell = make_shared<opset4::RNNCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
hidden_size,
|
||||
vector<string>{"sigmoid"},
|
||||
vector<float>{},
|
||||
vector<float>{},
|
||||
clip);
|
||||
auto function = make_shared<Function>(rnn_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.3432185f, 0.612268f, 0.20272376f, 0.9513413f, 0.30585995f, 0.7265472f});
|
||||
// Ht
|
||||
test_case.add_input<float>({0.12444675f, 0.52055854f, 0.46489045f, 0.4983964f, 0.7730452f, 0.28439692f});
|
||||
// W
|
||||
test_case.add_input<float>({0.41930267f,
|
||||
0.7872176f,
|
||||
0.89940447f,
|
||||
0.23659843f,
|
||||
0.24676207f,
|
||||
0.17101714f,
|
||||
0.3147149f,
|
||||
0.6555601f,
|
||||
0.4559603f});
|
||||
// R
|
||||
test_case.add_input<float>({0.8374871f,
|
||||
0.86660194f,
|
||||
0.82114047f,
|
||||
0.71549815f,
|
||||
0.18775631f,
|
||||
0.3182116f,
|
||||
0.25392973f,
|
||||
0.38301638f,
|
||||
0.85531586f});
|
||||
// B
|
||||
test_case.add_input<float>({1.0289404f, 1.6362579f, 0.4370661f});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.94126844f, 0.9036043f, 0.841243f, 0.9468489f, 0.934215f, 0.873708f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, gru_cell_bias_clip) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 3;
|
||||
float clip = 2.88f;
|
||||
bool linear_before_reset = false;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size});
|
||||
|
||||
const auto gru_cell = make_shared<opset4::GRUCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
hidden_size,
|
||||
vector<string>{"sigmoid", "tanh"},
|
||||
vector<float>{},
|
||||
vector<float>{},
|
||||
clip,
|
||||
linear_before_reset);
|
||||
auto function = make_shared<Function>(gru_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.52421564f, 0.78845507f, 0.9372873f, 0.59783894f, 0.18278378f, 0.2084126f});
|
||||
|
||||
// Ht
|
||||
test_case.add_input<float>({0.45738035f, 0.996877f, 0.82882977f, 0.47492632f, 0.88471466f, 0.57833236f});
|
||||
|
||||
// W
|
||||
test_case.add_input<float>({0.5815369f, 0.16559383f, 0.08464007f, 0.843122f, 0.73968244f, 0.11359601f,
|
||||
0.8295078f, 0.9240567f, 0.10007995f, 0.20573162f, 0.09002485f, 0.2839569f,
|
||||
0.3096991f, 0.5638341f, 0.5787327f, 0.84552664f, 0.16263747f, 0.7243242f,
|
||||
0.8049057f, 0.43966424f, 0.46294412f, 0.9833361f, 0.31369713f, 0.1719934f,
|
||||
0.4937093f, 0.6353004f, 0.77982515f});
|
||||
|
||||
// R
|
||||
test_case.add_input<float>({0.16510165f, 0.52435565f, 0.2788478f, 0.99427545f, 0.1623331f, 0.01389796f,
|
||||
0.99669236f, 0.53901845f, 0.8737506f, 0.9254788f, 0.21172932f, 0.11634306f,
|
||||
0.40111724f, 0.37497616f, 0.2903471f, 0.6796794f, 0.65131867f, 0.78163475f,
|
||||
0.12058706f, 0.45591718f, 0.791677f, 0.76497287f, 0.9895242f, 0.7845312f,
|
||||
0.51267904f, 0.49030215f, 0.08498167f});
|
||||
|
||||
// B (the sum of biases for W and R)
|
||||
test_case.add_input<float>({
|
||||
0.8286678f + 0.9175602f,
|
||||
0.9153158f + 0.14958014f,
|
||||
0.9581612f + 0.49230585f,
|
||||
0.6639213f + 0.63162816f,
|
||||
0.84239805f + 0.4161903f,
|
||||
0.5282445f + 0.22148274f,
|
||||
0.14153397f + 0.50496656f,
|
||||
0.22404431f + 0.34798595f,
|
||||
0.6549655f + 0.6699164f,
|
||||
});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.48588726f, 0.99670005f, 0.83759373f, 0.5023099f, 0.89410484f, 0.60011315f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, gru_cell_linear_before_reset) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 3;
|
||||
float clip = 2.88f;
|
||||
bool linear_before_reset = true;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{(gates_count + 1) * hidden_size});
|
||||
|
||||
const auto gru_cell = make_shared<opset4::GRUCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
hidden_size,
|
||||
vector<string>{"sigmoid", "tanh"},
|
||||
vector<float>{},
|
||||
vector<float>{},
|
||||
clip,
|
||||
linear_before_reset);
|
||||
auto function = make_shared<Function>(gru_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.12249453f, 0.6127907f, 0.5001741f, 0.5124603f, 0.04329684f, 0.023834f});
|
||||
// Ht
|
||||
test_case.add_input<float>({0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f});
|
||||
|
||||
// W
|
||||
test_case.add_input<float>({0.72259396f, 0.11561195f, 0.9457856f, 0.19037509f, 0.6964006f, 0.33459795f,
|
||||
0.5468904f, 0.85646594f, 0.5101311f, 0.9712257f, 0.3687071f, 0.60280246f,
|
||||
0.56943774f, 0.7475505f, 0.2490578f, 0.86977345f, 0.85542053f, 0.29660386f,
|
||||
0.49717373f, 0.7473479f, 0.53454477f, 0.15974349f, 0.5804805f, 0.14303213f,
|
||||
0.07514781f, 0.5865731f, 0.76409274f});
|
||||
// R
|
||||
test_case.add_input<float>({0.91382647f, 0.41527033f, 0.28040004f, 0.23601337f, 0.04471736f, 0.03888785f,
|
||||
0.06308217f, 0.44844428f, 0.29384327f, 0.49037653f, 0.50421673f, 0.7366393f,
|
||||
0.63143945f, 0.00277612f, 0.37198433f, 0.06966069f, 0.4613444f, 0.10999731f,
|
||||
0.78273284f, 0.21453214f, 0.10751773f, 0.18332677f, 0.1326976f, 0.9998985f,
|
||||
0.19263928f, 0.10979804f, 0.52575564f});
|
||||
|
||||
// B (the sum of biases for W and R for z and r gates, and separately for W and R for h gate)
|
||||
test_case.add_input<float>({0.61395123f, // 0.09875853f + 0.5151927f,
|
||||
1.08667738f, // 0.37801138f + 0.708666f,
|
||||
1.32600244f, // 0.7729636f + 0.55303884f,
|
||||
0.81917698f, // 0.78493553f + 0.03424145f,
|
||||
1.37736335f, // 0.5662702f + 0.81109315f,
|
||||
0.42931147f, // 0.12406381f + 0.30524766f,
|
||||
0.66729516f,
|
||||
0.7752771f,
|
||||
0.78819966f,
|
||||
0.6606634f,
|
||||
0.99040645f,
|
||||
0.21112025f});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.8709214f, 0.48411977f, 0.74495184f, 0.6074972f, 0.44572943f, 0.1467715f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
// Hard Sigmoid activation function is unsupprted with v3::GRUCell
|
||||
NGRAPH_TEST(${BACKEND_NAME}, gru_cell_hardsigmoid_activation_function) {
|
||||
const size_t batch_size = 2;
|
||||
const size_t input_size = 3;
|
||||
const size_t hidden_size = 3;
|
||||
const size_t gates_count = 3;
|
||||
float clip = 2.88f;
|
||||
bool linear_before_reset = true;
|
||||
|
||||
const auto X = make_shared<op::Parameter>(element::f32, Shape{batch_size, input_size});
|
||||
const auto W = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, input_size});
|
||||
const auto R = make_shared<op::Parameter>(element::f32, Shape{gates_count * hidden_size, hidden_size});
|
||||
const auto H_t = make_shared<op::Parameter>(element::f32, Shape{batch_size, hidden_size});
|
||||
const auto B = make_shared<op::Parameter>(element::f32, Shape{(gates_count + 1) * hidden_size});
|
||||
|
||||
const auto gru_cell = make_shared<opset4::GRUCell>(X,
|
||||
H_t,
|
||||
W,
|
||||
R,
|
||||
B,
|
||||
hidden_size,
|
||||
vector<string>{"hardsigmoid", "hardsigmoid"},
|
||||
vector<float>{1.8345f, 1.8345f},
|
||||
vector<float>{3.05f, 3.05f},
|
||||
clip,
|
||||
linear_before_reset);
|
||||
auto function = make_shared<Function>(gru_cell, ParameterVector{X, H_t, W, R, B});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
// X
|
||||
test_case.add_input<float>({0.12249453f, 0.6127907f, 0.5001741f, 0.5124603f, 0.04329684f, 0.023834f});
|
||||
|
||||
// Ht
|
||||
test_case.add_input<float>({0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f});
|
||||
|
||||
// W
|
||||
test_case.add_input<float>({0.72259396f, 0.11561195f, 0.9457856f, 0.19037509f, 0.6964006f, 0.33459795f,
|
||||
0.5468904f, 0.85646594f, 0.5101311f, 0.9712257f, 0.3687071f, 0.60280246f,
|
||||
0.56943774f, 0.7475505f, 0.2490578f, 0.86977345f, 0.85542053f, 0.29660386f,
|
||||
0.49717373f, 0.7473479f, 0.53454477f, 0.15974349f, 0.5804805f, 0.14303213f,
|
||||
0.07514781f, 0.5865731f, 0.76409274f});
|
||||
// R
|
||||
test_case.add_input<float>({0.91382647f, 0.41527033f, 0.28040004f, 0.23601337f, 0.04471736f, 0.03888785f,
|
||||
0.06308217f, 0.44844428f, 0.29384327f, 0.49037653f, 0.50421673f, 0.7366393f,
|
||||
0.63143945f, 0.00277612f, 0.37198433f, 0.06966069f, 0.4613444f, 0.10999731f,
|
||||
0.78273284f, 0.21453214f, 0.10751773f, 0.18332677f, 0.1326976f, 0.9998985f,
|
||||
0.19263928f, 0.10979804f, 0.52575564f});
|
||||
|
||||
// B (the sum of biases for W and R for z and r gates, and separately for W and R for h gate)
|
||||
test_case.add_input<float>({0.09875853f + 0.5151927f,
|
||||
0.37801138f + 0.708666f,
|
||||
0.7729636f + 0.55303884f,
|
||||
0.78493553f + 0.03424145f,
|
||||
0.5662702f + 0.81109315f,
|
||||
0.12406381f + 0.30524766f,
|
||||
0.66729516f,
|
||||
0.7752771f,
|
||||
0.78819966f,
|
||||
0.6606634f,
|
||||
0.99040645f,
|
||||
0.21112025f});
|
||||
|
||||
test_case.add_expected_output<float>(Shape{batch_size, hidden_size},
|
||||
{0.8598948f, 0.41189128f, 0.72824323f, 0.53940123f, 0.31485787f, 0.04053852f});
|
||||
|
||||
test_case.run();
|
||||
}
|
26
ngraph/test/visitors/op/ctc_greedy_decoder.cpp
Normal file
26
ngraph/test/visitors/op/ctc_greedy_decoder.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/opsets/opset1.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, ctc_greedy_decoder_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset1::CTCGreedyDecoder>();
|
||||
bool m_ctc_merge_repeated = false;
|
||||
auto data = make_shared<op::Parameter>(element::f32, Shape{3, 1, 3});
|
||||
auto masks = make_shared<op::Parameter>(element::i32, Shape{3, 1});
|
||||
auto decoder = make_shared<op::v0::CTCGreedyDecoder>(data, masks, m_ctc_merge_repeated);
|
||||
|
||||
NodeBuilder builder(decoder);
|
||||
auto g_decoder = ov::as_type_ptr<opset1::CTCGreedyDecoder>(builder.create());
|
||||
|
||||
EXPECT_EQ(g_decoder->get_ctc_merge_repeated(), decoder->get_ctc_merge_repeated());
|
||||
}
|
28
ngraph/test/visitors/op/ctc_greedy_decoder_seq_len.cpp
Normal file
28
ngraph/test/visitors/op/ctc_greedy_decoder_seq_len.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/opsets/opset1.hpp"
|
||||
#include "ngraph/opsets/opset6.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, ctc_greedy_decoder_seq_len_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset6::CTCGreedyDecoderSeqLen>();
|
||||
bool merge_repeated = false;
|
||||
auto data = make_shared<op::Parameter>(element::f32, Shape{1, 3, 3});
|
||||
auto seq_len = make_shared<op::Parameter>(element::i32, Shape{1});
|
||||
auto blank_index = op::Constant::create<int32_t>(element::i32, Shape{}, {2});
|
||||
auto decoder = make_shared<op::v6::CTCGreedyDecoderSeqLen>(data, seq_len, blank_index, merge_repeated);
|
||||
|
||||
NodeBuilder builder(decoder);
|
||||
auto g_decoder = ov::as_type_ptr<opset6::CTCGreedyDecoderSeqLen>(builder.create());
|
||||
|
||||
EXPECT_EQ(g_decoder->get_merge_repeated(), decoder->get_merge_repeated());
|
||||
}
|
27
ngraph/test/visitors/op/experimental_detectron_topkrois.cpp
Normal file
27
ngraph/test/visitors/op/experimental_detectron_topkrois.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/opsets/opset1.hpp"
|
||||
#include "ngraph/opsets/opset6.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, experimental_detectron_topkrois_op) {
|
||||
NodeBuilder::get_ops().register_factory<opset6::ExperimentalDetectronTopKROIs>();
|
||||
size_t num_rois = 1;
|
||||
auto input_rois = std::make_shared<op::Parameter>(element::f32, Shape{2, 4});
|
||||
auto input_probs = std::make_shared<op::Parameter>(element::f32, Shape{2});
|
||||
auto topkrois = std::make_shared<op::v6::ExperimentalDetectronTopKROIs>(input_rois, input_probs, num_rois);
|
||||
|
||||
NodeBuilder builder(topkrois);
|
||||
auto g_topkrois = ov::as_type_ptr<opset6::ExperimentalDetectronTopKROIs>(builder.create());
|
||||
|
||||
EXPECT_EQ(g_topkrois->get_max_rois(), topkrois->get_max_rois());
|
||||
}
|
Loading…
Reference in New Issue
Block a user