forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuantizedConv2DTf.cpp
More file actions
86 lines (71 loc) · 2.46 KB
/
Copy pathQuantizedConv2DTf.cpp
File metadata and controls
86 lines (71 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// QuantizedConv2DTf.cpp
// MNNConverter
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include <string.h>
#include "TfUtils.hpp"
#include "tfOpConverter.hpp"
#include "graph.pb.h"
DECLARE_OP_CONVERTER(QuantizedConv2DTf);
MNN::OpType QuantizedConv2DTf::opType() {
return MNN::OpType_TfQuantizedConv2D;
}
MNN::OpParameter QuantizedConv2DTf::type() {
return MNN::OpParameter_TfQuantizedConv2D;
}
void QuantizedConv2DTf::run(MNN::OpT *dstOp, TmpNode *srcNode, TmpGraph *tempGraph) {
auto TfQuantizedConv2D = new MNN::TfQuantizedConv2DT;
TmpNode *weightNode = tempGraph->_getTmpNode(srcNode->inEdges[1]);
tensorflow::AttrValue value;
int kh = 1;
int kw = 1;
int num_input = 1;
int num_output = 1;
if (find_attr_value(weightNode->tfNode, "value", value)) {
const tensorflow::TensorProto &weightTensor = value.tensor();
const tensorflow::TensorShapeProto &shape = weightTensor.tensor_shape();
CHECK(shape.dim_size() == 4) << "Weight Shape Wrong!";
kh = shape.dim(0).size();
kw = shape.dim(1).size();
num_input = shape.dim(2).size();
num_output = shape.dim(3).size();
}
TfQuantizedConv2D->common = std::unique_ptr<MNN::Convolution2DCommonT>(new MNN::Convolution2DCommonT);
auto &common = TfQuantizedConv2D->common;
common->relu = false;
common->group = 1;
common->outputCount = num_output;
common->kernelX = kw;
common->kernelY = kh;
int dilation_h = 1;
int dilation_w = 1;
if (find_attr_value(srcNode->tfNode, "rate", value)) {
// height, width
dilation_h = value.list().i(0);
dilation_w = value.list().i(1);
}
common->dilateX = dilation_w;
common->dilateY = dilation_h;
int stride_h = 1;
int stride_w = 1;
if (find_attr_value(srcNode->tfNode, "strides", value)) {
// batch, height, width, channels
stride_h = value.list().i(1);
stride_w = value.list().i(2);
}
common->strideX = stride_w;
common->strideY = stride_h;
common->padX = 0;
common->padY = 0;
common->padMode = MNN::PadMode_SAME;
if (find_attr_value(srcNode->tfNode, "padding", value)) {
if (value.s() == "VALID") {
common->padMode = MNN::PadMode_VALID;
}
}
dstOp->main.value = TfQuantizedConv2D;
}
REGISTER_CONVERTER(QuantizedConv2DTf, QuantizedConv2D);