forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResizeBilinearTf.cpp
More file actions
79 lines (69 loc) · 2.74 KB
/
Copy pathResizeBilinearTf.cpp
File metadata and controls
79 lines (69 loc) · 2.74 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
//
// ResizeBilinearTf.cpp
// MNNConverter
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include <string.h>
#include "TfUtils.hpp"
#include "graph.pb.h"
#include "tfOpConverter.hpp"
DECLARE_OP_CONVERTER(InterpTf);
MNN::OpType InterpTf::opType() {
return MNN::OpType_Interp;
}
MNN::OpParameter InterpTf::type() {
return MNN::OpParameter_Interp;
}
void InterpTf::run(MNN::OpT *dstOp, TmpNode *srcNode, TmpGraph *tempGraph) {
auto interpParam = new MNN::InterpT;
TmpNode *constShapeNode = tempGraph->_getTmpNode(srcNode->inEdges[1]);
tensorflow::AttrValue value;
// ResizeBilinear's input shape could be computed at the runtime
if (constShapeNode->opType == "Const") {
if (find_attr_value(constShapeNode->tfNode, "value", value)) {
const tensorflow::TensorProto &sizeTensor = value.tensor();
const std::string tensor_content = sizeTensor.tensor_content();
if (!tensor_content.empty()) {
assert(tensor_content.size() >= sizeof(int));
int h = *(int *)tensor_content.data();
int w = h;
if (tensor_content.size() >= sizeof(int) * 2) {
w = *(int *)(tensor_content.data() + sizeof(int));
}
interpParam->outputHeight = h;
interpParam->outputWidth = w;
} else {
CHECK(sizeTensor.tensor_shape().dim_size() == 2) << "Resize op Parameter ERROR!!! ===> "
<< srcNode->opName;
const int *sizeData = sizeTensor.int_val().data();
interpParam->outputHeight = sizeData[0];
interpParam->outputWidth = sizeData[1];
}
}
}
interpParam->alignCorners = false; // defalut false
if (find_attr_value(srcNode->tfNode, "align_corners", value)) {
interpParam->alignCorners = value.b();
}
// TODO defalut
interpParam->widthScale = 1.0;
interpParam->heightScale = 1.0;
// 1:near 2: bilinear 3: cubic
if (srcNode->opType == "ResizeNearestNeighbor") {
interpParam->resizeType = 1;
} else {
interpParam->resizeType = 2;
}
dstOp->main.value = interpParam;
// delete the const input edges!!! Must to do
// Const node, others no delete
if (constShapeNode->opType == "Const") {
const std::vector<std::string>::iterator it2delete = srcNode->inEdges.begin() + 1;
srcNode->inEdges.erase(it2delete);
DCHECK(srcNode->inEdges.size() == 1) << "Resize op Input ERROR!!! ===> " << srcNode->opName;
}
}
REGISTER_CONVERTER(InterpTf, ResizeBilinear);
REGISTER_CONVERTER(InterpTf, ResizeNearestNeighbor);