conv_to_binary_conv.hpp
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #pragma once
6 
7 #include <transformations_visibility.hpp>
8 #include <ngraph/pass/graph_rewrite.hpp>
9 
10 namespace ngraph {
11 namespace pass {
12 
13 class TRANSFORMATIONS_API ConvToBinaryConv;
14 
15 } // namespace pass
16 } // namespace ngraph
17 
18 /**
19  * @ingroup ie_transformation_common_api
20  * @brief This transformation converts Convolution to BinaryConvolution under following conditions:
21  * - first input to Convolution is a FakeQuantize with levels==2 with output low,high being either (0, 1) or (-1, 1)
22  * - second input (weights) is a constant with values -1 or 1
23  * The transformation also converts weights to binary Constant (with 'u1' type)
24  * For example, when output_low is equal to 0 and output_high is equal to 1, following graph
25  *
26  * .... .... out_low out_high
27  * | | | |
28  * +--------------------------+ +-------------------------------------+
29  * | FakeQuantize (levels==2) | | Constant |
30  * | (on activations) | | (weights containing -1 or 1 values) |
31  * +--------------------------+ +-------------------------------------+
32  * | |
33  * | |
34  * ----------------- -------------------
35  * | |
36  * v v
37  * +-------------+
38  * | Convolution |
39  * +-------------+
40  * |
41  * v
42  * is transformed to:
43  *
44  * .... .... out_low out_high
45  * | | | |
46  * +--------------------------+ +---------------------------------+
47  * | FakeQuantize (levels==2) | | Constant (with u1 type) |
48  * | (on activations) | | (with u1 type - binary weights) |
49  * +--------------------------+ +---------------------------------+
50  * | |
51  * | |
52  * ----------------- -------------------
53  * | |
54  * v v
55  * +-------------------+
56  * | BinaryConvolution |
57  * +-------------------+
58  * |
59  * v
60  * +------------+ +----------------------------------------------------+
61  * | | | Constant |
62  * | Add | <---| (weights from original graph, |
63  * | | | sum-reduced over [1,..., len(weights.shape)] axes |
64  * +------------+ +----------------------------------------------------+
65  * |
66  * v
67  * +------------+ +-----+
68  * | Multiply | <---| 0.5 |
69  * +------------+ +-----+
70  * |
71  * v
72  */
73 class ngraph::pass::ConvToBinaryConv : public ngraph::pass::MatcherPass {
74 public:
75  NGRAPH_RTTI_DECLARATION;
77 };
This transformation converts Convolution to BinaryConvolution under following conditions:
Definition: conv_to_binary_conv.hpp:73
ngraph namespace
Definition: add_fake_quantize_fusion.hpp:14