use MSLIBS_SERVER while downloading third_party & fix
mem leak in detection_post_process
This commit is contained in:
parent
12109600fc
commit
5b17a69d35
16
build.sh
16
build.sh
|
@ -426,7 +426,15 @@ build_flatbuffer() {
|
||||||
cd ${BASEPATH}
|
cd ${BASEPATH}
|
||||||
FLATC="${BASEPATH}"/third_party/flatbuffers/build/flatc
|
FLATC="${BASEPATH}"/third_party/flatbuffers/build/flatc
|
||||||
if [[ ! -f "${FLATC}" ]]; then
|
if [[ ! -f "${FLATC}" ]]; then
|
||||||
|
if [[ ${MSLIBS_SERVER} ]]; then
|
||||||
|
cd "${BASEPATH}"/third_party/
|
||||||
|
rm -rf ./v1.11.0.tar.gz ./flatbuffers
|
||||||
|
wget http://${MSLIBS_SERVER}:8081/libs/flatbuffers/v1.11.0.tar.gz
|
||||||
|
tar -zxvf ./v1.11.0.tar.gz
|
||||||
|
mv ./flatbuffers-1.11.0 ./flatbuffers
|
||||||
|
else
|
||||||
git submodule update --init --recursive third_party/flatbuffers
|
git submodule update --init --recursive third_party/flatbuffers
|
||||||
|
fi
|
||||||
cd ${BASEPATH}/third_party/flatbuffers
|
cd ${BASEPATH}/third_party/flatbuffers
|
||||||
rm -rf build && mkdir -pv build && cd build && cmake -DFLATBUFFERS_BUILD_SHAREDLIB=ON .. && make -j$THREAD_NUM
|
rm -rf build && mkdir -pv build && cd build && cmake -DFLATBUFFERS_BUILD_SHAREDLIB=ON .. && make -j$THREAD_NUM
|
||||||
gene_flatbuffer
|
gene_flatbuffer
|
||||||
|
@ -447,7 +455,15 @@ build_protobuf() {
|
||||||
cd ${BASEPATH}
|
cd ${BASEPATH}
|
||||||
PROTOC="${BASEPATH}"/third_party/protobuf/build/bin/protoc
|
PROTOC="${BASEPATH}"/third_party/protobuf/build/bin/protoc
|
||||||
if [[ ! -f "${PROTOC}" ]]; then
|
if [[ ! -f "${PROTOC}" ]]; then
|
||||||
|
if [[ ${MSLIBS_SERVER} ]]; then
|
||||||
|
cd "${BASEPATH}"/third_party/
|
||||||
|
rm -rf ./v3.8.0.tar.gz ./protobuf
|
||||||
|
wget http://${MSLIBS_SERVER}:8081/libs/protobuf/v3.8.0.tar.gz
|
||||||
|
tar -zxvf ./v3.8.0.tar.gz
|
||||||
|
mv ./protobuf-3.8.0 ./protobuf
|
||||||
|
else
|
||||||
git submodule update --init --recursive third_party/protobuf
|
git submodule update --init --recursive third_party/protobuf
|
||||||
|
fi
|
||||||
cd ${BASEPATH}/third_party/protobuf
|
cd ${BASEPATH}/third_party/protobuf
|
||||||
rm -rf build && mkdir -pv build && ./autogen.sh
|
rm -rf build && mkdir -pv build && ./autogen.sh
|
||||||
./configure --prefix=${BASEPATH}/third_party/protobuf/build
|
./configure --prefix=${BASEPATH}/third_party/protobuf/build
|
||||||
|
|
|
@ -30,6 +30,7 @@ int DetectionPostProcessCPUKernel::Init() {
|
||||||
MS_ASSERT(context_->allocator != nullptr);
|
MS_ASSERT(context_->allocator != nullptr);
|
||||||
auto anchor_tensor = in_tensors_.at(2);
|
auto anchor_tensor = in_tensors_.at(2);
|
||||||
DetectionPostProcessParameter *parameter = reinterpret_cast<DetectionPostProcessParameter *>(op_parameter_);
|
DetectionPostProcessParameter *parameter = reinterpret_cast<DetectionPostProcessParameter *>(op_parameter_);
|
||||||
|
parameter->anchors_ = nullptr;
|
||||||
if (anchor_tensor->data_type() == kNumberTypeUInt8) {
|
if (anchor_tensor->data_type() == kNumberTypeUInt8) {
|
||||||
const auto quant_params = anchor_tensor->GetQuantParams();
|
const auto quant_params = anchor_tensor->GetQuantParams();
|
||||||
const double scale = quant_params.at(0).scale;
|
const double scale = quant_params.at(0).scale;
|
||||||
|
@ -37,15 +38,21 @@ int DetectionPostProcessCPUKernel::Init() {
|
||||||
auto anchor_uint8 = reinterpret_cast<uint8_t *>(anchor_tensor->Data());
|
auto anchor_uint8 = reinterpret_cast<uint8_t *>(anchor_tensor->Data());
|
||||||
auto anchor_fp32 =
|
auto anchor_fp32 =
|
||||||
reinterpret_cast<float *>(context_->allocator->Malloc(anchor_tensor->ElementsNum() * sizeof(float)));
|
reinterpret_cast<float *>(context_->allocator->Malloc(anchor_tensor->ElementsNum() * sizeof(float)));
|
||||||
|
if (anchor_fp32 == nullptr) {
|
||||||
|
MS_LOG(ERROR) << "Malloc anchor failed";
|
||||||
|
return RET_ERROR;
|
||||||
|
}
|
||||||
for (int i = 0; i < anchor_tensor->ElementsNum(); ++i) {
|
for (int i = 0; i < anchor_tensor->ElementsNum(); ++i) {
|
||||||
*(anchor_fp32 + i) = static_cast<float>((static_cast<int>(anchor_uint8[i]) - zp) * scale);
|
*(anchor_fp32 + i) = static_cast<float>((static_cast<int>(anchor_uint8[i]) - zp) * scale);
|
||||||
}
|
}
|
||||||
parameter->anchors_ = anchor_fp32;
|
parameter->anchors_ = anchor_fp32;
|
||||||
} else if (anchor_tensor->data_type() == kNumberTypeFloat32) {
|
} else if (anchor_tensor->data_type() == kNumberTypeFloat32) {
|
||||||
auto anchor_fp32 = reinterpret_cast<float *>(anchor_tensor->Data());
|
parameter->anchors_ = reinterpret_cast<float *>(context_->allocator->Malloc(anchor_tensor->Size()));
|
||||||
for (int i = 0; i < anchor_tensor->ElementsNum(); ++i) {
|
if (parameter->anchors_ == nullptr) {
|
||||||
parameter->anchors_[i] = anchor_fp32[i];
|
MS_LOG(ERROR) << "Malloc anchor failed";
|
||||||
|
return RET_ERROR;
|
||||||
}
|
}
|
||||||
|
memcpy(parameter->anchors_, anchor_tensor->Data(), anchor_tensor->Size());
|
||||||
} else {
|
} else {
|
||||||
MS_LOG(ERROR) << "unsupported anchor data type " << anchor_tensor->data_type();
|
MS_LOG(ERROR) << "unsupported anchor data type " << anchor_tensor->data_type();
|
||||||
return RET_ERROR;
|
return RET_ERROR;
|
||||||
|
@ -53,6 +60,11 @@ int DetectionPostProcessCPUKernel::Init() {
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DetectionPostProcessCPUKernel::~DetectionPostProcessCPUKernel() {
|
||||||
|
DetectionPostProcessParameter *parameter = reinterpret_cast<DetectionPostProcessParameter *>(op_parameter_);
|
||||||
|
context_->allocator->Free(parameter->anchors_);
|
||||||
|
}
|
||||||
|
|
||||||
int DetectionPostProcessCPUKernel::ReSize() { return RET_OK; }
|
int DetectionPostProcessCPUKernel::ReSize() { return RET_OK; }
|
||||||
|
|
||||||
int DetectionPostProcessCPUKernel::Run() {
|
int DetectionPostProcessCPUKernel::Run() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DetectionPostProcessCPUKernel : public LiteKernel {
|
||||||
: LiteKernel(parameter, inputs, outputs, ctx, primitive) {
|
: LiteKernel(parameter, inputs, outputs, ctx, primitive) {
|
||||||
param_ = reinterpret_cast<DetectionPostProcessCPUKernel *>(parameter);
|
param_ = reinterpret_cast<DetectionPostProcessCPUKernel *>(parameter);
|
||||||
}
|
}
|
||||||
~DetectionPostProcessCPUKernel() override = default;
|
~DetectionPostProcessCPUKernel() override;
|
||||||
|
|
||||||
int Init() override;
|
int Init() override;
|
||||||
int ReSize() override;
|
int ReSize() override;
|
||||||
|
|
Loading…
Reference in New Issue