• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/delegates/gpu/common/transformations/model_transformations.h"
17 
18 #include <memory>
19 
20 #include "tensorflow/lite/delegates/gpu/common/custom_transformations.h"
21 #include "tensorflow/lite/delegates/gpu/common/model_transformer.h"
22 #include "tensorflow/lite/delegates/gpu/common/transformations/add_quant_adjustments.h"
23 #include "tensorflow/lite/delegates/gpu/common/transformations/fuse_add_to_conv.h"
24 #include "tensorflow/lite/delegates/gpu/common/transformations/fuse_mul_to_conv.h"
25 #include "tensorflow/lite/delegates/gpu/common/transformations/make_fully_connected.h"
26 #include "tensorflow/lite/delegates/gpu/common/transformations/make_padding.h"
27 #include "tensorflow/lite/delegates/gpu/common/transformations/merge_densify.h"
28 #include "tensorflow/lite/delegates/gpu/common/transformations/merge_padding_with.h"
29 #include "tensorflow/lite/delegates/gpu/common/transformations/remove_noop.h"
30 
31 namespace tflite {
32 namespace gpu {
33 
34 namespace {
35 
ApplyGeneralTransformations(ModelTransformer * transformer)36 bool ApplyGeneralTransformations(ModelTransformer* transformer) {
37   // whenever any of these transforms return false, that means that a graph
38   // is in the broken state and processing should not continue.
39   return transformer->Apply("add_quant_adjustments",
40                             NewAddQuantAdjustments().get()) &&
41          transformer->Apply("remove_degenerate_upsampling",
42                             NewRemoveDegenerateUpsampling().get()) &&
43          transformer->Apply("remove_single_input_add",
44                             NewRemoveSingleInputAdd().get()) &&
45          transformer->Apply("remove_single_input_concat",
46                             NewRemoveSingleInputConcat().get()) &&
47          transformer->Apply("remove_identity_reshape",
48                             NewRemoveIdentityReshape().get()) &&
49          transformer->Apply("remove_identity_strided_slice",
50                             NewRemoveIdentityStridedSlice().get()) &&
51          transformer->Apply("make_padding_from_concat",
52                             NewMakePaddingFromConcat().get()) &&
53          transformer->Apply("make_fully_connected_from_convolution",
54                             NewMakeFullyConnectedFromConvolution().get()) &&
55          transformer->Apply("merge_densify", NewMergeDensify().get()) &&
56          transformer->Apply("merge_padding_with_convolution",
57                             NewMergePaddingWithConvolution2D().get()) &&
58          transformer->Apply("merge_padding_with_pooling",
59                             NewMergePaddingWithPooling().get()) &&
60          transformer->Apply("merge_padding_with_depthwise_convolution",
61                             NewMergePaddingWithDepthwiseConvolution().get()) &&
62          transformer->Apply("merge_convolution_with_mul",
63                             NewMergeConvolutionWithMul().get()) &&
64          transformer->Apply("merge_convolution_with_add",
65                             NewMergeConvolutionWithAdd().get()) &&
66          transformer->Apply("merge_add_with_convolution",
67                             NewMergeAddWithConvolution().get()) &&
68          transformer->Apply("merge_mul_with_convolution",
69                             NewMergeMulWithConvolution().get());
70 }
71 
72 }  // namespace
73 
ApplyModelTransformations(ModelTransformer * transformer)74 bool ApplyModelTransformations(ModelTransformer* transformer) {
75   return ApplyCustomTransformations(transformer) &&
76          ApplyGeneralTransformations(transformer);
77 }
78 
79 }  // namespace gpu
80 }  // namespace tflite
81