Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
92eb0ab
add override mark
ChaoII Sep 30, 2022
c34b67a
Merge branch 'develop' into develop
jiangjiajun Oct 5, 2022
5ac31e7
Merge branch 'develop' into develop
jiangjiajun Oct 6, 2022
dd64a46
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 8, 2022
ff5ee8f
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 8, 2022
38ce0cf
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 8, 2022
cff22b8
delete some
ChaoII Oct 9, 2022
d6215ad
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 9, 2022
db3c81e
recovery
ChaoII Oct 9, 2022
1d64e35
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 9, 2022
0251b22
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 10, 2022
2910b3f
recovery
ChaoII Oct 11, 2022
f2f95ad
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 11, 2022
c54af78
add tracking
ChaoII Oct 11, 2022
fff9af0
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 11, 2022
f8f6998
add tracking py_bind and example
ChaoII Oct 12, 2022
5b845b4
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 12, 2022
9f79627
add pptracking
ChaoII Oct 12, 2022
6b9a5c4
add pptracking
ChaoII Oct 12, 2022
1d134b0
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 12, 2022
d800402
iomanip head file
ChaoII Oct 13, 2022
d7b534e
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 13, 2022
c92e5d5
add opencv_video lib
ChaoII Oct 13, 2022
a0b7f67
add python libs package
ChaoII Oct 13, 2022
cef6dd5
Merge branch 'develop' into develop
jiangjiajun Oct 13, 2022
a4dedb8
complete comments
ChaoII Oct 13, 2022
d80be12
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 13, 2022
3da3d36
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 13, 2022
00fa281
Merge branch 'develop' into develop
jiangjiajun Oct 16, 2022
1902c3c
Merge branch 'develop' into develop
jiangjiajun Oct 17, 2022
e8c6f0b
Merge branch 'develop' into develop
jiangjiajun Oct 17, 2022
9552329
add jdeTracker_ member variable
ChaoII Oct 17, 2022
33ab3e6
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 17, 2022
0a18021
add 'FASTDEPLOY_DECL' macro
ChaoII Oct 18, 2022
e86411c
remove kwargs params
ChaoII Oct 18, 2022
c80dbd9
Merge branch 'develop' into develop
jiangjiajun Oct 20, 2022
6eb6a7a
Merge branch 'develop' into develop
jiangjiajun Oct 20, 2022
cb424cd
Merge branch 'develop' into develop
jiangjiajun Oct 20, 2022
c4bf265
Merge branch 'develop' into develop
jiangjiajun Oct 20, 2022
7dbd62a
[Doc]add pptracking doc
ChaoII Oct 21, 2022
5b93f1d
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 21, 2022
4e8db89
Merge branch 'develop' into develop
jiangjiajun Oct 21, 2022
9a3f1a4
[Doc]update pptracking docs
ChaoII Oct 21, 2022
5eaf19e
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 21, 2022
df0d551
delete 'ENABLE_PADDLE_FRONTEND' switch
ChaoII Oct 21, 2022
23f329d
add pptracking unit test
ChaoII Oct 21, 2022
a5f5544
update pptracking unit test
ChaoII Oct 22, 2022
20edce2
modify test video file path and remove trt test
ChaoII Oct 24, 2022
09d9a7f
update unit test model url
ChaoII Oct 24, 2022
2e09944
Merge branch 'develop' into develop
jiangjiajun Oct 25, 2022
b23bb44
remove 'FASTDEPLOY_DECL' macro
ChaoII Oct 25, 2022
0734229
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 25, 2022
edcdab6
Merge branch 'develop' into develop
jiangjiajun Oct 25, 2022
dd99333
fix build python packages about pptracking on win32
ChaoII Oct 25, 2022
faaa94e
Merge branch 'develop' of github.com:ChaoII/FastDeploy into develop
ChaoII Oct 25, 2022
bef7cc9
Merge branch 'develop' into develop
jiangjiajun Oct 25, 2022
25c1576
Merge branch 'develop' into develop
jiangjiajun Oct 26, 2022
778de0d
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into dev…
ChaoII Oct 26, 2022
e1b5cf4
update comment
ChaoII Oct 26, 2022
7001bee
Merge branch 'develop' into pptracking
jiangjiajun Oct 26, 2022
60ca6d4
add pptracking model explain
ChaoII Oct 26, 2022
4b4705b
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into ppt…
ChaoII Oct 26, 2022
470134f
Merge branch 'pptracking' of github.com:ChaoII/FastDeploy into pptrac…
ChaoII Oct 26, 2022
a2fe764
Merge branch 'develop' into pptracking
jiangjiajun Oct 28, 2022
8025d28
Merge branch 'develop' into pptracking
jiangjiajun Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/vision/tracking/pptracking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# PP-Tracking模型部署

