MCPcopy Create free account
hub / github.com/alibaba/MNN / onCompute

Method onCompute

source/geometry/GeometryShape.cpp:92–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90class GeometryPriorBox : public GeometryComputer {
91public:
92 virtual bool onCompute(const Op* op, const std::vector<Tensor*>& inputs, const std::vector<Tensor*>& outputs,
93 Context& context, CommandBuffer& res) const override {
94 if(!context.allocTensor(outputs[0])) {
95 return false;
96 }
97 std::shared_ptr<Tensor> outputTemp(new Tensor(outputs[0], Tensor::CAFFE));
98 if (nullptr == outputTemp->host<void>()) {
99 // Out of memory
100 return false;
101 }
102 auto layer = op->main_as_PriorBox();
103 auto input0 = inputs[0];
104 const int w = input0->width();
105 const int h = input0->height();
106
107 // image width, height
108 int imageW = layer->imageWidth();
109 if (imageW <= 0) {
110 imageW = inputs[1]->width();
111 }
112 int imageH = layer->imageHeight();
113 if (imageH <= 0) {
114 imageH = inputs[1]->height();
115 }
116
117 // step width, height
118 float stepW = layer->stepWidth();
119 if (stepW <= 0) {
120 stepW = (float)imageW / w;
121 }
122 float stepH = layer->stepHeight();
123 if (stepH <= 0) {
124 stepH = (float)imageH / h;
125 }
126
127 // sizes
128 auto minSizes = layer->minSizes();
129 auto minSizeCount = minSizes ? minSizes->size() : 0;
130 auto maxSizes = layer->maxSizes();
131 auto maxSizeCount = maxSizes ? maxSizes->size() : 0;
132 auto aspectRatios = layer->aspectRatios();
133 bool flip = layer->flip();
134
135 std::vector<float> aspectRatiosValue{1.0f};
136 if (aspectRatios != nullptr) {
137 for (int i = 0; i < aspectRatios->size(); ++i) {
138 auto ratio = aspectRatios->data()[i];
139 bool exist = false;
140 for (auto v : aspectRatiosValue) {
141 auto diff = v - ratio;
142 if (diff < 0) {
143 diff = -diff;
144 }
145 if (diff < 1e-6) {
146 exist = true;
147 break;
148 }
149 }

Callers

nothing calls this directly

Calls 11

MNNCPUCopyBufferFunction · 0.85
allocTensorMethod · 0.80
sqrtFunction · 0.50
minFunction · 0.50
maxFunction · 0.50
widthMethod · 0.45
heightMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
offsetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected