Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
79 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
aa23471
add tracking trail on vis_mot
ChaoII Oct 31, 2022
87c00ce
fix conflicts
ChaoII Oct 31, 2022
d02baa3
Merge branch 'develop' into pptracking
jiangjiajun Oct 31, 2022
ba7a848
Merge branch 'develop' into pptracking
jiangjiajun Oct 31, 2022
4fd8144
Merge branch 'develop' into pptracking
jiangjiajun Nov 1, 2022
cbd8ce1
add tracking trail
ChaoII Nov 1, 2022
4f5400f
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into ppt…
ChaoII Nov 1, 2022
10772b1
Merge branch 'develop' into pptracking
jiangjiajun Nov 2, 2022
08d3bdc
Merge branch 'develop' of github.com:PaddlePaddle/FastDeploy into ppt…
ChaoII Nov 2, 2022
08123fb
Merge branch 'pptracking' of github.com:ChaoII/FastDeploy into pptrac…
ChaoII Nov 2, 2022
62e5352
modify code for some suggestion
ChaoII Nov 2, 2022
875fb04
fix conflict
ChaoII Nov 2, 2022
893036e
remove unused import
ChaoII Nov 2, 2022
52c8063
fix import bug
ChaoII Nov 2, 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
79 changes: 41 additions & 38 deletions examples/vision/tracking/pptracking/cpp/infer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@ void CpuInfer(const std::string& model_dir, const std::string& video_file) {

fastdeploy::vision::MOTResult result;
fastdeploy::vision::tracking::TrailRecorder recorder;
//during each prediction, data is inserted into the recorder. As the number of predictions increases,
//the memory will continue to grow. You can cancel the insertion through 'UnBindRecorder'.
int count = 0; // unbind condition
// during each prediction, data is inserted into the recorder. As the number of predictions increases,
// the memory will continue to grow. You can cancel the insertion through 'UnbindRecorder'.
// int count = 0; // unbind condition
model.BindRecorder(&recorder);
cv::Mat frame;
cv::VideoCapture capture(video_file);
while (capture.read(frame)) {
if (frame.empty()) {
break;
break;
}
if (!model.Predict(&frame, &result)) {
std::cerr << "Failed to predict." << std::endl;
return;
std::cerr << "Failed to predict." << std::endl;
return;
}
// such as adding this code can cancel trail datat bind
if(count++ == 10) model.UnBindRecorder();
// if(count++ == 10) model.UnbindRecorder();
// std::cout << result.Str() << std::endl;
cv::Mat out_img = fastdeploy::vision::VisMOT(frame, result, 0.0, &recorder);
cv::imshow("mot",out_img);
cv::waitKey(30);
}
model.UnbindRecorder();
capture.release();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在for循环后,显式调用一行model.UnBindRecorder(); 便于用户直接了解

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加显示调用

cv::destroyAllWindows();
}
Expand All @@ -76,27 +77,28 @@ void GpuInfer(const std::string& model_dir, const std::string& video_file) {

fastdeploy::vision::MOTResult result;
fastdeploy::vision::tracking::TrailRecorder trail_recorder;
//during each prediction, data is inserted into the recorder. As the number of predictions increases,
//the memory will continue to grow. You can cancel the insertion through 'UnBindRecorder'.
int count = 0; // unbind condition
// during each prediction, data is inserted into the recorder. As the number of predictions increases,
// the memory will continue to grow. You can cancel the insertion through 'UnbindRecorder'.
// int count = 0; // unbind condition
model.BindRecorder(&trail_recorder);
cv::Mat frame;
cv::VideoCapture capture(video_file);
while (capture.read(frame)) {
if (frame.empty()) {
break;
}
if (!model.Predict(&frame, &result)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
// such as adding this code can cancel trail datat bind
if(count++ == 10) model.UnBindRecorder();
// std::cout << result.Str() << std::endl;
cv::Mat out_img = fastdeploy::vision::VisMOT(frame, result, 0.0, &trail_recorder);
cv::imshow("mot",out_img);
cv::waitKey(30);
if (frame.empty()) {
break;
}
if (!model.Predict(&frame, &result)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
// such as adding this code can cancel trail datat bind
//if(count++ == 10) model.UnbindRecorder();
// std::cout << result.Str() << std::endl;
cv::Mat out_img = fastdeploy::vision::VisMOT(frame, result, 0.0, &trail_recorder);
cv::imshow("mot",out_img);
cv::waitKey(30);
}
model.UnbindRecorder();
capture.release();
cv::destroyAllWindows();
}
Expand All @@ -120,26 +122,27 @@ void TrtInfer(const std::string& model_dir, const std::string& video_file) {
fastdeploy::vision::MOTResult result;
fastdeploy::vision::tracking::TrailRecorder recorder;
//during each prediction, data is inserted into the recorder. As the number of predictions increases,
//the memory will continue to grow. You can cancel the insertion through 'UnBindRecorder'.
int count = 0; // unbind condition
//the memory will continue to grow. You can cancel the insertion through 'UnbindRecorder'.
// int count = 0; // unbind condition
model.BindRecorder(&recorder);
cv::Mat frame;
cv::VideoCapture capture(video_file);
while (capture.read(frame)) {
if (frame.empty()) {
break;
}
if (!model.Predict(&frame, &result)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
// such as adding this code can cancel trail datat bind
if(count++ == 10) model.UnBindRecorder();
// std::cout << result.Str() << std::endl;
cv::Mat out_img = fastdeploy::vision::VisMOT(frame, result, 0.0, &recorder);
cv::imshow("mot",out_img);
cv::waitKey(30);
if (frame.empty()) {
break;
}
if (!model.Predict(&frame, &result)) {
std::cerr << "Failed to predict." << std::endl;
return;
}
// such as adding this code can cancel trail datat bind
// if(count++ == 10) model.UnbindRecorder();
// std::cout << result.Str() << std::endl;
cv::Mat out_img = fastdeploy::vision::VisMOT(frame, result, 0.0, &recorder);
cv::imshow("mot",out_img);
cv::waitKey(30);
}
model.UnbindRecorder();
capture.release();
cv::destroyAllWindows();
}
Expand Down
12 changes: 6 additions & 6 deletions examples/vision/tracking/pptracking/python/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import fastdeploy as fd
import cv2
import time
import os


Expand Down Expand Up @@ -61,10 +60,10 @@ def build_option(args):
model_file, params_file, config_file, runtime_option=runtime_option)

# 初始化轨迹记录器
trail_recorder = fd.vision.tracking.TrailRecorder()
recorder = fd.vision.tracking.TrailRecorder()
# 绑定记录器 注意:每次预测时,往trail_recorder里面插入数据,随着预测次数的增加,内存会不断地增长,
# 可以通过unbind_trail_recorders()方法来解除绑定
model.bind_trail_recorders(trail_recorder)
# 可以通过unbind_recorder()方法来解除绑定
model.bind_recorder(recorder)
# 预测图片分割结果
cap = cv2.VideoCapture(args.video)
# count = 0
Expand All @@ -75,10 +74,11 @@ def build_option(args):
result = model.predict(frame)
# count += 1
# if count == 10:
# model.unbind_trail_recorders()
img = fd.vision.vis_mot(frame, result, 0.0)
# model.unbind_recorder()
img = fd.vision.vis_mot(frame, result, 0.0, recorder)
cv2.imshow("video", img)
if cv2.waitKey(30) == ord("q"):
break
model.unbind_recorder()
cap.release()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也显式调用一行model.unbind_trail_recorder()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加显示调用

cv2.destroyAllWindows()
14 changes: 3 additions & 11 deletions fastdeploy/vision/tracking/pptracking/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ bool PPTracking::Postprocess(std::vector<FDTensor>& infer_result, MOTResult *res
result->boxes.push_back(box);
result->ids.push_back(1);
result->scores.push_back(*dets.ptr<float>(0, 4));

} else {
std::vector<Track>::iterator titer;
for (titer = tracks.begin(); titer != tracks.end(); ++titer) {
Expand All @@ -288,14 +287,7 @@ bool PPTracking::Postprocess(std::vector<FDTensor>& infer_result, MOTResult *res
float center_x = (result->boxes[i][0] + result->boxes[i][2]) / 2;
float center_y = (result->boxes[i][1] + result->boxes[i][3]) / 2;
int id = result->ids[i];
auto iter = recorder_->records.find(id);
if (iter != recorder_->records.end()) {
auto trail = recorder_->records[id];
trail.push_back({int(center_x), int(center_y)});
recorder_->Add(id, trail);
} else {
recorder_->Add(id, {{int(center_x), int(center_y)}});
}
recorder_->Add(id,{int(center_x), int(center_y)});
}
return true;
}
Expand All @@ -306,11 +298,11 @@ void PPTracking::BindRecorder(TrailRecorder* recorder){
is_record_trail_ = true;
}

void PPTracking::UnBindRecorder(){
void PPTracking::UnbindRecorder(){

is_record_trail_ = false;
std::map<int, std::vector<std::array<int, 2>>>::iterator iter;
for(iter=recorder_->records.begin();iter!=recorder_->records.end();iter++){
for(iter = recorder_->records.begin(); iter != recorder_->records.end(); iter++){
iter->second.clear();
iter->second.shrink_to_fit();
}
Expand Down
16 changes: 11 additions & 5 deletions fastdeploy/vision/tracking/pptracking/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ namespace vision {
namespace tracking {
struct TrailRecorder{
std::map<int, std::vector<std::array<int, 2>>> records;
void Add(int id, const std::vector<std::array<int, 2>>& record);
void Add(int id, const std::array<int, 2>& record);
};

inline void TrailRecorder::Add(int id, const
std::vector<std::array<int, 2>> &record) {
records[id] = record;
inline void TrailRecorder::Add(int id, const std::array<int, 2>& record) {
auto iter = records.find(id);
if (iter != records.end()) {
auto trail = records[id];
trail.push_back(record);
records[id] = trail;
} else {
records[id] = {record};
}
}

class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
Expand Down Expand Up @@ -66,7 +72,7 @@ class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
void BindRecorder(TrailRecorder* recorder);
/** \brief cancel binding and clear trail information
*/
void UnBindRecorder();
void UnbindRecorder();


private:
Expand Down
4 changes: 2 additions & 2 deletions fastdeploy/vision/tracking/pptracking/pptracking_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void BindPPTracking(pybind11::module &m) {
self.Predict(&mat, res);
return res;
})
.def("bind_trail_recorders", &vision::tracking::PPTracking::BindRecorder)
.def("unbind_trail_recorders", &vision::tracking::PPTracking::UnBindRecorder);
.def("bind_recorder", &vision::tracking::PPTracking::BindRecorder)
.def("unbind_recorder", &vision::tracking::PPTracking::UnbindRecorder);
}
} // namespace fastdeploy
27 changes: 19 additions & 8 deletions python/fastdeploy/vision/tracking/pptracking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
from __future__ import absolute_import
from .... import FastDeployModel, ModelFormat
from .... import c_lib_wrap as C
import logging

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以改成

try:
    TrailRecorder = C.TrailRecorder
except:
    pass

这样在python层面可以直接用fastdeploy.vision.tracking.TrailRecorder 无需再创建一个类

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按要求调整


class TrailRecorder(C.vision.tracking.TrailRecorder):
def __init__(self):
super(TrailRecorder, self).__init__()
try:
TrailRecorder = C.vision.tracking.TrailRecorder
except Exception as e:
logging.warning("something was wrong, detail:" + str(e) +
"so 'TrailRecorder' can not be loaded")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行提示不用打出来,就单纯pass即可,否则在没有ENABLE_VISION的时候,import fastdeploy会打出来上面这行提示



class PPTracking(FastDeployModel):
Expand Down Expand Up @@ -54,8 +56,17 @@ def predict(self, input_image):
assert input_image is not None, "The input image data is None."
return self._model.predict(input_image)

def bind_trail_recorders(self, val):
self._model.bind_trail_recorders(val)
def bind_recorder(self, val):
""" Binding tracking trail

:param val: (TrailRecorder) trail recorder, which is contained object's id and center point sequence
:return: None
"""
self._model.bind_recorder(val)

def unbind_trail_recorders(self):
self._model.unbind_trail_recorders()
def unbind_recorder(self):
""" cancel binding of tracking trail

:return:
"""
self._model.unbind_recorder()