## 模型版本说明

- [PaddleDetection release/2.5](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5)

## 支持模型列表

目前FastDeploy支持如下模型的部署

- [PP-Tracking系列模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/mot)


## 导出部署模型

在部署前,需要先将训练好的PP-Tracking导出成部署模型,导出PPTracking导出模型步骤,参考文档[导出模型](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/cpp/README.md)。


## 下载预训练模型

为了方便开发者的测试,下面提供了PP-Tracking行人跟踪垂类模型,开发者可直接下载使用,更多模型参见[PPTracking](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/deploy/pptracking/README_cn.md)。

| 模型 | 参数大小 | 精度 | 备注 |
|:-----------------------------------------------------------------------------------------------------|:-------|:----- | :------ |
| [PP-Tracking](https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz) | 51.2MB | - |

**说明**
- 仅支持JDE模型(JDE,FairMOT,MCFairMOT);
- 目前暂不支持SDE模型的部署,待PaddleDetection官方更新SED部署代码后,对SDE模型进行支持。


## 详细部署文档

- [Python部署](python)
- [C++部署](cpp)
1 change: 0 additions & 1 deletion examples/vision/tracking/pptracking/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ make -j
wget https://bj.bcebos.com/paddlehub/fastdeploy/fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz
tar -xvf fairmot_hrnetv2_w18_dlafpn_30e_576x320.tgz
wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4
wget https://bj.bcebos.com/paddlehub/fastdeploy/person.mp4


# CPU推理
Expand Down
71 changes: 71 additions & 0 deletions fastdeploy/vision/common/processors/letter_box.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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/common/processors/letter_box.h"

namespace fastdeploy{
namespace vision{
bool LetterBoxResize::ImplByOpenCV(Mat* mat) {

if (mat->Channels() != color_.size()) {
FDERROR << "Pad: Require input channels equals to size of padding value, "
"but now channels = "
<< mat->Channels()
<< ", the size of padding values = " << color_.size() << "."
<< std::endl;
return false;
}
cv::Mat* im = mat->GetOpenCVMat();
// generate scale_factor
int origin_w = mat->Width();
int origin_h = mat->Height();
int target_h = target_size_[0];
int target_w = target_size_[1];
float ratio_h = static_cast<float>(target_h) / static_cast<float>(origin_h);
float ratio_w = static_cast<float>(target_w) / static_cast<float>(origin_w);
float resize_scale = std::min(ratio_h, ratio_w);
// get_resized_shape
int new_shape_w = std::round(im->cols * resize_scale);
int new_shape_h = std::round(im->rows * resize_scale);
// calculate pad
float padw = (target_size_[1] - new_shape_w) / 2.;
float padh = (target_size_[0] - new_shape_h) / 2.;
int top = std::round(padh - 0.1);
int bottom = std::round(padh + 0.1);
int left = std::round(padw - 0.1);
int right = std::round(padw + 0.1);
cv::resize(*im, *im, cv::Size(new_shape_w, new_shape_h), 0, 0, cv::INTER_AREA);
cv::Scalar color;
if (color_.size() == 1) {
color = cv::Scalar(color_[0]);
} else if (color_.size() == 2) {
color = cv::Scalar(color_[0], color_[1]);
} else if (color_.size() == 3) {
color = cv::Scalar(color_[0], color_[1], color_[2]);
} else {
color = cv::Scalar(color_[0], color_[1], color_[2], color_[3]);
}
cv::copyMakeBorder(*im, *im, top, bottom, left, right, cv::BORDER_CONSTANT, color);
mat->SetWidth(im->cols);
mat->SetHeight(im->rows);
return true;
}

bool LetterBoxResize::Run(Mat* mat, const std::vector<int>& target_size, const std::vector<float>& color, ProcLib lib) {
auto l = LetterBoxResize(target_size,color);
return l(mat, lib);
}

} // namespace vision
} // namespace fastdeploy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
// 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.
Expand All @@ -14,23 +14,28 @@

