q.yao 823ca38646
[Feature] Add NCNN mmdetection support (#49)
* first

* fix0

* fix1

* dirty work

* wip

* add allocator

* finally done!

* lint

* fix lint

* better gather

* better onnx2ncnn

* fix expand

* [Fix] NCNN TensorSlice op bugs (#42)

* fix custom ops support, fix multiple mark bug, add name mapping

* check if the value_info need to be added

* remove unnecessary print

* add nms implement

* two stage split wip

* add two stage split

* add split retinanet visualize

* add two stage split (wip)

* finish two stage split

* fix lint

* move parse string to mmdeploy.utils

* add calib data generator

* create calib dataset

* finish end2end int8

* add split two stage tensorrt visualize

* fix tensorslice bugs

* fix lint

* fix clang-format

* remove comments

* int param

* fix lint

Co-authored-by: grimoire <yaoqian@sensetime.com>

* add two stage ncnn support

* remove unused ops

* git unused config

* remove no_grad, should add in refactor

* add ncnn wrapper

* fix lint

* size return tuple

* Resolve grammar error

* Fix lint

* Trim Trailing Whitespace

* fix trim

* update wrapper

* remove logs

* remove

* csrc optimize

Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
2021-08-26 18:40:14 +08:00

48 lines
963 B
C++
Executable File

#include "shape.h"
#include "../ncnn_ops_definer.h"
namespace mmlab {
using namespace ncnn;
DEFINE_LAYER_CREATOR(Shape)
DEFINE_NCNN_OPS(Shape, Shape)
Shape::Shape() {
one_blob_only = true;
support_inplace = false;
}
int Shape::forward(const Mat &bottom_blob, Mat &top_blob,
const Option &opt) const {
int dims = bottom_blob.dims;
int w = bottom_blob.w;
size_t elemsize = sizeof(float);
top_blob.create(dims + 1, elemsize, opt.blob_allocator);
if (top_blob.empty()) {
return -100;
}
float *outptr = top_blob;
if (dims == 1) {
outptr[0] = 1.0f;
outptr[1] = w;
return 0;
}
if (dims == 2) {
int h = bottom_blob.h;
outptr[0] = 1.0f;
outptr[1] = h;
outptr[2] = w;
return 0;
}
if (dims == 3) {
int h = bottom_blob.h;
int channels = bottom_blob.c;
outptr[0] = 1.0f;
outptr[1] = channels;
outptr[2] = h;
outptr[3] = w;
return 0;
}
}
} // namespace mmlab