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

55 lines
1.4 KiB
C++
Executable File

#include "constantofshape.h"
#include "../ncnn_ops_definer.h"
namespace mmlab {
using namespace ncnn;
DEFINE_LAYER_CREATOR(ConstantOfShape)
DEFINE_NCNN_OPS(ConstantOfShape, ConstantOfShape)
ConstantOfShape::ConstantOfShape() {
one_blob_only = true;
support_inplace = false;
}
int ConstantOfShape::load_param(const ParamDict& pd) {
val = pd.get(0, 0.f);
return 0;
}
int ConstantOfShape::forward(const Mat& bottom_blob, Mat& top_blob,
const Option& opt) const {
int dims = bottom_blob.w - 1;
const float* bottom_ptr = bottom_blob;
const float* shape_ptr = bottom_ptr + 1;
if (dims == 1) {
int w = (int)(shape_ptr[0] + 0.5);
size_t elemsize = sizeof(val);
top_blob.create(w, elemsize, opt.blob_allocator);
if (top_blob.empty()) return -100;
top_blob.fill(val);
return 0;
}
if (dims == 2) {
int h = (int)(shape_ptr[0] + 0.5);
int w = (int)(shape_ptr[1] + 0.5);
size_t elemsize = sizeof(val);
top_blob.create(w, h, elemsize, opt.blob_allocator);
if (top_blob.empty()) return -100;
top_blob.fill(val);
return 0;
}
if (dims == 3) {
int channels = (int)(shape_ptr[0] + 0.5);
int h = (int)(shape_ptr[1] + 0.5);
int w = (int)(shape_ptr[2] + 0.5);
size_t elemsize = sizeof(val);
top_blob.create(w, h, channels, elemsize, opt.blob_allocator);
if (top_blob.empty()) return -100;
top_blob.fill(val);
return 0;
}
}
} // namespace mmlab