#pragma once

#include "fastdeploy/vision/common/processors/transform.h"
#include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/vision/common/processors/base.h"

namespace fastdeploy {
namespace vision {
namespace tracking {
class LetterBoxResize: public Processor{
public:
LetterBoxResize(const std::vector<int>& target_size, const std::vector<float>& color);
bool ImplByOpenCV(Mat* mat) override;
std::string Name() override { return "LetterBoxResize"; }
private:
std::vector<int> target_size_;
std::vector<float> color_;
};

} // namespace tracking
} // namespace vision
} // namespace fastdeploy
class LetterBoxResize : public Processor {
public:
LetterBoxResize(const std::vector<int>& target_size, const std::vector<float>& color) {
target_size_ = target_size;
color_ = color;
}

bool ImplByOpenCV(Mat* mat);

std::string Name() { return "LetterBoxResize"; }

static bool Run(Mat* mat,const std::vector<int>& target_size, const std::vector<float>& color,
ProcLib lib = ProcLib::OPENCV);

private:
std::vector<int> target_size_;
std::vector<float> color_;
};
} // namespace vision
} // namespace fastdeploy
1 change: 1 addition & 0 deletions fastdeploy/vision/common/processors/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
#include "fastdeploy/vision/common/processors/resize_by_short.h"
#include "fastdeploy/vision/common/processors/stride_pad.h"
#include "fastdeploy/vision/common/processors/warp_affine.h"
#include "fastdeploy/vision/common/processors/letter_box.h"
15 changes: 12 additions & 3 deletions fastdeploy/vision/common/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,25 @@ struct FASTDEPLOY_DECL OCRResult : public BaseResult {
std::string Str();
};

/*! @brief MOT(Multi-Object Tracking) result structure for all the MOT models
*/
struct FASTDEPLOY_DECL MOTResult : public BaseResult {
// left top right bottom
/** \brief All the tracking object boxes for an input image, the size of `boxes` is the number of tracking objects, and the element of `boxes` is a array of 4 float values, means [xmin, ymin, xmax, ymax]
*/
std::vector<std::array<int, 4>> boxes;
/** \brief All the tracking object ids
*/
std::vector<int> ids;
/** \brief The confidence for all the tracking objects
*/
std::vector<float> scores;
/** \brief The classify label id for all the tracking object
*/
std::vector<int> class_ids;
ResultType type = ResultType::MOT;

/// Clear MOT result
void Clear();

/// Debug function, convert the result to string to print
std::string Str();
};

Expand Down
59 changes: 0 additions & 59 deletions fastdeploy/vision/tracking/pptracking/letter_box.cc

This file was deleted.

37 changes: 0 additions & 37 deletions fastdeploy/vision/tracking/pptracking/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,7 @@ bool PPTracking::BuildPreprocessPipelineFromConfig(){
return true;
}

