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 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-HumanV2/APP/pptracking/python/mot/motion/kalman_filter.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/mtmct/postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/mtmct/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/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-HumanV2/APP/pptracking/python/mot/tracker/base_jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_jde_tracker.py
Apache-2.0
def to_tlwh(self): """Get position in format `(top left x, top left y, width, height)`.""" ret = self.mean[:4].copy() ret[2] *= ret[3] ret[:2] -= ret[2:] / 2 return ret
Get position in format `(top left x, top left y, width, height)`.
to_tlwh
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
Apache-2.0
def to_tlbr(self): """Get position in bounding box format `(min x, miny, max x, max y)`.""" ret = self.to_tlwh() ret[2:] = ret[:2] + ret[2:] return ret
Get position in bounding box format `(min x, miny, max x, max y)`.
to_tlbr
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
Apache-2.0
def predict(self, kalman_filter): """ Propagate the state distribution to the current time step using a Kalman filter prediction step. """ self.mean, self.covariance = kalman_filter.predict(self.mean, self.covariance) ...
Propagate the state distribution to the current time step using a Kalman filter prediction step.
predict
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
Apache-2.0
def update(self, kalman_filter, detection): """ Perform Kalman filter measurement update step and update the associated detection feature cache. """ self.mean, self.covariance = kalman_filter.update(self.mean, self.covaria...
Perform Kalman filter measurement update step and update the associated detection feature cache.
update
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
Apache-2.0
def mark_missed(self): """Mark this track as missed (no association at the current time step). """ if self.state == TrackState.Tentative: self.state = TrackState.Deleted elif self.time_since_update > self._max_age: self.state = TrackState.Deleted
Mark this track as missed (no association at the current time step).
mark_missed
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/base_sde_tracker.py
Apache-2.0
def update(self, pred_dets, pred_embs): """ Perform measurement update and track management. Args: pred_dets (np.array): Detection results of the image, the shape is [N, 6], means 'cls_id, score, x0, y0, x1, y1'. pred_embs (np.array): Embedding results of ...
Perform measurement update and track management. Args: pred_dets (np.array): Detection results of the image, the shape is [N, 6], means 'cls_id, score, x0, y0, x1, y1'. pred_embs (np.array): Embedding results of the image, the shape is [N, 128], u...
update
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/deepsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/deepsort_tracker.py
Apache-2.0
def update(self, pred_dets, pred_embs=None): """ Processes the image frame and finds bounding box(detections). Associates the detection with corresponding tracklets and also handles lost, removed, refound and active tracklets. Args: pred_dets (np.array): Detectio...
Processes the image frame and finds bounding box(detections). Associates the detection with corresponding tracklets and also handles lost, removed, refound and active tracklets. Args: pred_dets (np.array): Detection results of the image, the shape is [N,...
update
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/jde_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/jde_tracker.py
Apache-2.0
def convert_bbox_to_z(bbox): """ Takes a bounding box in the form [x1,y1,x2,y2] and returns z in the form [x,y,s,r] where x,y is the centre of the box and s is the scale/area and r is the aspect ratio """ w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] x = bbox[0] + w / 2. y = bbox[1...
Takes a bounding box in the form [x1,y1,x2,y2] and returns z in the form [x,y,s,r] where x,y is the centre of the box and s is the scale/area and r is the aspect ratio
convert_bbox_to_z
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
Apache-2.0
def convert_x_to_bbox(x, score=None): """ Takes a bounding box in the centre form [x,y,s,r] and returns it in the form [x1,y1,x2,y2] where x1,y1 is the top left and x2,y2 is the bottom right """ w = np.sqrt(x[2] * x[3]) h = x[2] / w if (score == None): return np.array( ...
Takes a bounding box in the centre form [x,y,s,r] and returns it in the form [x1,y1,x2,y2] where x1,y1 is the top left and x2,y2 is the bottom right
convert_x_to_bbox
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
Apache-2.0
def update(self, bbox): """ Updates the state vector with observed bbox. """ if bbox is not None: if self.last_observation.sum() >= 0: # no previous observation previous_box = None for i in range(self.delta_t): dt = self.de...
Updates the state vector with observed bbox.
update
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
Apache-2.0
def predict(self): """ Advances the state vector and returns the predicted bounding box estimate. """ if ((self.kf.x[6] + self.kf.x[2]) <= 0): self.kf.x[6] *= 0.0 self.kf.predict() self.age += 1 if (self.time_since_update > 0): self.hit_st...
Advances the state vector and returns the predicted bounding box estimate.
predict
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
Apache-2.0
def update(self, pred_dets, pred_embs=None): """ Args: pred_dets (np.array): Detection results of the image, the shape is [N, 6], means 'cls_id, score, x0, y0, x1, y1'. pred_embs (np.array): Embedding results of the image, the shape is [N, 128] or ...
Args: pred_dets (np.array): Detection results of the image, the shape is [N, 6], means 'cls_id, score, x0, y0, x1, y1'. pred_embs (np.array): Embedding results of the image, the shape is [N, 128] or [N, 512], default as None. Return: ...
update
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/pptracking/python/mot/tracker/ocsort_tracker.py
Apache-2.0
def __init__(self, config, model_info: dict={}, data_info: dict={}, perf_info: dict={}, resource_info: dict={}, **kwargs): """ Construct PaddleInferBenchmark Class to format logs. args: ...
Construct PaddleInferBenchmark Class to format logs. args: config(paddle.inference.Config): paddle inference config model_info(dict): basic model info {'model_name': 'resnet50' 'precision': 'fp32'} data_info(dict): input data info ...
__init__
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/python/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/benchmark_utils.py
Apache-2.0
def parse_config(self, config) -> dict: """ parse paddle predictor config args: config(paddle.inference.Config): paddle inference config return: config_status(dict): dict style config info """ if isinstance(config, paddle_infer.Config): ...
parse paddle predictor config args: config(paddle.inference.Config): paddle inference config return: config_status(dict): dict style config info
parse_config
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/python/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/benchmark_utils.py
Apache-2.0
def report(self, identifier=None): """ print log report args: identifier(string): identify log """ if identifier: identifier = f"[{identifier}]" else: identifier = "" self.logger.info("\n") self.logger.info( ...
print log report args: identifier(string): identify log
report
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/python/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/benchmark_utils.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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/infer.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeat number for prediction Returns: result (dict): 'segm': np.ndarray,shape:[N, im_h, im_w] 'cate_label': label of segm, shape:[N] 'cate_score': confidence sco...
Args: repeats (int): repeat number for prediction Returns: result (dict): 'segm': np.ndarray,shape:[N, im_h, im_w] 'cate_label': label of segm, shape:[N] 'cate_score': confidence score of segm, shape:[N]
predict
python
PaddlePaddle/models
modelcenter/PP-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/infer.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeat 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): repeat 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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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, \ "--image_file or --image_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-HumanV2/APP/python/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/infer.py
Apache-2.0
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-HumanV2/APP/python/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/keypoint_preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/keypoint_preprocess.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-HumanV2/APP/python/mot_jde_infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/mot_jde_infer.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-HumanV2/APP/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/picodet_postprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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_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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/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 """ 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-HumanV2/APP/python/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/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-HumanV2/APP/python/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-HumanV2/APP/python/visualize.py
Apache-2.0
def __init__(self, cfg): """ Prepare for prediction. The usage and docs of paddle inference, please refer to https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html """ self.cfg = DeployConfig(cfg) self._init_base_config() self._ini...
Prepare for prediction. The usage and docs of paddle inference, please refer to https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html
__init__
python
PaddlePaddle/models
modelcenter/PP-LiteSeg/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-LiteSeg/APP/app.py
Apache-2.0
def get_pseudo_color_map(self, pred, color_map=None): """ Get the pseudo color image. Args: pred (numpy.ndarray): the origin predicted image. color_map (list, optional): the palette color map. Default: None, use paddleseg's default color map. Retur...
Get the pseudo color image. Args: pred (numpy.ndarray): the origin predicted image. color_map (list, optional): the palette color map. Default: None, use paddleseg's default color map. Returns: (numpy.ndarray): the pseduo image.
get_pseudo_color_map
python
PaddlePaddle/models
modelcenter/PP-LiteSeg/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-LiteSeg/APP/app.py
Apache-2.0
def get_color_map_list(self, num_classes, custom_color=None): """ Returns the color map for visualizing the segmentation mask, which can support arbitrary number of classes. Args: num_classes (int): Number of classes. custom_color (list, optional): Save images wit...
Returns the color map for visualizing the segmentation mask, which can support arbitrary number of classes. Args: num_classes (int): Number of classes. custom_color (list, optional): Save images with a custom color map. Default: None, use paddleseg's default color map. ...
get_color_map_list
python
PaddlePaddle/models
modelcenter/PP-LiteSeg/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-LiteSeg/APP/app.py
Apache-2.0
def get_output(img, size, bg, download_size): """ Get the special size and background photo. Args: img(numpy:ndarray): The image array. size(str): The size user specified. bg(str): The background color user specified. download_size(str): The size for image saving. """ ...
Get the special size and background photo. Args: img(numpy:ndarray): The image array. size(str): The size user specified. bg(str): The background color user specified. download_size(str): The size for image saving.
get_output
python
PaddlePaddle/models
modelcenter/PP-Matting/APP1/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Matting/APP1/app.py
Apache-2.0
def __init__(self, cfg): """ Prepare for prediction. The usage and docs of paddle inference, please refer to https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html """ self.cfg = DeployConfig(cfg) self._init_base_config() self._ini...
Prepare for prediction. The usage and docs of paddle inference, please refer to https://paddleinference.paddlepaddle.org.cn/product_introduction/summary.html
__init__
python
PaddlePaddle/models
modelcenter/PP-Matting/APP1/predict.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-Matting/APP1/predict.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('paddlecv://')
Whether path is URL. Args: path (string): URL string or not.
is_url
python
PaddlePaddle/models
modelcenter/PP-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/download.py
Apache-2.0
def get_model_path(path): """Get model path from WEIGHTS_HOME, if not exists, download it from url. """ if not is_url(path): return path url = parse_url(path) path, _ = get_path(url, WEIGHTS_HOME, path_depth=2) return path
Get model path from WEIGHTS_HOME, if not exists, download it from url.
get_model_path
python
PaddlePaddle/models
modelcenter/PP-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/download.py
Apache-2.0
def get_config_path(path): """Get config path from CONFIGS_HOME, if not exists, download it from url. """ if not is_url(path): return path url = parse_url(path) path, _ = get_path(url, CONFIGS_HOME) return path
Get config path from CONFIGS_HOME, if not exists, download it from url.
get_config_path
python
PaddlePaddle/models
modelcenter/PP-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/download.py
Apache-2.0
def get_dict_path(path): """Get config path from CONFIGS_HOME, if not exists, download it from url. """ if not is_url(path): return path url = parse_url(path) path, _ = get_path(url, DICTS_HOME) return path
Get config path from CONFIGS_HOME, if not exists, download it from url.
get_dict_path
python
PaddlePaddle/models
modelcenter/PP-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/download.py
Apache-2.0
def get_path(url, root_dir, md5sum=None, check_exist=True, path_depth=1): """ 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, return the path. url (str): download url root_dir (str): 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, return the path. url (str): download url root_dir (str): root dir for downloading, it should be WEIGHTS_HOME md5sum (st...
get_path
python
PaddlePaddle/models
modelcenter/PP-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/download.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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/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-PicoDet/APP/src/preprocess.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/preprocess.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-PicoDet/APP/src/visualize.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-PicoDet/APP/src/visualize.py
Apache-2.0
def download_with_progressbar(url: str, save_path: str): """Download file from given url and decompress it Args: url (str): url save_path (str): path for saving downloaded file Raises: Exception: exception """ print(f"Auto downloading {url} to {save_path}") if os.path.e...
Download file from given url and decompress it Args: url (str): url save_path (str): path for saving downloaded file Raises: Exception: exception
download_with_progressbar
python
PaddlePaddle/models
modelcenter/PP-ShiTuV2/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-ShiTuV2/APP/app.py
Apache-2.0
def model_inference(image) -> tuple: """send given image to inference model and get result from output Args: image (gr.Image): input image Returns: tuple: (drawn image to display, result in json format) """ results = clas_engine.predict(image, print_pred=True, predict_type="shitu")...
send given image to inference model and get result from output Args: image (gr.Image): input image Returns: tuple: (drawn image to display, result in json format)
model_inference
python
PaddlePaddle/models
modelcenter/PP-ShiTuV2/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-ShiTuV2/APP/app.py
Apache-2.0
def draw_bbox_results(image: Union[np.ndarray, Image.Image], results: List[Dict[str, Any]]) -> np.ndarray: """draw bounding box(es) Args: image (Union[np.ndarray, Image.Image]): image to be drawn results (List[Dict[str, Any]]): information for drawing bounding box Ret...
draw bounding box(es) Args: image (Union[np.ndarray, Image.Image]): image to be drawn results (List[Dict[str, Any]]): information for drawing bounding box Returns: np.ndarray: drawn image
draw_bbox_results
python
PaddlePaddle/models
modelcenter/PP-ShiTuV2/APP/app.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-ShiTuV2/APP/app.py
Apache-2.0
def __init__(self, config, model_info: dict={}, data_info: dict={}, perf_info: dict={}, resource_info: dict={}, **kwargs): """ Construct PaddleInferBenchmark Class to format logs. args: ...
Construct PaddleInferBenchmark Class to format logs. args: config(paddle.inference.Config): paddle inference config model_info(dict): basic model info {'model_name': 'resnet50' 'precision': 'fp32'} data_info(dict): input data info ...
__init__
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/benchmark_utils.py
Apache-2.0
def parse_config(self, config) -> dict: """ parse paddle predictor config args: config(paddle.inference.Config): paddle inference config return: config_status(dict): dict style config info """ if isinstance(config, paddle_infer.Config): ...
parse paddle predictor config args: config(paddle.inference.Config): paddle inference config return: config_status(dict): dict style config info
parse_config
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/benchmark_utils.py
Apache-2.0
def report(self, identifier=None): """ print log report args: identifier(string): identify log """ if identifier: identifier = f"[{identifier}]" else: identifier = "" self.logger.info("\n") self.logger.info( ...
print log report args: identifier(string): identify log
report
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/benchmark_utils.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/benchmark_utils.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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/download.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/download.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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/infer.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeat number for prediction Returns: result (dict): 'segm': np.ndarray,shape:[N, im_h, im_w] 'cate_label': label of segm, shape:[N] 'cate_score': confidence sco...
Args: repeats (int): repeat number for prediction Returns: result (dict): 'segm': np.ndarray,shape:[N, im_h, im_w] 'cate_label': label of segm, shape:[N] 'cate_score': confidence score of segm, shape:[N]
predict
python
PaddlePaddle/models
modelcenter/PP-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/infer.py
Apache-2.0
def predict(self, repeats=1): ''' Args: repeats (int): repeat 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): repeat 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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/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, \ "--image_file or --image_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-TinyPose/APP/infer.py
https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-TinyPose/APP/infer.py
Apache-2.0