未验证 提交 714b339b 编写于 作者: F Feng Ni 提交者: GitHub

Fix mot lazy import and warning (#6476)

* [Dy2St]Fix cascade_rcnn export model problem (#6468)

* [Dy2St]Fix cascade_rcnn export model problem

* [Dy2St]Fix cascade_rcnn export model problem

* fix import for mot

* fix import for mot deploy

* fix lazy import mot
上级 0e2e8924
...@@ -81,7 +81,7 @@ PP-Human赋能社区智能精细化管理教程[链接](https://aistudio.baidu.c ...@@ -81,7 +81,7 @@ PP-Human赋能社区智能精细化管理教程[链接](https://aistudio.baidu.c
``` ```
pip install -r requirements.txt pip install -r requirements.txt
# 或手动pip安装MOT相关的库 # 或手动pip安装MOT相关的库
pip install lap sklearn motmetrics openpyxl pip install lap motmetrics sklearn filterpy
``` ```
**注意:** **注意:**
- 预测需确保已安装[ffmpeg](https://ffmpeg.org/ffmpeg.html), Linux(Ubuntu)平台可以直接用以下命令安装:`apt-get update && apt-get install -y ffmpeg` - 预测需确保已安装[ffmpeg](https://ffmpeg.org/ffmpeg.html), Linux(Ubuntu)平台可以直接用以下命令安装:`apt-get update && apt-get install -y ffmpeg`
......
...@@ -49,7 +49,7 @@ PP-Tracking supports GUI predict and deployment. Please refer to this [doc](http ...@@ -49,7 +49,7 @@ PP-Tracking supports GUI predict and deployment. Please refer to this [doc](http
## Installation ## Installation
Install all the related dependencies for MOT: Install all the related dependencies for MOT:
``` ```
pip install lap sklearn motmetrics openpyxl pip install lap motmetrics sklearn filterpy
or or
pip install -r requirements.txt pip install -r requirements.txt
``` ```
......
...@@ -18,8 +18,14 @@ import re ...@@ -18,8 +18,14 @@ import re
import cv2 import cv2
import gc import gc
import numpy as np import numpy as np
from sklearn import preprocessing try:
from sklearn.cluster import AgglomerativeClustering from sklearn import preprocessing
from sklearn.cluster import AgglomerativeClustering
except:
print(
'Warning: Unable to use MTMCT in PP-Human, please install sklearn, for example: `pip install sklearn`'
)
pass
import pandas as pd import pandas as pd
from tqdm import tqdm from tqdm import tqdm
from functools import reduce from functools import reduce
......
...@@ -17,7 +17,6 @@ import paddle ...@@ -17,7 +17,6 @@ import paddle
from paddle.nn import functional as F from paddle.nn import functional as F
import re import re
from shapely.geometry import Polygon from shapely.geometry import Polygon
import pyclipper
import cv2 import cv2
import copy import copy
...@@ -111,6 +110,12 @@ class DBPostProcess(object): ...@@ -111,6 +110,12 @@ class DBPostProcess(object):
return np.array(boxes, dtype=np.int16), scores return np.array(boxes, dtype=np.int16), scores
def unclip(self, box): def unclip(self, box):
try:
import pyclipper
except Exception as e:
raise RuntimeError(
'Unable to use vehicleplate postprocess in PP-Vehicle, please install pyclipper, for example: `pip install pyclipper`, see https://github.com/fonttools/pyclipper'
)
unclip_ratio = self.unclip_ratio unclip_ratio = self.unclip_ratio
poly = Polygon(box) poly = Polygon(box)
distance = poly.area * unclip_ratio / poly.length distance = poly.area * unclip_ratio / poly.length
......
...@@ -15,7 +15,14 @@ ...@@ -15,7 +15,14 @@
This code is based on https://github.com/Zhongdao/Towards-Realtime-MOT/blob/master/tracker/matching.py This code is based on https://github.com/Zhongdao/Towards-Realtime-MOT/blob/master/tracker/matching.py
""" """
import lap try:
import lap
except:
print(
'Warning: Unable to use JDE/FairMOT/ByteTrack, please install lap, for example: `pip install lap`, see https://github.com/gatagat/lap'
)
pass
import scipy import scipy
import numpy as np import numpy as np
from scipy.spatial.distance import cdist from scipy.spatial.distance import cdist
...@@ -53,6 +60,12 @@ def merge_matches(m1, m2, shape): ...@@ -53,6 +60,12 @@ def merge_matches(m1, m2, shape):
def linear_assignment(cost_matrix, thresh): def linear_assignment(cost_matrix, thresh):
try:
import lap
except Exception as e:
raise RuntimeError(
'Unable to use JDE/FairMOT/ByteTrack, please install lap, for example: `pip install lap`, see https://github.com/gatagat/lap'
)
if cost_matrix.size == 0: if cost_matrix.size == 0:
return np.empty( return np.empty(
(0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple( (0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple(
......
...@@ -19,7 +19,13 @@ Note: The following codes are strongly related to camera parameters of the AIC21 ...@@ -19,7 +19,13 @@ Note: The following codes are strongly related to camera parameters of the AIC21
""" """
import numpy as np import numpy as np
from sklearn.cluster import AgglomerativeClustering try:
from sklearn.cluster import AgglomerativeClustering
except:
print(
'Warning: Unable to use MTMCT in PP-Tracking, please install sklearn, for example: `pip install sklearn`'
)
pass
from .utils import get_dire, get_match, get_cid_tid, combin_feature, combin_cluster from .utils import get_dire, get_match, get_cid_tid, combin_feature, combin_cluster
from .utils import normalize, intracam_ignore, visual_rerank from .utils import normalize, intracam_ignore, visual_rerank
......
...@@ -20,7 +20,13 @@ import re ...@@ -20,7 +20,13 @@ import re
import cv2 import cv2
from tqdm import tqdm from tqdm import tqdm
import numpy as np import numpy as np
import motmetrics as mm try:
import motmetrics as mm
except:
print(
'Warning: Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
pass
from functools import reduce from functools import reduce
from .utils import parse_pt_gt, parse_pt, compare_dataframes_mtmc from .utils import parse_pt_gt, parse_pt, compare_dataframes_mtmc
...@@ -201,6 +207,12 @@ def print_mtmct_result(gt_file, pred_file): ...@@ -201,6 +207,12 @@ def print_mtmct_result(gt_file, pred_file):
summary.loc[:, 'idr'] *= 100 summary.loc[:, 'idr'] *= 100
summary.loc[:, 'idf1'] *= 100 summary.loc[:, 'idf1'] *= 100
summary.loc[:, 'mota'] *= 100 summary.loc[:, 'mota'] *= 100
try:
import motmetrics as mm
except Exception as e:
raise RuntimeError(
'Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
print( print(
mm.io.render_summary( mm.io.render_summary(
summary, summary,
......
...@@ -20,9 +20,6 @@ import re ...@@ -20,9 +20,6 @@ import re
import cv2 import cv2
import gc import gc
import numpy as np import numpy as np
from sklearn import preprocessing
from sklearn.cluster import AgglomerativeClustering
import motmetrics as mm
import pandas as pd import pandas as pd
from tqdm import tqdm from tqdm import tqdm
import warnings import warnings
...@@ -195,10 +192,10 @@ def find_topk(a, k, axis=-1, largest=True, sorted=True): ...@@ -195,10 +192,10 @@ def find_topk(a, k, axis=-1, largest=True, sorted=True):
a = np.asanyarray(a) a = np.asanyarray(a)
if largest: if largest:
index_array = np.argpartition(a, axis_size-k, axis=axis) index_array = np.argpartition(a, axis_size - k, axis=axis)
topk_indices = np.take(index_array, -np.arange(k)-1, axis=axis) topk_indices = np.take(index_array, -np.arange(k) - 1, axis=axis)
else: else:
index_array = np.argpartition(a, k-1, axis=axis) index_array = np.argpartition(a, k - 1, axis=axis)
topk_indices = np.take(index_array, np.arange(k), axis=axis) topk_indices = np.take(index_array, np.arange(k), axis=axis)
topk_values = np.take_along_axis(a, topk_indices, axis=axis) topk_values = np.take_along_axis(a, topk_indices, axis=axis)
if sorted: if sorted:
...@@ -228,7 +225,8 @@ def batch_numpy_topk(qf, gf, k1, N=6000): ...@@ -228,7 +225,8 @@ def batch_numpy_topk(qf, gf, k1, N=6000):
temp_qd = temp_qd / (np.max(temp_qd, axis=0)[0]) temp_qd = temp_qd / (np.max(temp_qd, axis=0)[0])
temp_qd = temp_qd.T temp_qd = temp_qd.T
initial_rank.append( initial_rank.append(
find_topk(temp_qd, k=k1, axis=1, largest=False, sorted=True)[1]) find_topk(
temp_qd, k=k1, axis=1, largest=False, sorted=True)[1])
del temp_qd del temp_qd
del temp_gf del temp_gf
del temp_qf del temp_qf
...@@ -374,6 +372,12 @@ def visual_rerank(prb_feats, ...@@ -374,6 +372,12 @@ def visual_rerank(prb_feats,
def normalize(nparray, axis=0): def normalize(nparray, axis=0):
try:
from sklearn import preprocessing
except Exception as e:
raise RuntimeError(
'Unable to use sklearn in MTMCT in PP-Tracking, please install sklearn, for example: `pip install sklearn`'
)
nparray = preprocessing.normalize(nparray, norm='l2', axis=axis) nparray = preprocessing.normalize(nparray, norm='l2', axis=axis)
return nparray return nparray
...@@ -453,6 +457,12 @@ def parse_pt_gt(mot_feature): ...@@ -453,6 +457,12 @@ def parse_pt_gt(mot_feature):
# eval result # eval result
def compare_dataframes_mtmc(gts, ts): def compare_dataframes_mtmc(gts, ts):
try:
import motmetrics as mm
except Exception as e:
raise RuntimeError(
'Unable to use motmetrics in MTMCT in PP-Tracking, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
"""Compute ID-based evaluation metrics for MTMCT """Compute ID-based evaluation metrics for MTMCT
Return: Return:
df (pandas.DataFrame): Results of the evaluations in a df with only the 'idf1', 'idp', and 'idr' columns. df (pandas.DataFrame): Results of the evaluations in a df with only the 'idf1', 'idp', and 'idr' columns.
...@@ -528,6 +538,12 @@ def get_labels(cid_tid_dict, ...@@ -528,6 +538,12 @@ def get_labels(cid_tid_dict,
use_ff=True, use_ff=True,
use_rerank=True, use_rerank=True,
use_st_filter=False): use_st_filter=False):
try:
from sklearn.cluster import AgglomerativeClustering
except Exception as e:
raise RuntimeError(
'Unable to use sklearn in MTMCT in PP-Tracking, please install sklearn, for example: `pip install sklearn`'
)
# 1st cluster # 1st cluster
sim_matrix = get_sim_matrix( sim_matrix = get_sim_matrix(
cid_tid_dict, cid_tid_dict,
......
...@@ -21,7 +21,13 @@ Note: The following codes are strongly related to zone of the AIC21 test-set S06 ...@@ -21,7 +21,13 @@ Note: The following codes are strongly related to zone of the AIC21 test-set S06
import os import os
import cv2 import cv2
import numpy as np import numpy as np
from sklearn.cluster import AgglomerativeClustering try:
from sklearn.cluster import AgglomerativeClustering
except:
print(
'Warning: Unable to use MTMCT in PP-Tracking, please install sklearn, for example: `pip install sklearn`'
)
pass
BBOX_B = 10 / 15 BBOX_B = 10 / 15
......
...@@ -16,7 +16,13 @@ This code is based on https://github.com/noahcao/OC_SORT/blob/master/trackers/oc ...@@ -16,7 +16,13 @@ This code is based on https://github.com/noahcao/OC_SORT/blob/master/trackers/oc
""" """
import numpy as np import numpy as np
from filterpy.kalman import KalmanFilter try:
from filterpy.kalman import KalmanFilter
except:
print(
'Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy'
)
pass
from ..matching.ocsort_matching import associate, linear_assignment, iou_batch from ..matching.ocsort_matching import associate, linear_assignment, iou_batch
...@@ -84,6 +90,12 @@ class KalmanBoxTracker(object): ...@@ -84,6 +90,12 @@ class KalmanBoxTracker(object):
count = 0 count = 0
def __init__(self, bbox, delta_t=3): def __init__(self, bbox, delta_t=3):
try:
from filterpy.kalman import KalmanFilter
except Exception as e:
raise RuntimeError(
'Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy'
)
self.kf = KalmanFilter(dim_x=7, dim_z=4) self.kf = KalmanFilter(dim_x=7, dim_z=4)
self.kf.F = np.array([[1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], self.kf.F = np.array([[1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0],
......
...@@ -21,16 +21,21 @@ import copy ...@@ -21,16 +21,21 @@ import copy
import sys import sys
import math import math
from collections import defaultdict from collections import defaultdict
from motmetrics.math_util import quiet_divide
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from .metrics import Metric from .metrics import Metric
import motmetrics as mm try:
import openpyxl import motmetrics as mm
metrics = mm.metrics.motchallenge_metrics from motmetrics.math_util import quiet_divide
mh = mm.metrics.create() metrics = mm.metrics.motchallenge_metrics
mh = mm.metrics.create()
except:
print(
'Warning: Unable to use MCMOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
pass
from ppdet.utils.logger import setup_logger from ppdet.utils.logger import setup_logger
logger = setup_logger(__name__) logger = setup_logger(__name__)
...@@ -300,6 +305,13 @@ class MCMOTEvaluator(object): ...@@ -300,6 +305,13 @@ class MCMOTEvaluator(object):
self.num_classes = num_classes self.num_classes = num_classes
self.load_annotations() self.load_annotations()
try:
import motmetrics as mm
mm.lap.default_solver = 'lap'
except Exception as e:
raise RuntimeError(
'Unable to use MCMOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
self.reset_accumulator() self.reset_accumulator()
self.class_accs = [] self.class_accs = []
...@@ -314,13 +326,9 @@ class MCMOTEvaluator(object): ...@@ -314,13 +326,9 @@ class MCMOTEvaluator(object):
) )
def reset_accumulator(self): def reset_accumulator(self):
import motmetrics as mm
mm.lap.default_solver = 'lap'
self.acc = mm.MOTAccumulator(auto_id=True) self.acc = mm.MOTAccumulator(auto_id=True)
def eval_frame_dict(self, trk_objs, gt_objs, rtn_events=False, union=False): def eval_frame_dict(self, trk_objs, gt_objs, rtn_events=False, union=False):
import motmetrics as mm
mm.lap.default_solver = 'lap'
if union: if union:
trk_tlwhs, trk_ids, trk_cls = unzip_objs_cls(trk_objs)[:3] trk_tlwhs, trk_ids, trk_cls = unzip_objs_cls(trk_objs)[:3]
gt_tlwhs, gt_ids, gt_cls = unzip_objs_cls(gt_objs)[:3] gt_tlwhs, gt_ids, gt_cls = unzip_objs_cls(gt_objs)[:3]
...@@ -394,9 +402,6 @@ class MCMOTEvaluator(object): ...@@ -394,9 +402,6 @@ class MCMOTEvaluator(object):
names, names,
metrics=('mota', 'num_switches', 'idp', 'idr', 'idf1', metrics=('mota', 'num_switches', 'idp', 'idr', 'idf1',
'precision', 'recall')): 'precision', 'recall')):
import motmetrics as mm
mm.lap.default_solver = 'lap'
names = copy.deepcopy(names) names = copy.deepcopy(names)
if metrics is None: if metrics is None:
metrics = mm.metrics.motchallenge_metrics metrics = mm.metrics.motchallenge_metrics
......
...@@ -28,6 +28,15 @@ from .map_utils import ap_per_class ...@@ -28,6 +28,15 @@ from .map_utils import ap_per_class
from .metrics import Metric from .metrics import Metric
from .munkres import Munkres from .munkres import Munkres
try:
import motmetrics as mm
mm.lap.default_solver = 'lap'
except:
print(
'Warning: Unable to use MOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
pass
from ppdet.utils.logger import setup_logger from ppdet.utils.logger import setup_logger
logger = setup_logger(__name__) logger = setup_logger(__name__)
...@@ -114,6 +123,13 @@ class MOTEvaluator(object): ...@@ -114,6 +123,13 @@ class MOTEvaluator(object):
self.data_type = data_type self.data_type = data_type
self.load_annotations() self.load_annotations()
try:
import motmetrics as mm
mm.lap.default_solver = 'lap'
except Exception as e:
raise RuntimeError(
'Unable to use MOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics'
)
self.reset_accumulator() self.reset_accumulator()
def load_annotations(self): def load_annotations(self):
...@@ -129,13 +145,9 @@ class MOTEvaluator(object): ...@@ -129,13 +145,9 @@ class MOTEvaluator(object):
gt_filename, is_ignore=True) gt_filename, is_ignore=True)
def reset_accumulator(self): def reset_accumulator(self):
import motmetrics as mm
mm.lap.default_solver = 'lap'
self.acc = mm.MOTAccumulator(auto_id=True) self.acc = mm.MOTAccumulator(auto_id=True)
def eval_frame(self, frame_id, trk_tlwhs, trk_ids, rtn_events=False): def eval_frame(self, frame_id, trk_tlwhs, trk_ids, rtn_events=False):
import motmetrics as mm
mm.lap.default_solver = 'lap'
# results # results
trk_tlwhs = np.copy(trk_tlwhs) trk_tlwhs = np.copy(trk_tlwhs)
trk_ids = np.copy(trk_ids) trk_ids = np.copy(trk_ids)
...@@ -193,8 +205,6 @@ class MOTEvaluator(object): ...@@ -193,8 +205,6 @@ class MOTEvaluator(object):
names, names,
metrics=('mota', 'num_switches', 'idp', 'idr', 'idf1', metrics=('mota', 'num_switches', 'idp', 'idr', 'idf1',
'precision', 'recall')): 'precision', 'recall')):
import motmetrics as mm
mm.lap.default_solver = 'lap'
names = copy.deepcopy(names) names = copy.deepcopy(names)
if metrics is None: if metrics is None:
metrics = mm.metrics.motchallenge_metrics metrics = mm.metrics.motchallenge_metrics
...@@ -231,8 +241,6 @@ class MOTMetric(Metric): ...@@ -231,8 +241,6 @@ class MOTMetric(Metric):
self.result_root = result_root self.result_root = result_root
def accumulate(self): def accumulate(self):
import motmetrics as mm
import openpyxl
metrics = mm.metrics.motchallenge_metrics metrics = mm.metrics.motchallenge_metrics
mh = mm.metrics.create() mh = mm.metrics.create()
summary = self.MOTEvaluator.get_summary(self.accs, self.seqs, metrics) summary = self.MOTEvaluator.get_summary(self.accs, self.seqs, metrics)
......
...@@ -15,7 +15,14 @@ ...@@ -15,7 +15,14 @@
This code is based on https://github.com/Zhongdao/Towards-Realtime-MOT/blob/master/tracker/matching.py This code is based on https://github.com/Zhongdao/Towards-Realtime-MOT/blob/master/tracker/matching.py
""" """
import lap try:
import lap
except:
print(
'Warning: Unable to use JDE/FairMOT/ByteTrack, please install lap, for example: `pip install lap`, see https://github.com/gatagat/lap'
)
pass
import scipy import scipy
import numpy as np import numpy as np
from scipy.spatial.distance import cdist from scipy.spatial.distance import cdist
...@@ -53,6 +60,12 @@ def merge_matches(m1, m2, shape): ...@@ -53,6 +60,12 @@ def merge_matches(m1, m2, shape):
def linear_assignment(cost_matrix, thresh): def linear_assignment(cost_matrix, thresh):
try:
import lap
except Exception as e:
raise RuntimeError(
'Unable to use JDE/FairMOT/ByteTrack, please install lap, for example: `pip install lap`, see https://github.com/gatagat/lap'
)
if cost_matrix.size == 0: if cost_matrix.size == 0:
return np.empty( return np.empty(
(0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple( (0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple(
......
...@@ -16,7 +16,13 @@ This code is based on https://github.com/noahcao/OC_SORT/blob/master/trackers/oc ...@@ -16,7 +16,13 @@ This code is based on https://github.com/noahcao/OC_SORT/blob/master/trackers/oc
""" """
import numpy as np import numpy as np
from filterpy.kalman import KalmanFilter try:
from filterpy.kalman import KalmanFilter
except:
print(
'Warning: Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy'
)
pass
from ..matching.ocsort_matching import associate, linear_assignment, iou_batch from ..matching.ocsort_matching import associate, linear_assignment, iou_batch
from ppdet.core.workspace import register, serializable from ppdet.core.workspace import register, serializable
...@@ -85,6 +91,12 @@ class KalmanBoxTracker(object): ...@@ -85,6 +91,12 @@ class KalmanBoxTracker(object):
count = 0 count = 0
def __init__(self, bbox, delta_t=3): def __init__(self, bbox, delta_t=3):
try:
from filterpy.kalman import KalmanFilter
except Exception as e:
raise RuntimeError(
'Unable to use OC-SORT, please install filterpy, for example: `pip install filterpy`, see https://github.com/rlabbe/filterpy'
)
self.kf = KalmanFilter(dim_x=7, dim_z=4) self.kf = KalmanFilter(dim_x=7, dim_z=4)
self.kf.F = np.array([[1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], self.kf.F = np.array([[1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0],
......
...@@ -10,11 +10,12 @@ Cython ...@@ -10,11 +10,12 @@ Cython
pycocotools pycocotools
#xtcocotools==1.6 #only for crowdpose #xtcocotools==1.6 #only for crowdpose
setuptools>=42.0.0 setuptools>=42.0.0
# for vehicleplate
pyclipper pyclipper
# for mot # for mot
lap lap
sklearn
motmetrics motmetrics
openpyxl sklearn
filterpy filterpy
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册