void PPTracking::GetNmsInfo() {
if (runtime_option.model_format == ModelFormat::PADDLE) {
std::string contents;
if (!ReadBinaryFromFile(runtime_option.model_file, &contents)) {
return;
}
auto reader = paddle2onnx::PaddleReader(contents.c_str(), contents.size());
if (reader.has_nms) {
has_nms_ = true;
background_label = reader.nms_params.background_label;
keep_top_k = reader.nms_params.keep_top_k;
nms_eta = reader.nms_params.nms_eta;
nms_threshold = reader.nms_params.nms_threshold;
score_threshold = reader.nms_params.score_threshold;
nms_top_k = reader.nms_params.nms_top_k;
normalized = reader.nms_params.normalized;
}
}
}

bool PPTracking::Initialize() {
// remove multiclass_nms3 now
// this is a trick operation for ppyoloe while inference on trt
GetNmsInfo();
runtime_option.remove_multiclass_nms_ = true;
runtime_option.custom_op_info_["multiclass_nms3"] = "MultiClassNMS";
if (!BuildPreprocessPipelineFromConfig()) {
FDERROR << "Failed to build preprocess pipeline from configuration file."
<< std::endl;
Expand All @@ -186,18 +161,6 @@ bool PPTracking::Initialize() {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
}

if (has_nms_ && runtime_option.backend == Backend::TRT) {
FDINFO << "Detected operator multiclass_nms3 in your model, will replace "
"it with fastdeploy::backend::MultiClassNMS(background_label="
<< background_label << ", keep_top_k=" << keep_top_k
<< ", nms_eta=" << nms_eta << ", nms_threshold=" << nms_threshold
<< ", score_threshold=" << score_threshold
<< ", nms_top_k=" << nms_top_k << ", normalized=" << normalized
<< ")." << std::endl;
has_nms_ = false;
}

// create JDETracker instance
std::unique_ptr<JDETracker> jdeTracker(new JDETracker);
jdeTracker_ = std::move(jdeTracker);
Expand Down
15 changes: 2 additions & 13 deletions fastdeploy/vision/tracking/pptracking/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/vision/common/result.h"
#include "fastdeploy/vision/tracking/pptracking/tracker.h"
#include "fastdeploy/vision/tracking/pptracking/letter_box.h"
//#include "fastdeploy/vision/tracking/pptracking/letter_box.h"

namespace fastdeploy {
namespace vision {
Expand Down Expand Up @@ -56,8 +56,8 @@ class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
private:

bool BuildPreprocessPipelineFromConfig();

bool Initialize();
void GetNmsInfo();

bool Preprocess(Mat* img, std::vector<FDTensor>* outputs);

Expand All @@ -69,19 +69,8 @@ class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
float conf_thresh_;
float tracked_thresh_;
float min_box_area_;
bool is_scale_ = true;
std::unique_ptr<JDETracker> jdeTracker_;

// configuration for nms
int64_t background_label = -1;
int64_t keep_top_k = 300;
float nms_eta = 1.0;
float nms_threshold = 0.7;
float score_threshold = 0.01;
int64_t nms_top_k = 10000;
bool normalized = true;
bool has_nms_ = true;

};

} // namespace tracking
Expand Down
13 changes: 13 additions & 0 deletions python/fastdeploy/vision/tracking/pptracking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def __init__(self,
config_file,
runtime_option=None,
model_format=ModelFormat.PADDLE):
"""Load a PPTracking model exported by PaddleDetection.

:param model_file: (str)Path of model file, e.g pptracking/model.pdmodel
:param params_file: (str)Path of parameters file, e.g ppyoloe/model.pdiparams
:param config_file: (str)Path of configuration file for deployment, e.g ppyoloe/infer_cfg.yml
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model
"""
super(PPTracking, self).__init__(runtime_option)

assert model_format == ModelFormat.PADDLE, "PPTracking model only support model format of ModelFormat.Paddle now."
Expand All @@ -33,5 +41,10 @@ def __init__(self,
assert self.initialized, "PPTracking model initialize failed."

def predict(self, input_image):
"""Predict the MOT result for an input image

:param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format
:return: MOTResult
"""
assert input_image is not None, "The input image data is None."
return self._model.predict(input_image)