Skip to content

Commit c9749ce

Browse files
Clean-up files in tests helpers (#1173)
1 parent acaab88 commit c9749ce

File tree

9 files changed

+256
-291
lines changed

9 files changed

+256
-291
lines changed

inference-engine/tests_deprecated/functional/mkldnn/shared_tests_instance/network_tests/network_test.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@
2323

2424
TEST_P(ModelTransformationsTest, LPT) {}
2525

26+
static void checkLayerInputPrecision(const ICNNNetwork& network, const std::string& layerName, Precision expectedPrecision, int inputIndex = -1) {
27+
CNNLayerPtr layer = getLayer(network, layerName);
28+
if (layer == nullptr) {
29+
THROW_IE_EXCEPTION << "layer '" << layerName << "' was not found";
30+
}
31+
for (size_t index = 0ul; index < layer->insData.size(); ++index) {
32+
if ((inputIndex != -1) && (index != inputIndex)) {
33+
continue;
34+
}
35+
36+
const DataWeakPtr weakData = layer->insData[index];
37+
ASSERT_EQ(expectedPrecision, weakData.lock()->getPrecision()) << " unexpected precision " << weakData.lock()->getPrecision() << " for layer " << layerName;
38+
}
39+
}
40+
2641
ModelParams getModelParams(const std::string modelName) {
2742
std::map<std::string, ModelParams> modelParams = {
2843
{
@@ -68,7 +83,7 @@ std::map<std::string, ModelParams> modelParams = {
6883
for (const std::pair<std::string, std::string> item : fakeQuantizeAndConcolutionItems) {
6984
TestsCommonFunc::checkLayerOuputPrecision(*usedNetwork, item.first, Precision::U8);
7085
if (!item.second.empty()) {
71-
TestsCommonFunc::checkLayerInputPrecision(*usedNetwork, item.second, Precision::U8, 0);
86+
checkLayerInputPrecision(*usedNetwork, item.second, Precision::U8, 0);
7287
}
7388
}
7489
}

inference-engine/tests_deprecated/functional/shared_tests/single_layer_tests/bin_conv_tests.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ class BinaryConvolutionOnlyTest : public TestsCommon,
9090

9191
protected:
9292

93+
static void fill_data_bin(float *data, size_t size) {
94+
for (size_t i = 0; i < size; i++) {
95+
data[i] = sinf((float)i) > 0.f ? 1.f : -1.f;
96+
}
97+
}
98+
99+
static void fill_data_bin_packed(int8_t *data, size_t size) {
100+
int nbits = 8;
101+
for (size_t i = 0; i < div_up(size, nbits); i++) {
102+
data[i] = static_cast<int8_t>(i % 255);
103+
}
104+
}
105+
93106
size_t calculateOutDim(size_t in_dim, size_t kernel, size_t stride, size_t pad_begin) {
94107
return (in_dim + 2lu * pad_begin - kernel) / stride + 1lu;
95108
}

inference-engine/tests_deprecated/functional/shared_tests/transformations/single_layer_transformations_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,35 @@ void SingleLayerTransformationsTest::compareInDetails(
181181
}
182182
}
183183

184+
static void relative_compare(
185+
const float* res,
186+
const float* ref,
187+
size_t size,
188+
float max_diff = 0.01f,
189+
const std::string assertDetails = "",
190+
float zero_diff = 1e-7f) {
191+
for (size_t i = 0lu; i < size; i++) {
192+
if (std::isnan(res[i]) && std::isnan(ref[i])) {
193+
continue;
194+
}
195+
196+
if ((ref[i] == 0.f) || (res[i] == 0.f)) {
197+
const float diff = fabs(res[i] - ref[i]);
198+
ASSERT_TRUE(diff < zero_diff) <<
199+
"\nAbsolute comparison of values ref: " << ref[i] << " and res: " << res[i] <<
200+
", diff: " << diff <<
201+
", index: " << i << "\n" << assertDetails;
202+
} else {
203+
const float diff = fabs((res[i] - ref[i]) / (std::max)(ref[i], res[i]));
204+
ASSERT_LT(diff, max_diff) <<
205+
"\nRelative comparison of values ref: " << ref[i] << " and res: " << res[i] <<
206+
", diff: " << diff <<
207+
", max_diff: " << max_diff <<
208+
", index: " << i << "\n" << assertDetails;
209+
}
210+
}
211+
}
212+
184213
void SingleLayerTransformationsTest::SetUp() {
185214
try {
186215
const SingleLayerTransformationsTestParams p = ::testing::WithParamInterface<SingleLayerTransformationsTestParams>::GetParam();

inference-engine/tests_deprecated/helpers/single_layer_common.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#endif
3232

3333
#define REPLACE_WITH_NUM(SRC, PATTERN, NUM) REPLACE_WITH_STR(SRC, PATTERN, to_string_c_locale(NUM))
34+
3435
#define REPLACE_WITH_NUM_VECTOR(SRC, PATTERN, NUMS) \
3536
{ std::string result; \
3637
if (NUMS.size() > 0u) { \
@@ -40,6 +41,7 @@
4041
} \
4142
} \
4243
REPLACE_WITH_STR(SRC, PATTERN, result); }
44+
4345
#define REPLACE_WITH_NUM_VECTOR_REVERSE(SRC, PATTERN, NUMS) \
4446
{ std::string result; \
4547
auto nums_size = NUMS.size(); \
@@ -50,6 +52,7 @@
5052
} \
5153
} \
5254
REPLACE_WITH_STR(SRC, PATTERN, result); }
55+
5356
#define REMOVE_LINE(SRC, PATTERN) REPLACE_WITH_STR(SRC, PATTERN, "")
5457

5558
#define PRETTY_PARAM(name, type) \
@@ -67,14 +70,6 @@
6770
*os << #name ": " << ::testing::PrintToString((name::param_type)(param)); \
6871
}
6972

70-
struct MapStrStr {
71-
std::map<std::string, std::string> data{};
72-
73-
explicit MapStrStr(std::map<std::string, std::string> _data) : data(std::move(_data)) {}
74-
75-
MapStrStr() = default;
76-
};
77-
7873
template<int Version = 3>
7974
inline InferenceEngine::CNNNetwork
8075
buildSingleLayerNetworkCommon(const std::string &layerType,

inference-engine/tests_deprecated/helpers/tests_common.cpp

Lines changed: 64 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -72,121 +72,73 @@ void TestsCommon::TearDown() {
7272
InferenceEngine::ExecutorManager::getInstance()->clear();
7373
}
7474

75-
IE_SUPPRESS_DEPRECATED_START
76-
77-
class BaseTestCreator {
78-
protected:
79-
std::string _type;
80-
public:
81-
explicit BaseTestCreator(const std::string& type) : _type(type) {}
82-
virtual ~BaseTestCreator() = default;
83-
84-
virtual InferenceEngine::CNNLayerPtr create(const std::string& type) = 0;
85-
86-
virtual bool shouldCreate(const std::string& type) = 0;
87-
};
88-
89-
template<class LT>
90-
class LayerTestCreator : public BaseTestCreator {
91-
public:
92-
explicit LayerTestCreator(const std::string& type) : BaseTestCreator(type) {}
93-
94-
InferenceEngine::CNNLayerPtr create(const std::string& type) override {
95-
InferenceEngine::LayerParams params;
96-
params.type = type;
97-
return std::make_shared<LT>(params);
75+
/**
76+
* @brief Copies a 8-bit RGB image to the blob.
77+
*
78+
* Throws an exception in case of dimensions or input size mismatch
79+
*
80+
* @tparam data_t Type of the target blob
81+
* @param RGB8 8-bit RGB image
82+
* @param RGB8_size Size of the image
83+
* @param blob Target blob to write image to
84+
*/
85+
template <typename data_t>
86+
void copyFromRGB8(uint8_t* RGB8, size_t RGB8_size, InferenceEngine::TBlob<data_t>* blob) {
87+
InferenceEngine::SizeVector dims = blob->getTensorDesc().getDims();
88+
if (4 != dims.size())
89+
THROW_IE_EXCEPTION << "Cannot write data to input blob! Blob has incorrect dimensions size " << dims.size();
90+
size_t num_channels = dims[1]; // because RGB
91+
size_t num_images = dims[0];
92+
size_t w = dims[3];
93+
size_t h = dims[2];
94+
size_t nPixels = w * h;
95+
96+
if (RGB8_size != w * h * num_channels * num_images)
97+
THROW_IE_EXCEPTION << "input pixels mismatch, expecting " << w * h * num_channels * num_images
98+
<< " bytes, got: " << RGB8_size;
99+
100+
std::vector<data_t*> dataArray;
101+
for (unsigned int n = 0; n < num_images; n++) {
102+
for (unsigned int i = 0; i < num_channels; i++) {
103+
if (!n && !i && dataArray.empty()) {
104+
dataArray.push_back(blob->data());
105+
} else {
106+
dataArray.push_back(dataArray.at(n * num_channels + i - 1) + nPixels);
107+
}
108+
}
98109
}
99-
100-
bool shouldCreate(const std::string& type) override {
101-
return type == _type;
110+
for (size_t n = 0; n < num_images; n++) {
111+
size_t n_num_channels = n * num_channels;
112+
size_t n_num_channels_nPixels = n_num_channels * nPixels;
113+
for (size_t i = 0; i < nPixels; i++) {
114+
size_t i_num_channels = i * num_channels + n_num_channels_nPixels;
115+
for (size_t j = 0; j < num_channels; j++) {
116+
dataArray.at(n_num_channels + j)[i] = RGB8[i_num_channels + j];
117+
}
118+
}
102119
}
103-
};
104-
105-
static std::vector<std::shared_ptr<BaseTestCreator>>& getCreators() {
106-
// there should be unique_ptr but it cant be used with initializer lists
107-
static std::vector<std::shared_ptr<BaseTestCreator> > creators = {
108-
std::make_shared<LayerTestCreator<InferenceEngine::PowerLayer>>("Power"),
109-
std::make_shared<LayerTestCreator<InferenceEngine::ConvolutionLayer>>("Convolution"),
110-
std::make_shared<LayerTestCreator<InferenceEngine::DeconvolutionLayer>>("Deconvolution"),
111-
std::make_shared<LayerTestCreator<InferenceEngine::PoolingLayer>>("Pooling"),
112-
std::make_shared<LayerTestCreator<InferenceEngine::FullyConnectedLayer>>("InnerProduct"),
113-
std::make_shared<LayerTestCreator<InferenceEngine::FullyConnectedLayer>>("FullyConnected"),
114-
std::make_shared<LayerTestCreator<InferenceEngine::NormLayer>>("LRN"),
115-
std::make_shared<LayerTestCreator<InferenceEngine::NormLayer>>("Norm"),
116-
std::make_shared<LayerTestCreator<InferenceEngine::SoftMaxLayer>>("Softmax"),
117-
std::make_shared<LayerTestCreator<InferenceEngine::SoftMaxLayer>>("LogSoftMax"),
118-
std::make_shared<LayerTestCreator<InferenceEngine::GRNLayer>>("GRN"),
119-
std::make_shared<LayerTestCreator<InferenceEngine::MVNLayer>>("MVN"),
120-
std::make_shared<LayerTestCreator<InferenceEngine::ReLULayer>>("ReLU"),
121-
std::make_shared<LayerTestCreator<InferenceEngine::ClampLayer>>("Clamp"),
122-
std::make_shared<LayerTestCreator<InferenceEngine::SplitLayer>>("Split"),
123-
std::make_shared<LayerTestCreator<InferenceEngine::SplitLayer>>("Slice"),
124-
std::make_shared<LayerTestCreator<InferenceEngine::ConcatLayer>>("Concat"),
125-
std::make_shared<LayerTestCreator<InferenceEngine::EltwiseLayer>>("Eltwise"),
126-
std::make_shared<LayerTestCreator<InferenceEngine::ScaleShiftLayer>>("ScaleShift"),
127-
std::make_shared<LayerTestCreator<InferenceEngine::PReLULayer>>("PReLU"),
128-
std::make_shared<LayerTestCreator<InferenceEngine::CropLayer>>("Crop"),
129-
std::make_shared<LayerTestCreator<InferenceEngine::ReshapeLayer>>("Reshape"),
130-
std::make_shared<LayerTestCreator<InferenceEngine::TileLayer>>("Tile"),
131-
std::make_shared<LayerTestCreator<InferenceEngine::BatchNormalizationLayer>>("BatchNormalization"),
132-
std::make_shared<LayerTestCreator<InferenceEngine::GemmLayer>>("Gemm"),
133-
std::make_shared<LayerTestCreator<InferenceEngine::PadLayer>>("Pad"),
134-
std::make_shared<LayerTestCreator<InferenceEngine::GatherLayer>>("Gather"),
135-
std::make_shared<LayerTestCreator<InferenceEngine::StridedSliceLayer>>("StridedSlice"),
136-
std::make_shared<LayerTestCreator<InferenceEngine::ShuffleChannelsLayer>>("ShuffleChannels"),
137-
std::make_shared<LayerTestCreator<InferenceEngine::DepthToSpaceLayer>>("DepthToSpace"),
138-
std::make_shared<LayerTestCreator<InferenceEngine::ReverseSequenceLayer>>("ReverseSequence"),
139-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Abs"),
140-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Acos"),
141-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Acosh"),
142-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Asin"),
143-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Asinh"),
144-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Atan"),
145-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Atanh"),
146-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Ceil"),
147-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Cos"),
148-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Cosh"),
149-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Erf"),
150-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Floor"),
151-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("HardSigmoid"),
152-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Log"),
153-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Exp"),
154-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Reciprocal"),
155-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Selu"),
156-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Sign"),
157-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Sin"),
158-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Sinh"),
159-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Softplus"),
160-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Softsign"),
161-
std::make_shared<LayerTestCreator<InferenceEngine::MathLayer>>("Tan"),
162-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceAnd"),
163-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceL1"),
164-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceL2"),
165-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceLogSum"),
166-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceLogSumExp"),
167-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceMax"),
168-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceMean"),
169-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceMin"),
170-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceOr"),
171-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceProd"),
172-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceSum"),
173-
std::make_shared<LayerTestCreator<InferenceEngine::ReduceLayer>>("ReduceSumSquare"),
174-
std::make_shared<LayerTestCreator<InferenceEngine::TopKLayer>>("TopK"),
175-
std::make_shared<LayerTestCreator<InferenceEngine::NonMaxSuppressionLayer>>("NonMaxSuppression"),
176-
std::make_shared<LayerTestCreator<InferenceEngine::ScatterUpdateLayer>>("ScatterUpdate"),
177-
std::make_shared<LayerTestCreator<InferenceEngine::ScatterElementsUpdateLayer>>("ScatterElementsUpdate")
178-
};
179-
return creators;
180120
}
181121

182-
InferenceEngine::CNNLayer::Ptr TestsCommon::createLayer(const std::string& type) {
183-
for (auto& creator : getCreators()) {
184-
if (!creator->shouldCreate(type))
185-
continue;
186-
return creator->create(type);
187-
}
188-
static LayerTestCreator<InferenceEngine::GenericLayer> genericCreator("");
189-
return genericCreator.create(type);
122+
/**
123+
* @brief Splits the RGB channels to either I16 Blob or float blob.
124+
*
125+
* The image buffer is assumed to be packed with no support for strides.
126+
*
127+
* @param imgBufRGB8 Packed 24bit RGB image (3 bytes per pixel: R-G-B)
128+
* @param lengthbytesSize Size in bytes of the RGB image. It is equal to amount of pixels times 3 (number of channels)
129+
* @param input Blob to contain the split image (to 3 channels)
130+
*/
131+
void ConvertImageToInput(unsigned char* imgBufRGB8, size_t lengthbytesSize, InferenceEngine::Blob& input) {
132+
InferenceEngine::TBlob<float>* float_input = dynamic_cast<InferenceEngine::TBlob<float>*>(&input);
133+
if (float_input != nullptr)
134+
copyFromRGB8(imgBufRGB8, lengthbytesSize, float_input);
135+
136+
InferenceEngine::TBlob<short>* short_input = dynamic_cast<InferenceEngine::TBlob<short>*>(&input);
137+
if (short_input != nullptr)
138+
copyFromRGB8(imgBufRGB8, lengthbytesSize, short_input);
139+
140+
InferenceEngine::TBlob<uint8_t>* byte_input = dynamic_cast<InferenceEngine::TBlob<uint8_t>*>(&input);
141+
if (byte_input != nullptr)
142+
copyFromRGB8(imgBufRGB8, lengthbytesSize, byte_input);
190143
}
191144

192-
IE_SUPPRESS_DEPRECATED_END

0 commit comments

Comments
 (0)