Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / cnn_network / cnn_layer_validation_tests.cpp
1 /*
2 * INTEL CONFIDENTIAL
3 * Copyright (C) 2018-2019 Intel Corporation.
4 *
5 * The source code contained or described herein and all documents
6 * related to the source code ("Material") are owned by Intel Corporation
7 * or its suppliers or licensors. Title to the Material remains with
8 * Intel Corporation or its suppliers and licensors. The Material may
9 * contain trade secrets and proprietary and confidential information
10 * of Intel Corporation and its suppliers and licensors, and is protected
11 * by worldwide copyright and trade secret laws and treaty provisions.
12 * No part of the Material may be used, copied, reproduced, modified,
13 * published, uploaded, posted, transmitted, distributed, or disclosed
14 * in any way without Intel's prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other
17 * intellectual property right is granted to or conferred upon you by
18 * disclosure or delivery of the Materials, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Include any supplier copyright notices as supplier requires Intel to use.
23 *
24 * Include supplier trademarks or logos as supplier requires Intel to use,
25 * preceded by an asterisk. An asterisked footnote can be added as follows:
26 * *Third Party trademarks are the property of their respective owners.
27 *
28 * Unless otherwise agreed by Intel in writing, you may not remove or alter
29 * this notice or any other notice embedded in Materials by Intel or Intel's
30 * suppliers or licensors in any way.
31 */
32 #include <gtest/gtest.h>
33 #include <xml_net_builder.hpp>
34 #include <inference_engine/cnn_network_impl.hpp>
35 #include <inference_engine/ie_format_parser.h>
36 #include <inference_engine/ie_layer_validators.hpp>
37 #include <xml_helper.hpp>
38 #include <../shape_infer/built_in_shape_infer_general_test.hpp>
39 #include <memory>
40 #include <../include/ie_data.h>
41
42 #include "layer_builder.h"
43 #include "shapes.h"
44 using namespace InferenceEngine;
45 using namespace InferenceEngine::details;
46
47 TEST_P(CNNLayerValidationTests, checkValidParams) {
48
49     assertThat(type)->setParams(valid_params);
50     auto layer = getLayer();
51     LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(type);
52
53     ASSERT_NO_THROW(validator->parseParams(layer.get()));
54     ASSERT_NO_THROW(validator->checkParams(layer.get()));
55 }
56
57 TEST_P(CNNLayerValidationTests, checkInvalidParams) {
58
59     assertThat(type);
60     int numberOfParams = getNumOfParams();
61     LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(type);
62     auto layer_ = getLayer();
63     for (int i = 0; i < numberOfParams; ++i) {
64         layer->setParams(!valid_params);
65         ASSERT_THROW(validator->parseParams(layer_.get()), InferenceEngineException);
66         ASSERT_THROW(validator->checkParams(layer_.get()), InferenceEngineException);
67     }
68 }
69
70 TEST_P(CNNLayerValidationTests, checkInvalidInputShapes) {
71     LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(type);
72     std::vector<DataPtr> spData;
73     assertThat(type)->setShapes(spData, !valid_input);
74
75     auto layer_ = getLayer();
76     InOutDims shapes;
77     InferenceEngine::details::getInOutShapes(layer_.get(), shapes);
78     ASSERT_THROW(validator->checkShapes(layer_.get(), shapes.inDims), InferenceEngineException);
79 }
80
81 TEST_P(CNNLayerValidationTests, checkValidShapes) {
82
83     std::vector<DataPtr> spData;
84     assertThat(type)->setShapes(spData, valid_input);
85     auto layer = getLayer();
86     LayerValidator::Ptr validator = LayerValidators::getInstance()->getValidator(type);
87     InOutDims shapes;
88     InferenceEngine::details::getInOutShapes(layer.get(), shapes);
89     ASSERT_NO_THROW(validator->checkShapes(layer.get(), shapes.inDims));
90 }
91
92 INSTANTIATE_TEST_CASE_P(
93         InstantiationName, CNNLayerValidationTests,
94         ::testing::Values(
95                 "Convolution"
96                 ,"Deconvolution"
97                 ,"DetectionOutput"
98         )
99 );