mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-04 16:22:57 +08:00

* [Android] Add Android build docs and demo (#26) * [Backend] Add override flag to lite backend * [Docs] Add Android C++ SDK build docs * [Doc] fix android_build_docs typos * Update CMakeLists.txt * Update android.md * [Doc] Add PicoDet Android demo docs * [Doc] Update PicoDet Andorid demo docs * [Doc] Update PaddleClasModel Android demo docs * [Doc] Update fastdeploy android jni docs * [Doc] Update fastdeploy android jni usage docs * [Android] init fastdeploy android jar package * [Backend] support int8 option for lite backend * [Model] add Backend::Lite to paddle model * [Backend] use CopyFromCpu for lite backend. * [Android] package jni srcs and java api into aar * Update infer.cc * Update infer.cc * [Android] Update package build.gradle * [Android] Update android app examples * [Android] update android detection app
85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "fastdeploy/vision/detection/ppdet/rcnn.h"
|
|
|
|
namespace fastdeploy {
|
|
namespace vision {
|
|
namespace detection {
|
|
|
|
FasterRCNN::FasterRCNN(const std::string& model_file,
|
|
const std::string& params_file,
|
|
const std::string& config_file,
|
|
const RuntimeOption& custom_option,
|
|
const ModelFormat& model_format) {
|
|
config_file_ = config_file;
|
|
valid_cpu_backends = {Backend::PDINFER, Backend::LITE};
|
|
valid_gpu_backends = {Backend::PDINFER};
|
|
has_nms_ = true;
|
|
runtime_option = custom_option;
|
|
runtime_option.model_format = model_format;
|
|
runtime_option.model_file = model_file;
|
|
runtime_option.params_file = params_file;
|
|
initialized = Initialize();
|
|
}
|
|
|
|
bool FasterRCNN::Initialize() {
|
|
if (!BuildPreprocessPipelineFromConfig()) {
|
|
FDERROR << "Failed to build preprocess pipeline from configuration file."
|
|
<< std::endl;
|
|
return false;
|
|
}
|
|
if (!InitRuntime()) {
|
|
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool FasterRCNN::Preprocess(Mat* mat, std::vector<FDTensor>* outputs) {
|
|
int origin_w = mat->Width();
|
|
int origin_h = mat->Height();
|
|
float scale[2] = {1.0, 1.0};
|
|
for (size_t i = 0; i < processors_.size(); ++i) {
|
|
if (!(*(processors_[i].get()))(mat)) {
|
|
FDERROR << "Failed to process image data in " << processors_[i]->Name()
|
|
<< "." << std::endl;
|
|
return false;
|
|
}
|
|
if (processors_[i]->Name().find("Resize") != std::string::npos) {
|
|
scale[0] = mat->Height() * 1.0 / origin_h;
|
|
scale[1] = mat->Width() * 1.0 / origin_w;
|
|
}
|
|
}
|
|
|
|
outputs->resize(3);
|
|
(*outputs)[0].Allocate({1, 2}, FDDataType::FP32, "im_shape");
|
|
(*outputs)[2].Allocate({1, 2}, FDDataType::FP32, "scale_factor");
|
|
float* ptr0 = static_cast<float*>((*outputs)[0].MutableData());
|
|
ptr0[0] = mat->Height();
|
|
ptr0[1] = mat->Width();
|
|
float* ptr2 = static_cast<float*>((*outputs)[2].MutableData());
|
|
ptr2[0] = scale[0];
|
|
ptr2[1] = scale[1];
|
|
(*outputs)[1].name = "image";
|
|
mat->ShareWithTensor(&((*outputs)[1]));
|
|
// reshape to [1, c, h, w]
|
|
(*outputs)[1].shape.insert((*outputs)[1].shape.begin(), 1);
|
|
return true;
|
|
}
|
|
|
|
} // namespace detection
|
|
} // namespace vision
|
|
} // namespace fastdeploy
|