code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def predict(self, repeats=1): ''' Args: repeats (int): repeat number for prediction Returns: results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] ...
Args: repeats (int): repeat number for prediction Returns: results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] MaskRCNN's results include 'mas...
predict
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_infer.py
Apache-2.0
def create_inputs(imgs, im_info): """generate input for different model type Args: imgs (list(numpy)): list of image (np.ndarray) im_info (list(dict)): list of image info Returns: inputs (dict): input of model """ inputs = {} inputs['image'] = np.stack(imgs, axis=0).astyp...
generate input for different model type Args: imgs (list(numpy)): list of image (np.ndarray) im_info (list(dict)): list of image info Returns: inputs (dict): input of model
create_inputs
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_infer.py
Apache-2.0
def check_model(self, yml_conf): """ Raises: ValueError: loaded model not in supported model type """ for support_model in KEYPOINT_SUPPORT_MODELS: if support_model in yml_conf['arch']: return True raise ValueError("Unsupported arch: {}, e...
Raises: ValueError: loaded model not in supported model type
check_model
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_infer.py
Apache-2.0
def warp_affine_joints(joints, mat): """Apply affine transformation defined by the transform matrix on the joints. Args: joints (np.ndarray[..., 2]): Origin coordinate of joints. mat (np.ndarray[3, 2]): The affine matrix. Returns: matrix (np.ndarray[..., 2]): Result coordinate ...
Apply affine transformation defined by the transform matrix on the joints. Args: joints (np.ndarray[..., 2]): Origin coordinate of joints. mat (np.ndarray[3, 2]): The affine matrix. Returns: matrix (np.ndarray[..., 2]): Result coordinate of joints.
warp_affine_joints
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
Apache-2.0
def get_max_preds(self, heatmaps): """get predictions from score maps Args: heatmaps: numpy.ndarray([batch_size, num_joints, height, width]) Returns: preds: numpy.ndarray([batch_size, num_joints, 2]), keypoints coords maxvals: numpy.ndarray([batch_size, num_...
get predictions from score maps Args: heatmaps: numpy.ndarray([batch_size, num_joints, height, width]) Returns: preds: numpy.ndarray([batch_size, num_joints, 2]), keypoints coords maxvals: numpy.ndarray([batch_size, num_joints, 2]), the maximum confidence of the key...
get_max_preds
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
Apache-2.0
def dark_postprocess(self, hm, coords, kernelsize): """ refer to https://github.com/ilovepose/DarkPose/lib/core/inference.py """ hm = self.gaussian_blur(hm, kernelsize) hm = np.maximum(hm, 1e-10) hm = np.log(hm) for n in range(coords.shape[0]): for p ...
refer to https://github.com/ilovepose/DarkPose/lib/core/inference.py
dark_postprocess
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
Apache-2.0
def get_final_preds(self, heatmaps, center, scale, kernelsize=3): """the highest heatvalue location with a quarter offset in the direction from the highest response to the second highest response. Args: heatmaps (numpy.ndarray): The predicted heatmaps center (numpy.ndarr...
the highest heatvalue location with a quarter offset in the direction from the highest response to the second highest response. Args: heatmaps (numpy.ndarray): The predicted heatmaps center (numpy.ndarray): The boxes center scale (numpy.ndarray): The scale factor ...
get_final_preds
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_postprocess.py
Apache-2.0
def get_affine_transform(center, input_size, rot, output_size, shift=(0., 0.), inv=False): """Get the affine transform matrix, given the center/scale/rot/output_size. Args: cente...
Get the affine transform matrix, given the center/scale/rot/output_size. Args: center (np.ndarray[2, ]): Center of the bounding box (x, y). scale (np.ndarray[2, ]): Scale of the bounding box wrt [width, height]. rot (float): Rotation angle (degree). output_size (np.ndarr...
get_affine_transform
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
Apache-2.0
def get_warp_matrix(theta, size_input, size_dst, size_target): """This code is based on https://github.com/open-mmlab/mmpose/blob/master/mmpose/core/post_processing/post_transforms.py Calculate the transformation matrix under the constraint of unbiased. Paper ref: Huang et al. The Devil is in ...
This code is based on https://github.com/open-mmlab/mmpose/blob/master/mmpose/core/post_processing/post_transforms.py Calculate the transformation matrix under the constraint of unbiased. Paper ref: Huang et al. The Devil is in the Details: Delving into Unbiased Data Processing for Human Pose ...
get_warp_matrix
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
Apache-2.0
def rotate_point(pt, angle_rad): """Rotate a point by an angle. Args: pt (list[float]): 2 dimensional point to be rotated angle_rad (float): rotation angle by radian Returns: list[float]: Rotated point. """ assert len(pt) == 2 sn, cs = np.sin(angle_rad), np.cos(angle_ra...
Rotate a point by an angle. Args: pt (list[float]): 2 dimensional point to be rotated angle_rad (float): rotation angle by radian Returns: list[float]: Rotated point.
rotate_point
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
Apache-2.0
def _get_3rd_point(a, b): """To calculate the affine matrix, three pairs of points are required. This function is used to get the 3rd point, given 2D points a & b. The 3rd point is defined by rotating vector `a - b` by 90 degrees anticlockwise, using b as the rotation center. Args: a (np.n...
To calculate the affine matrix, three pairs of points are required. This function is used to get the 3rd point, given 2D points a & b. The 3rd point is defined by rotating vector `a - b` by 90 degrees anticlockwise, using b as the rotation center. Args: a (np.ndarray): point(x,y) b (np...
_get_3rd_point
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/keypoint_preprocess.py
Apache-2.0
def hard_nms(box_scores, iou_threshold, top_k=-1, candidate_size=200): """ Args: box_scores (N, 5): boxes in corner-form and probabilities. iou_threshold: intersection over union threshold. top_k: keep top_k results. If k <= 0, keep all the results. candidate_size: only consider ...
Args: box_scores (N, 5): boxes in corner-form and probabilities. iou_threshold: intersection over union threshold. top_k: keep top_k results. If k <= 0, keep all the results. candidate_size: only consider the candidates with the highest scores. Returns: picked: a list o...
hard_nms
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/picodet_postprocess.py
Apache-2.0
def iou_of(boxes0, boxes1, eps=1e-5): """Return intersection-over-union (Jaccard index) of boxes. Args: boxes0 (N, 4): ground truth boxes. boxes1 (N or 1, 4): predicted boxes. eps: a small number to avoid 0 as denominator. Returns: iou (N): IoU values. """ overlap_lef...
Return intersection-over-union (Jaccard index) of boxes. Args: boxes0 (N, 4): ground truth boxes. boxes1 (N or 1, 4): predicted boxes. eps: a small number to avoid 0 as denominator. Returns: iou (N): IoU values.
iou_of
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/picodet_postprocess.py
Apache-2.0
def area_of(left_top, right_bottom): """Compute the areas of rectangles given two corners. Args: left_top (N, 2): left top corner. right_bottom (N, 2): right bottom corner. Returns: area (N): return the area. """ hw = np.clip(right_bottom - left_top, 0.0, None) return hw[...
Compute the areas of rectangles given two corners. Args: left_top (N, 2): left top corner. right_bottom (N, 2): right bottom corner. Returns: area (N): return the area.
area_of
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/picodet_postprocess.py
Apache-2.0
def decode_image(im_file, im_info): """read rgb image Args: im_file (str|np.ndarray): input can be image path or np.ndarray im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ if isinstance(...
read rgb image Args: im_file (str|np.ndarray): input can be image path or np.ndarray im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
decode_image
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ im_channel = im.shape[2...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def generate_scale(self, img): """ Args: img (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y """ limit_side_len = self.limit_side_len h, w, c = img.shape # limit the...
Args: img (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y
generate_scale
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ assert len(self.target_...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def generate_scale(self, im): """ Args: im (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y """ origin_shape = im.shape[:2] im_c = im.shape[2] if self.keep_ratio: ...
Args: im (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y
generate_scale
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, img): """ Performs resize operations. Args: img (PIL.Image): a PIL.Image. return: resized_img: a PIL.Image after scaling. """ result_img = None if isinstance(img, np.ndarray): h, w, _ = img.shape eli...
Performs resize operations. Args: img (PIL.Image): a PIL.Image. return: resized_img: a PIL.Image after scaling.
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ im = im.astype(np.float...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ im = im.transpose((2, 0...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ coarsest_stride = self....
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __init__(self, target_size): """ Resize image to target size, convert normalized xywh to pixel xyxy format ([x_center, y_center, width, height] -> [x0, y0, x1, y1]). Args: target_size (int|list): image target size. """ super(LetterBoxResize, self).__init__...
Resize image to target size, convert normalized xywh to pixel xyxy format ([x_center, y_center, width, height] -> [x0, y0, x1, y1]). Args: target_size (int|list): image target size.
__init__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ assert len(self.target_...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __init__(self, size, fill_value=[114.0, 114.0, 114.0]): """ Pad image to a specified size. Args: size (list[int]): image target size fill_value (list[float]): rgb value of pad area, default (114.0, 114.0, 114.0) """ super(Pad, self).__init__() ...
Pad image to a specified size. Args: size (list[int]): image target size fill_value (list[float]): rgb value of pad area, default (114.0, 114.0, 114.0)
__init__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ img = cv2.cvtColor(im, ...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/preprocess.py
Apache-2.0
def get_current_memory_mb(): """ It is used to Obtain the memory usage of the CPU and GPU during the running of the program. And this function Current program is time-consuming. """ import pynvml import psutil import GPUtil gpu_id = int(os.environ.get('CUDA_VISIBLE_DEVICES', 0)) pid...
It is used to Obtain the memory usage of the CPU and GPU during the running of the program. And this function Current program is time-consuming.
get_current_memory_mb
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/utils.py
Apache-2.0
def nms(dets, match_threshold=0.6, match_metric='iou'): """ Apply NMS to avoid detecting too many overlapping bounding boxes. Args: dets: shape [N, 5], [score, x1, y1, x2, y2] match_metric: 'iou' or 'ios' match_threshold: overlap thresh for match metric. """ if de...
Apply NMS to avoid detecting too many overlapping bounding boxes. Args: dets: shape [N, 5], [score, x1, y1, x2, y2] match_metric: 'iou' or 'ios' match_threshold: overlap thresh for match metric.
nms
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/utils.py
Apache-2.0
def visualize_box_mask(im, results, labels, threshold=0.5): """ Args: im (str/np.ndarray): path of image/np.ndarray read by cv2 results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] ...
Args: im (str/np.ndarray): path of image/np.ndarray read by cv2 results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] MaskRCNN's results include 'masks': np.ndarray: ...
visualize_box_mask
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/visualize.py
Apache-2.0
def get_color_map_list(num_classes): """ Args: num_classes (int): number of class Returns: color_map (list): RGB color list """ color_map = num_classes * [0, 0, 0] for i in range(0, num_classes): j = 0 lab = i while lab: color_map[i * 3] |= (((...
Args: num_classes (int): number of class Returns: color_map (list): RGB color list
get_color_map_list
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/visualize.py
Apache-2.0
def draw_mask(im, np_boxes, np_masks, labels, threshold=0.5): """ Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] np_masks (np.ndarray): shape:[N, im_h, im_w] labels (...
Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] np_masks (np.ndarray): shape:[N, im_h, im_w] labels (list): labels:['class1', ..., 'classn'] threshold (float): th...
draw_mask
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/visualize.py
Apache-2.0
def draw_box(im, np_boxes, labels, threshold=0.5): """ Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] labels (list): labels:['class1', ..., 'classn'] ...
Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] labels (list): labels:['class1', ..., 'classn'] threshold (float): threshold of box Returns: ...
draw_box
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/visualize.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeats number for prediction Returns: result (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] ...
Args: repeats (int): repeats number for prediction Returns: result (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] MaskRCNN's result include 'mask...
predict
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/attr_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/attr_infer.py
Apache-2.0
def is_url(path): """ Whether path is URL. Args: path (string): URL string or not. """ return path.startswith('http://') \ or path.startswith('https://') \ or path.startswith('ppdet://')
Whether path is URL. Args: path (string): URL string or not.
is_url
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def _download(url, path, md5sum=None): """ Download from url, save to path. url (str): download url path (str): download to given path """ if not osp.exists(path): os.makedirs(path) fname = osp.split(url)[-1] fullname = osp.join(path, fname) retry_cnt = 0 while not (osp....
Download from url, save to path. url (str): download url path (str): download to given path
_download
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def _move_and_merge_tree(src, dst): """ Move src directory to dst, if dst is already exists, merge src to dst """ if not osp.exists(dst): shutil.move(src, dst) elif osp.isfile(src): shutil.move(src, dst) else: for fp in os.listdir(src): src_fp = osp.join(s...
Move src directory to dst, if dst is already exists, merge src to dst
_move_and_merge_tree
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def _decompress(fname): """ Decompress for zip and tar file """ # For protecting decompressing interupted, # decompress to fpath_tmp directory firstly, if decompress # successed, move decompress files to fpath and delete # fpath_tmp and remove download compress file. fpath = osp.split(f...
Decompress for zip and tar file
_decompress
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def get_path(url, root_dir=WEIGHTS_HOME, md5sum=None, check_exist=True): """ Download from given url to root_dir. if file or directory specified by url is exists under root_dir, return the path directly, otherwise download from url and decompress it, return the path. url (str): download url root...
Download from given url to root_dir. if file or directory specified by url is exists under root_dir, return the path directly, otherwise download from url and decompress it, return the path. url (str): download url root_dir (str): root dir for downloading md5sum (str): md5 sum of download packa...
get_path
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def get_weights_path(url): """Get weights path from WEIGHTS_HOME, if not exists, download it from url. """ url = parse_url(url) md5sum = None if url in MODEL_URL_MD5_DICT.keys(): md5sum = MODEL_URL_MD5_DICT[url] path, _ = get_path(url, WEIGHTS_HOME, md5sum) return path
Get weights path from WEIGHTS_HOME, if not exists, download it from url.
get_weights_path
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/download.py
Apache-2.0
def get_model_dir(cfg): """ Auto download inference model if the model_path is a url link. Otherwise it will use the model_path directly. """ for key in cfg.keys(): if type(cfg[key]) == dict and \ ("enable" in cfg[key].keys() and cfg[key]['enable'] or "...
Auto download inference model if the model_path is a url link. Otherwise it will use the model_path directly.
get_model_dir
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/pipeline.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/pipeline.py
Apache-2.0
def get_test_images(infer_dir, infer_img): """ Get image path list in TEST mode """ assert infer_img is not None or infer_dir is not None, \ "--infer_img or --infer_dir should be set" assert infer_img is None or os.path.isfile(infer_img), \ "{} is not a file".format(infer_img) ...
Get image path list in TEST mode
get_test_images
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/pipe_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/pipe_utils.py
Apache-2.0
def refine_keypoint_coordinary(kpts, bbox, coord_size): """ This function is used to adjust coordinate values to a fixed scale. """ tl = bbox[:, 0:2] wh = bbox[:, 2:] - tl tl = np.expand_dims(np.transpose(tl, (1, 0)), (2, 3)) wh = np.expand_dims(np.transpose(wh, (1, 0)), (2, 3)) targ...
This function is used to adjust coordinate values to a fixed scale.
refine_keypoint_coordinary
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/pipe_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/pipe_utils.py
Apache-2.0
def boxes_from_bitmap(self, pred, _bitmap, dest_width, dest_height): ''' _bitmap: single map with shape (1, H, W), whose values are binarized as {0, 1} ''' bitmap = _bitmap height, width = bitmap.shape outs = cv2.findContours((bitmap * 255).astype(np.uin...
_bitmap: single map with shape (1, H, W), whose values are binarized as {0, 1}
boxes_from_bitmap
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
Apache-2.0
def box_score_fast(self, bitmap, _box): ''' box_score_fast: use bbox mean score as the mean score ''' h, w = bitmap.shape[:2] box = _box.copy() xmin = np.clip(np.floor(box[:, 0].min()).astype(np.int), 0, w - 1) xmax = np.clip(np.ceil(box[:, 0].max()).astype(np.int...
box_score_fast: use bbox mean score as the mean score
box_score_fast
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
Apache-2.0
def box_score_slow(self, bitmap, contour): ''' box_score_slow: use polyon mean score as the mean score ''' h, w = bitmap.shape[:2] contour = contour.copy() contour = np.reshape(contour, (-1, 2)) xmin = np.clip(np.min(contour[:, 0]), 0, w - 1) xmax = np.cl...
box_score_slow: use polyon mean score as the mean score
box_score_slow
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
Apache-2.0
def decode(self, text_index, text_prob=None, is_remove_duplicate=False): """ convert text-index into text-label. """ result_list = [] ignored_tokens = self.get_ignored_tokens() batch_size = len(text_index) for batch_idx in range(batch_size): selection = np.ones(len(te...
convert text-index into text-label.
decode
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicleplate_postprocess.py
Apache-2.0
def draw_ocr(image, boxes, txts=None, scores=None, drop_score=0.5, font_path="./doc/fonts/simfang.ttf"): """ Visualize the results of OCR detection and recognition args: image(Image|array): RGB image boxes(list): boxes with sha...
Visualize the results of OCR detection and recognition args: image(Image|array): RGB image boxes(list): boxes with shape(N, 4, 2) txts(list): the texts scores(list): txxs corresponding scores drop_score(float): only scores greater than drop_threshold will be visualized ...
draw_ocr
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
Apache-2.0
def str_count(s): """ Count the number of Chinese characters, a single English character and a single number equal to half the length of Chinese characters. args: s(string): the input of string return(int): the number of Chinese characters """ import string count_zh =...
Count the number of Chinese characters, a single English character and a single number equal to half the length of Chinese characters. args: s(string): the input of string return(int): the number of Chinese characters
str_count
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
Apache-2.0
def text_visual(texts, scores, img_h=400, img_w=600, threshold=0., font_path="./doc/simfang.ttf"): """ create new blank img and draw txt on it args: texts(list): the text will be draw scores(list|None): correspon...
create new blank img and draw txt on it args: texts(list): the text will be draw scores(list|None): corresponding score of each txt img_h(int): the height of blank img img_w(int): the width of blank img font_path: the path of font which is used to draw text return(ar...
text_visual
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
Apache-2.0
def get_rotate_crop_image(img, points): ''' img_height, img_width = img.shape[0:2] left = int(np.min(points[:, 0])) right = int(np.max(points[:, 0])) top = int(np.min(points[:, 1])) bottom = int(np.max(points[:, 1])) img_crop = img[top:bottom, left:right, :].copy() points[:, 0] = points[...
img_height, img_width = img.shape[0:2] left = int(np.min(points[:, 0])) right = int(np.max(points[:, 0])) top = int(np.min(points[:, 1])) bottom = int(np.max(points[:, 1])) img_crop = img[top:bottom, left:right, :].copy() points[:, 0] = points[:, 0] - left points[:, 1] = points[:, 1] - ...
get_rotate_crop_image
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pipeline/ppvehicle/vehicle_plateutils.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeats number for prediction Returns: result (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] ''' ...
Args: repeats (int): repeats number for prediction Returns: result (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max]
predict
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
Apache-2.0
def create_inputs(imgs, im_info): """generate input for different model type Args: imgs (list(numpy)): list of images (np.ndarray) im_info (list(dict)): list of image info Returns: inputs (dict): input of model """ inputs = {} im_shape = [] scale_factor = [] if l...
generate input for different model type Args: imgs (list(numpy)): list of images (np.ndarray) im_info (list(dict)): list of image info Returns: inputs (dict): input of model
create_inputs
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
Apache-2.0
def check_model(self, yml_conf): """ Raises: ValueError: loaded model not in supported model type """ for support_model in SUPPORT_MODELS: if support_model in yml_conf['arch']: return True raise ValueError("Unsupported arch: {}, expect {}"...
Raises: ValueError: loaded model not in supported model type
check_model
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
Apache-2.0
def load_predictor(model_dir, run_mode='paddle', batch_size=1, device='CPU', min_subgraph_size=3, use_dynamic_shape=False, trt_min_shape=1, trt_max_shape=1280, trt_opt_...
set AnalysisConfig, generate AnalysisPredictor Args: model_dir (str): root path of __model__ and __params__ device (str): Choose the device you want to run, it can be: CPU/GPU/XPU, default is CPU run_mode (str): mode of running(paddle/trt_fp32/trt_fp16/trt_int8) use_dynamic_shape (bo...
load_predictor
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
Apache-2.0
def get_test_images(infer_dir, infer_img): """ Get image path list in TEST mode """ assert infer_img is not None or infer_dir is not None, \ "--infer_img or --infer_dir should be set" assert infer_img is None or os.path.isfile(infer_img), \ "{} is not a file".format(infer_img) ...
Get image path list in TEST mode
get_test_images
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/det_infer.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeats number for prediction Returns: result (dict): include 'pred_dets': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] ...
Args: repeats (int): repeats number for prediction Returns: result (dict): include 'pred_dets': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] FairMOT(JDE)'s result inclu...
predict
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot_jde_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot_jde_infer.py
Apache-2.0
def get_current_memory_mb(): """ It is used to Obtain the memory usage of the CPU and GPU during the running of the program. And this function Current program is time-consuming. """ import pynvml import psutil import GPUtil gpu_id = int(os.environ.get('CUDA_VISIBLE_DEVICES', 0)) pid...
It is used to Obtain the memory usage of the CPU and GPU during the running of the program. And this function Current program is time-consuming.
get_current_memory_mb
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot_utils.py
Apache-2.0
def hard_nms(box_scores, iou_threshold, top_k=-1, candidate_size=200): """ Args: box_scores (N, 5): boxes in corner-form and probabilities. iou_threshold: intersection over union threshold. top_k: keep top_k results. If k <= 0, keep all the results. candidate_size: only consider ...
Args: box_scores (N, 5): boxes in corner-form and probabilities. iou_threshold: intersection over union threshold. top_k: keep top_k results. If k <= 0, keep all the results. candidate_size: only consider the candidates with the highest scores. Returns: picked: a list o...
hard_nms
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
Apache-2.0
def iou_of(boxes0, boxes1, eps=1e-5): """Return intersection-over-union (Jaccard index) of boxes. Args: boxes0 (N, 4): ground truth boxes. boxes1 (N or 1, 4): predicted boxes. eps: a small number to avoid 0 as denominator. Returns: iou (N): IoU values. """ overlap_lef...
Return intersection-over-union (Jaccard index) of boxes. Args: boxes0 (N, 4): ground truth boxes. boxes1 (N or 1, 4): predicted boxes. eps: a small number to avoid 0 as denominator. Returns: iou (N): IoU values.
iou_of
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
Apache-2.0
def area_of(left_top, right_bottom): """Compute the areas of rectangles given two corners. Args: left_top (N, 2): left top corner. right_bottom (N, 2): right bottom corner. Returns: area (N): return the area. """ hw = np.clip(right_bottom - left_top, 0.0, None) return hw[...
Compute the areas of rectangles given two corners. Args: left_top (N, 2): left top corner. right_bottom (N, 2): right bottom corner. Returns: area (N): return the area.
area_of
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/picodet_postprocess.py
Apache-2.0
def decode_image(im_file, im_info): """read rgb image Args: im_file (str|np.ndarray): input can be image path or np.ndarray im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ if isinstance(...
read rgb image Args: im_file (str|np.ndarray): input can be image path or np.ndarray im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
decode_image
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ assert len(self.target_...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def generate_scale(self, im): """ Args: im (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y """ origin_shape = im.shape[:2] im_c = im.shape[2] if self.keep_ratio: ...
Args: im (np.ndarray): image (np.ndarray) Returns: im_scale_x: the resize ratio of X im_scale_y: the resize ratio of Y
generate_scale
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ im = im.astype(np.float...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ im = im.transpose((2, 0...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ coarsest_stride = self....
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __init__(self, target_size): """ Resize image to target size, convert normalized xywh to pixel xyxy format ([x_center, y_center, width, height] -> [x0, y0, x1, y1]). Args: target_size (int|list): image target size. """ super(LetterBoxResize, self).__init__...
Resize image to target size, convert normalized xywh to pixel xyxy format ([x_center, y_center, width, height] -> [x0, y0, x1, y1]). Args: target_size (int|list): image target size.
__init__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __call__(self, im, im_info): """ Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image """ assert len(self.target_...
Args: im (np.ndarray): image (np.ndarray) im_info (dict): info of image Returns: im (np.ndarray): processed image (np.ndarray) im_info (dict): info of processed image
__call__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def __init__(self, size, fill_value=[114.0, 114.0, 114.0]): """ Pad image to a specified size. Args: size (list[int]): image target size fill_value (list[float]): rgb value of pad area, default (114.0, 114.0, 114.0) """ super(Pad, self).__init__() ...
Pad image to a specified size. Args: size (list[int]): image target size fill_value (list[float]): rgb value of pad area, default (114.0, 114.0, 114.0)
__init__
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/preprocess.py
Apache-2.0
def to_tlbr(self): """ Convert bounding box to format `(min x, min y, max x, max y)`, i.e., `(top left, bottom right)`. """ ret = self.tlwh.copy() ret[2:] += ret[:2] return ret
Convert bounding box to format `(min x, min y, max x, max y)`, i.e., `(top left, bottom right)`.
to_tlbr
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
Apache-2.0
def to_xyah(self): """ Convert bounding box to format `(center x, center y, aspect ratio, height)`, where the aspect ratio is `width / height`. """ ret = self.tlwh.copy() ret[:2] += ret[2:] / 2 ret[2] /= ret[3] return ret
Convert bounding box to format `(center x, center y, aspect ratio, height)`, where the aspect ratio is `width / height`.
to_xyah
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
Apache-2.0
def update_object_info(object_in_region_info, result, region_type, entrance, fps, illegal_parking_time, distance_threshold_frame=3, distance_threshold_interval...
For consecutive frames, the distance between two frame is smaller than distance_threshold_frame, regard as parking For parking in general, the move distance should smaller than distance_threshold_interval The moving distance of the vehicle is scaled according to the y, which is inversely proportional to y....
update_object_info
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/utils.py
Apache-2.0
def visualize_box_mask(im, results, labels, threshold=0.5): """ Args: im (str/np.ndarray): path of image/np.ndarray read by cv2 results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] lab...
Args: im (str/np.ndarray): path of image/np.ndarray read by cv2 results (dict): include 'boxes': np.ndarray: shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] labels (list): labels:['class1', ..., 'classn'] threshold (flo...
visualize_box_mask
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
Apache-2.0
def get_color_map_list(num_classes): """ Args: num_classes (int): number of class Returns: color_map (list): RGB color list """ color_map = num_classes * [0, 0, 0] for i in range(0, num_classes): j = 0 lab = i while lab: color_map[i * 3] |= (((...
Args: num_classes (int): number of class Returns: color_map (list): RGB color list
get_color_map_list
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
Apache-2.0
def draw_box(im, np_boxes, labels, threshold=0.5): """ Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] labels (list): labels:['class1', ..., 'classn'] ...
Args: im (PIL.Image.Image): PIL image np_boxes (np.ndarray): shape:[N,6], N: number of box, matix element:[class, score, x_min, y_min, x_max, y_max] labels (list): labels:['class1', ..., 'classn'] threshold (float): threshold of box Returns: ...
draw_box
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/visualize.py
Apache-2.0
def iou_1toN(bbox, candidates): """ Computer intersection over union (IoU) by one box to N candidates. Args: bbox (ndarray): A bounding box in format `(top left x, top left y, width, height)`. candidates (ndarray): A matrix of candidate bounding boxes (one per row) in the sa...
Computer intersection over union (IoU) by one box to N candidates. Args: bbox (ndarray): A bounding box in format `(top left x, top left y, width, height)`. candidates (ndarray): A matrix of candidate bounding boxes (one per row) in the same format as `bbox`. Returns: ...
iou_1toN
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def iou_cost(tracks, detections, track_indices=None, detection_indices=None): """ IoU distance metric. Args: tracks (list[Track]): A list of tracks. detections (list[Detection]): A list of detections. track_indices (Optional[list[int]]): A list of indices to tracks that ...
IoU distance metric. Args: tracks (list[Track]): A list of tracks. detections (list[Detection]): A list of detections. track_indices (Optional[list[int]]): A list of indices to tracks that should be matched. Defaults to all `tracks`. detection_indices (Optional[list...
iou_cost
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def _nn_euclidean_distance(s, q): """ Compute pair-wise squared (Euclidean) distance between points in `s` and `q`. Args: s (ndarray): Sample points: an NxM matrix of N samples of dimensionality M. q (ndarray): Query points: an LxM matrix of L samples of dimensionality M. Returns: ...
Compute pair-wise squared (Euclidean) distance between points in `s` and `q`. Args: s (ndarray): Sample points: an NxM matrix of N samples of dimensionality M. q (ndarray): Query points: an LxM matrix of L samples of dimensionality M. Returns: distances (ndarray): A vector of leng...
_nn_euclidean_distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def _nn_cosine_distance(s, q): """ Compute pair-wise cosine distance between points in `s` and `q`. Args: s (ndarray): Sample points: an NxM matrix of N samples of dimensionality M. q (ndarray): Query points: an LxM matrix of L samples of dimensionality M. Returns: distances (n...
Compute pair-wise cosine distance between points in `s` and `q`. Args: s (ndarray): Sample points: an NxM matrix of N samples of dimensionality M. q (ndarray): Query points: an LxM matrix of L samples of dimensionality M. Returns: distances (ndarray): A vector of length M that con...
_nn_cosine_distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def partial_fit(self, features, targets, active_targets): """ Update the distance metric with new data. Args: features (ndarray): An NxM matrix of N features of dimensionality M. targets (ndarray): An integer array of associated target identities. active_targ...
Update the distance metric with new data. Args: features (ndarray): An NxM matrix of N features of dimensionality M. targets (ndarray): An integer array of associated target identities. active_targets (List[int]): A list of targets that are currently ...
partial_fit
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def distance(self, features, targets): """ Compute distance between features and targets. Args: features (ndarray): An NxM matrix of N features of dimensionality M. targets (list[int]): A list of targets to match the given `features` against. Returns: ...
Compute distance between features and targets. Args: features (ndarray): An NxM matrix of N features of dimensionality M. targets (list[int]): A list of targets to match the given `features` against. Returns: cost_matrix (ndarray): a cost matrix of shape le...
distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def min_cost_matching(distance_metric, max_distance, tracks, detections, track_indices=None, detection_indices=None): """ Solve linear assignment problem. Args: distance_metric : ...
Solve linear assignment problem. Args: distance_metric : Callable[List[Track], List[Detection], List[int], List[int]) -> ndarray The distance metric is given a list of tracks and detections as well as a list of N track indices and M detection indices. The ...
min_cost_matching
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def matching_cascade(distance_metric, max_distance, cascade_depth, tracks, detections, track_indices=None, detection_indices=None): """ Run matching cascade. Args: distance_...
Run matching cascade. Args: distance_metric : Callable[List[Track], List[Detection], List[int], List[int]) -> ndarray The distance metric is given a list of tracks and detections as well as a list of N track indices and M detection indices. The metric ...
matching_cascade
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def gate_cost_matrix(kf, cost_matrix, tracks, detections, track_indices, detection_indices, gated_cost=INFTY_COST, only_position=False): """ Invalidate infeasible en...
Invalidate infeasible entries in cost matrix based on the state distributions obtained by Kalman filtering. Args: kf (object): The Kalman filter. cost_matrix (ndarray): The NxM dimensional cost matrix, where N is the number of track indices and M is the number of detection indi...
gate_cost_matrix
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/deepsort_matching.py
Apache-2.0
def iou_distance(atracks, btracks): """ Compute cost based on IoU between two list[STrack]. """ if (len(atracks) > 0 and isinstance(atracks[0], np.ndarray)) or ( len(btracks) > 0 and isinstance(btracks[0], np.ndarray)): atlbrs = atracks btlbrs = btracks else: atlb...
Compute cost based on IoU between two list[STrack].
iou_distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/jde_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/jde_matching.py
Apache-2.0
def embedding_distance(tracks, detections, metric='euclidean'): """ Compute cost based on features between two list[STrack]. """ cost_matrix = np.zeros((len(tracks), len(detections)), dtype=np.float) if cost_matrix.size == 0: return cost_matrix det_features = np.asarray( [track.c...
Compute cost based on features between two list[STrack].
embedding_distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/jde_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/jde_matching.py
Apache-2.0
def iou_batch(bboxes1, bboxes2): """ From SORT: Computes IOU between two bboxes in the form [x1,y1,x2,y2] """ bboxes2 = np.expand_dims(bboxes2, 0) bboxes1 = np.expand_dims(bboxes1, 1) xx1 = np.maximum(bboxes1[..., 0], bboxes2[..., 0]) yy1 = np.maximum(bboxes1[..., 1], bboxes2[..., 1]) x...
From SORT: Computes IOU between two bboxes in the form [x1,y1,x2,y2]
iou_batch
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/ocsort_matching.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/matching/ocsort_matching.py
Apache-2.0
def initiate(self, measurement): """ Create track from unassociated measurement. Args: measurement (ndarray): Bounding box coordinates (x, y, a, h) with center position (x, y), aspect ratio a, and height h. Returns: The mean vector (8 dimensional...
Create track from unassociated measurement. Args: measurement (ndarray): Bounding box coordinates (x, y, a, h) with center position (x, y), aspect ratio a, and height h. Returns: The mean vector (8 dimensional) and covariance matrix (8x8 dim...
initiate
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def predict(self, mean, covariance): """ Run Kalman filter prediction step. Args: mean (ndarray): The 8 dimensional mean vector of the object state at the previous time step. covariance (ndarray): The 8x8 dimensional covariance matrix of the ...
Run Kalman filter prediction step. Args: mean (ndarray): The 8 dimensional mean vector of the object state at the previous time step. covariance (ndarray): The 8x8 dimensional covariance matrix of the object state at the previous time step. ...
predict
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def project(self, mean, covariance): """ Project state distribution to measurement space. Args mean (ndarray): The state's mean vector (8 dimensional array). covariance (ndarray): The state's covariance matrix (8x8 dimensional). Returns: The projecte...
Project state distribution to measurement space. Args mean (ndarray): The state's mean vector (8 dimensional array). covariance (ndarray): The state's covariance matrix (8x8 dimensional). Returns: The projected mean and covariance matrix of the given state ...
project
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def multi_predict(self, mean, covariance): """ Run Kalman filter prediction step (Vectorized version). Args: mean (ndarray): The Nx8 dimensional mean matrix of the object states at the previous time step. covariance (ndarray): The Nx8x8 dimensiona...
Run Kalman filter prediction step (Vectorized version). Args: mean (ndarray): The Nx8 dimensional mean matrix of the object states at the previous time step. covariance (ndarray): The Nx8x8 dimensional covariance matrics of the object sta...
multi_predict
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def update(self, mean, covariance, measurement): """ Run Kalman filter correction step. Args: mean (ndarray): The predicted state's mean vector (8 dimensional). covariance (ndarray): The state's covariance matrix (8x8 dimensional). measurement (ndarray): The ...
Run Kalman filter correction step. Args: mean (ndarray): The predicted state's mean vector (8 dimensional). covariance (ndarray): The state's covariance matrix (8x8 dimensional). measurement (ndarray): The 4 dimensional measurement vector (x, y, a, h...
update
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def gating_distance(self, mean, covariance, measurements, only_position=False, metric='maha'): """ Compute gating distance between state distribution and measurements. A suitab...
Compute gating distance between state distribution and measurements. A suitable distance threshold can be obtained from `chi2inv95`. If `only_position` is False, the chi-square distribution has 4 degrees of freedom, otherwise 2. Args: mean (ndarray): Mean ve...
gating_distance
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/motion/kalman_filter.py
Apache-2.0
def sub_cluster(cid_tid_dict, scene_cluster, use_ff=True, use_rerank=True, use_camera=False, use_st_filter=False): ''' cid_tid_dict: all camera_id and track_id scene_cluster: like [41, 42, 43, 44, 45, 46] in AIC21 MTMCT S06 test...
cid_tid_dict: all camera_id and track_id scene_cluster: like [41, 42, 43, 44, 45, 46] in AIC21 MTMCT S06 test videos
sub_cluster
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/mtmct/postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/mtmct/postprocess.py
Apache-2.0
def getData(fpath, names=None, sep='\s+|\t+|,'): """ Get the necessary track data from a file handle. Args: fpath (str) : Original path of file reading from. names (list[str]): List of column names for the data. sep (str): Allowed separators regular expression string. Return: ...
Get the necessary track data from a file handle. Args: fpath (str) : Original path of file reading from. names (list[str]): List of column names for the data. sep (str): Allowed separators regular expression string. Return: df (pandas.DataFrame): Data frame containing the data l...
getData
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/mtmct/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/mtmct/utils.py
Apache-2.0
def init_count(num_classes): """ Initiate _count for all object classes :param num_classes: """ for cls_id in range(num_classes): BaseTrack._count_dict[cls_id] = 0
Initiate _count for all object classes :param num_classes:
init_count
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
Apache-2.0
def tlwh(self): """Get current position in bounding box format `(top left x, top left y, width, height)`. """ if self.mean is None: return self._tlwh.copy() ret = self.mean[:4].copy() ret[2] *= ret[3] ret[:2] -= ret[2:] / 2 return ret
Get current position in bounding box format `(top left x, top left y, width, height)`.
tlwh
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
Apache-2.0
def tlbr(self): """Convert bounding box to format `(min x, min y, max x, max y)`, i.e., `(top left, bottom right)`. """ ret = self.tlwh.copy() ret[2:] += ret[:2] return ret
Convert bounding box to format `(min x, min y, max x, max y)`, i.e., `(top left, bottom right)`.
tlbr
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
Apache-2.0
def tlwh_to_xyah(tlwh): """Convert bounding box to format `(center x, center y, aspect ratio, height)`, where the aspect ratio is `width / height`. """ ret = np.asarray(tlwh).copy() ret[:2] += ret[2:] / 2 ret[2] /= ret[3] return ret
Convert bounding box to format `(center x, center y, aspect ratio, height)`, where the aspect ratio is `width / height`.
tlwh_to_xyah
python
PaddlePaddle/models
modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Vehicle/APP/pptracking/python/mot/tracker/base_jde_tracker.py
Apache-2.0