ONE - On-device Neural Engine
Loading...
Searching...
No Matches
caffe_op_creator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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#ifndef MIR_CAFFE_OP_CREATOR_H
18#define MIR_CAFFE_OP_CREATOR_H
19
20#include <set>
21#include <map>
22#include <vector>
23#include <memory>
24
25#include "mir/Graph.h"
26#include "mir/TensorVariant.h"
27#include "mir/Shape.h"
28
29#include "caffe/proto/caffe.pb.h"
30
31namespace mir_caffe
32{
33
35{
36public:
37 explicit CaffeOpCreator(mir::Graph *g) : _graph(g){};
38
39 std::vector<mir::Operation::Output *> convertInput(const caffe::LayerParameter &layer);
40
41 std::vector<mir::Operation::Output *>
42 convertConvolution(const caffe::LayerParameter &layer,
43 const std::vector<mir::Operation::Output *> &inputs);
44
45 std::vector<mir::Operation::Output *>
46 convertInnerProduct(const caffe::LayerParameter &layer,
47 const std::vector<mir::Operation::Output *> &inputs);
48
49 std::vector<mir::Operation::Output *>
50 convertConcat(const caffe::LayerParameter &layer,
51 const std::vector<mir::Operation::Output *> &inputs);
52
53 std::vector<mir::Operation::Output *>
54 convertPooling(const caffe::LayerParameter &layer,
55 const std::vector<mir::Operation::Output *> &inputs);
56
57 std::vector<mir::Operation::Output *>
58 convertSoftmax(const caffe::LayerParameter &layer,
59 const std::vector<mir::Operation::Output *> &inputs);
60
61 std::vector<mir::Operation::Output *>
62 convertReshape(const caffe::LayerParameter &layer,
63 const std::vector<mir::Operation::Output *> &inputs);
64
65 std::vector<mir::Operation::Output *>
66 convertReLU(const caffe::LayerParameter &layer,
67 const std::vector<mir::Operation::Output *> &inputs);
68
69 std::vector<mir::Operation::Output *>
70 convertScale(const caffe::LayerParameter &layer,
71 const std::vector<mir::Operation::Output *> &inputs);
72
73 std::vector<mir::Operation::Output *>
74 convertBatchNorm(const caffe::LayerParameter &layer,
75 const std::vector<mir::Operation::Output *> &inputs);
76
77 std::vector<mir::Operation::Output *>
78 convertDropout(const caffe::LayerParameter &layer,
79 const std::vector<mir::Operation::Output *> &inputs);
80
81 std::vector<mir::Operation::Output *>
82 convertDeconvolution(const caffe::LayerParameter &layer,
83 const std::vector<mir::Operation::Output *> &inputs);
84
85 std::vector<mir::Operation::Output *>
86 convertELU(const caffe::LayerParameter &layer,
87 const std::vector<mir::Operation::Output *> &inputs);
88
89 std::vector<mir::Operation::Output *>
90 convertEmbed(const caffe::LayerParameter &layer,
91 const std::vector<mir::Operation::Output *> &inputs);
92
93 std::vector<mir::Operation::Output *>
94 convertSigmoid(const caffe::LayerParameter &layer,
95 const std::vector<mir::Operation::Output *> &inputs);
96
97 std::vector<mir::Operation::Output *>
98 convertTanH(const caffe::LayerParameter &layer,
99 const std::vector<mir::Operation::Output *> &inputs);
100
101 std::vector<mir::Operation::Output *>
102 convertEltwise(const caffe::LayerParameter &layer,
103 const std::vector<mir::Operation::Output *> &inputs);
104
105 std::vector<mir::Operation::Output *>
106 convertSplit(const caffe::LayerParameter &layer,
107 const std::vector<mir::Operation::Output *> &inputs);
108
109 std::vector<mir::Operation::Output *>
110 convertLSTM(const caffe::LayerParameter &layer,
111 const std::vector<mir::Operation::Output *> &inputs);
112
113 void checkConvolution(const caffe::LayerParameter &layer,
114 std::set<std::string> &problems_ops_set);
115
116 void checkPooling(const caffe::LayerParameter &layer, std::set<std::string> &problems_ops_set);
117
118 void checkReshape(const caffe::LayerParameter &layer, std::set<std::string> &problems_ops_set);
119
120 void checkBatchNorm(const caffe::LayerParameter &layer, std::set<std::string> &problems_ops_set);
121
122 void checkLSTM(const caffe::LayerParameter &layer, std::set<std::string> &problems_ops_set);
123
124private:
125 mir::Graph *_graph = nullptr;
126
127 std::vector<mir::Operation::Output *> createSplit(mir::Operation::Output *arg, int32_t num_parts,
128 int32_t axis);
129
131 mir::Operation::Output *weights, int32_t axis);
132
133 mir::TensorVariant convertBlob(const caffe::BlobProto &blob);
134
135 template <typename OpType, typename... Types> mir::Operation *createOp(Types &&...args);
136};
137
138template <typename OpType, typename... Types>
139mir::Operation *CaffeOpCreator::createOp(Types &&...args)
140{
141 return _graph->create<OpType>(std::forward<Types>(args)...);
142}
143
144} // namespace mir_caffe
145
146#endif // MIR_CAFFE_OP_CREATOR_H
Operation * create(Args &&...args)
Definition Graph.h:41
Represents an output of a node.
Definition Operation.h:60
std::vector< mir::Operation::Output * > convertReLU(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertSplit(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
void checkBatchNorm(const caffe::LayerParameter &layer, std::set< std::string > &problems_ops_set)
std::vector< mir::Operation::Output * > convertInput(const caffe::LayerParameter &layer)
void checkReshape(const caffe::LayerParameter &layer, std::set< std::string > &problems_ops_set)
std::vector< mir::Operation::Output * > convertDeconvolution(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertLSTM(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertEltwise(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertELU(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertConvolution(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertPooling(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertInnerProduct(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertBatchNorm(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertSigmoid(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
void checkPooling(const caffe::LayerParameter &layer, std::set< std::string > &problems_ops_set)
void checkLSTM(const caffe::LayerParameter &layer, std::set< std::string > &problems_ops_set)
std::vector< mir::Operation::Output * > convertScale(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertReshape(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
Converts Caffe Reshape layer to Model IR Reshape operation.
std::vector< mir::Operation::Output * > convertSoftmax(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertDropout(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
void checkConvolution(const caffe::LayerParameter &layer, std::set< std::string > &problems_ops_set)
std::vector< mir::Operation::Output * > convertTanH(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertEmbed(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)
std::vector< mir::Operation::Output * > convertConcat(const caffe::LayerParameter &layer, const std::vector< mir::Operation::Output * > &inputs)