Imported Upstream version 1.4.0
[platform/core/ml/nnfw.git] / compiler / mir-onnx-importer / Op / Dropout.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "Dropout.h"
18
19 #include "AttributeHelpers.h"
20
21 namespace mir_onnx
22 {
23
24 void convertDropoutV1(const onnx::NodeProto &onnx_node, ConverterContext *context)
25 {
26   // consumed_inputs attribute not used
27   convertDropoutV6(onnx_node, context);
28 }
29
30 void convertDropoutV6(const onnx::NodeProto &onnx_node, ConverterContext *context)
31 {
32   const auto is_test = getAttributeValue<std::int64_t>(onnx_node, "is_test", 0);
33   if (is_test == 0)
34     throw std::runtime_error("Not supported is_test attribute!");
35
36   convertDropoutV10(onnx_node, context);
37 }
38
39 void convertDropoutV7(const onnx::NodeProto &onnx_node, ConverterContext *context)
40 {
41   convertDropoutV10(onnx_node, context);
42 }
43
44 void convertDropoutV10(const onnx::NodeProto &onnx_node, ConverterContext *context)
45 {
46   std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
47
48   // ratio attribute not used
49
50   // This is a no-op in inference mode.
51   context->setNodeOutputs(onnx_node, {inputs[0]});
52 }
53
54 } // namespace mir_onnx