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 _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-YOLOv2/APP/src/download.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/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-YOLOv2/APP/src/visualize.py | https://github.com/PaddlePaddle/models/blob/master/modelcenter/PP-YOLOv2/APP/src/visualize.py | Apache-2.0 |
def get_package_data_files(package, data, package_dir=None):
"""
Helps to list all specified files in package including files in directories
since `package_data` ignores directories.
"""
if package_dir is None:
package_dir = os.path.join(*package.split('.'))
all_files = []
for f in d... |
Helps to list all specified files in package including files in directories
since `package_data` ignores directories.
| get_package_data_files | python | PaddlePaddle/models | paddlecv/setup.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/setup.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# for the input_keys as list
# inputs = [pipe_input[key] for pipe_input in pipe_inputs for key in self.input_keys]
key = self.input_keys... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/custom_op/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/inference.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 | paddlecv/custom_op/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/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 | paddlecv/custom_op/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/custom_op/preprocess.py | Apache-2.0 |
def topo_sort(self):
"""
Topological sort of DAG, creates inverted multi-layers views.
Args:
graph (dict): the DAG stucture
in_degrees (dict): Next op list for each op
Returns:
sort_result: the hierarchical topology list. examples:
DAG ... |
Topological sort of DAG, creates inverted multi-layers views.
Args:
graph (dict): the DAG stucture
in_degrees (dict): Next op list for each op
Returns:
sort_result: the hierarchical topology list. examples:
DAG :[A -> B -> C -> E]
... | topo_sort | python | PaddlePaddle/models | paddlecv/ppcv/core/framework.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/core/framework.py | Apache-2.0 |
def register(cls):
"""
Register a given module class.
Args:
cls (type): Module class to be registered.
Returns: cls
"""
if cls.__name__ in global_config:
raise ValueError("Module class already registered: {}".format(
cls.__name__))
global_config[cls.__name__] = cl... |
Register a given module class.
Args:
cls (type): Module class to be registered.
Returns: cls
| register | python | PaddlePaddle/models | paddlecv/ppcv/core/workspace.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/core/workspace.py | Apache-2.0 |
def create(cls_name, op_cfg, env_cfg):
"""
Create an instance of given module class.
Args:
cls_name(str): Class of which to create instnce.
Return: instance of type `cls_or_name`
"""
assert type(cls_name) == str, "should be a name of class"
if cls_name not in global_config:
... |
Create an instance of given module class.
Args:
cls_name(str): Class of which to create instnce.
Return: instance of type `cls_or_name`
| create | python | PaddlePaddle/models | paddlecv/ppcv/core/workspace.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/core/workspace.py | Apache-2.0 |
def create_operators(params, mod):
"""
create operators based on the config
Args:
params(list): a dict list, used to create some operators
mod(module) : a module that can import single ops
"""
assert isinstance(params, list), ('operator config should be a list')
if mod is None:
... |
create operators based on the config
Args:
params(list): a dict list, used to create some operators
mod(module) : a module that can import single ops
| create_operators | python | PaddlePaddle/models | paddlecv/ppcv/ops/base.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/base.py | Apache-2.0 |
def get(self, key):
"""
key can be one of [list, tuple, str]
"""
if isinstance(key, (list, tuple)):
return [self.data_dict[k] for k in key]
elif isinstance(key, (str)):
return self.data_dict[key]
else:
assert False, f"key({key}) type mu... |
key can be one of [list, tuple, str]
| get | python | PaddlePaddle/models | paddlecv/ppcv/ops/general_data_obj.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/general_data_obj.py | Apache-2.0 |
def get_rotate_crop_image(self, 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, :]... |
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
... | get_rotate_crop_image | python | PaddlePaddle/models | paddlecv/ppcv/ops/connector/op_connector.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/op_connector.py | Apache-2.0 |
def sorted_boxes(self, dt_boxes):
"""
Sort text boxes in order from top to bottom, left to right
args:
dt_boxes(array):detected text boxes with shape [4, 2]
return:
sorted boxes(array) with shape [4, 2]
"""
num_boxes = dt_boxes.shape[0]
sor... |
Sort text boxes in order from top to bottom, left to right
args:
dt_boxes(array):detected text boxes with shape [4, 2]
return:
sorted boxes(array) with shape [4, 2]
| sorted_boxes | python | PaddlePaddle/models | paddlecv/ppcv/ops/connector/op_connector.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/op_connector.py | Apache-2.0 |
def compute_iou(rec1, rec2):
"""
computing IoU
:param rec1: (y0, x0, y1, x1), which reflects
(top, left, bottom, right)
:param rec2: (y0, x0, y1, x1)
:return: scala value of IoU
"""
# computing area of each rectangles
S_rec1 = (rec1[2] - rec1[0]) * (rec1[3] - rec1[1])
S_r... |
computing IoU
:param rec1: (y0, x0, y1, x1), which reflects
(top, left, bottom, right)
:param rec2: (y0, x0, y1, x1)
:return: scala value of IoU
| compute_iou | python | PaddlePaddle/models | paddlecv/ppcv/ops/connector/table_matcher.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/table_matcher.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 | paddlecv/ppcv/ops/connector/tracker/tracker.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/tracker/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 | paddlecv/ppcv/ops/connector/tracker/tracker.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/tracker/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 | paddlecv/ppcv/ops/connector/tracker/tracker.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/tracker/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 | paddlecv/ppcv/ops/connector/tracker/tracker.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/tracker/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 | paddlecv/ppcv/ops/connector/tracker/tracker.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/connector/tracker/tracker.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/classification/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/classification/inference.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# for the input_keys as list
# inputs = [pipe_input[key] for pipe_input in pipe_inputs for key in self.input_keys]
key = self.input_keys... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/detection/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/inference.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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/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[:, :, ::-1]
... |
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 | paddlecv/ppcv/ops/models/detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/detection/preprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# for the input_keys as list
# inputs = [pipe_input[key] for pipe_input in pipe_inputs for key in self.input_keys]
# step1: for the inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/keypoint/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/keypoint/inference.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 | paddlecv/ppcv/ops/models/keypoint/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/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 | paddlecv/ppcv/ops/models/keypoint/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/keypoint/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 | paddlecv/ppcv/ops/models/keypoint/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/keypoint/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 | paddlecv/ppcv/ops/models/keypoint/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/keypoint/preprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/nlp/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/nlp/inference.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_crnn_recognition/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_crnn_recognition/inference.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 | paddlecv/ppcv/ops/models/ocr/ocr_crnn_recognition/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_crnn_recognition/postprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/inference.py | Apache-2.0 |
def polygons_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
boxes = []
scores = []
contours, _ =... |
_bitmap: single map with shape (1, H, W),
whose values are binarized as {0, 1}
| polygons_from_bitmap | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.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 | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/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("int"), 0, w - 1)
xmax = np.clip(np.ceil(box[:, 0].max()).astype("int"),... |
box_score_fast: use bbox mean score as the mean score
| box_score_fast | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/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 | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | Apache-2.0 |
def sorted_boxes(dt_boxes):
"""
Sort text boxes in order from top to bottom, left to right
args:
dt_boxes(array):detected text boxes with shape [4, 2]
return:
sorted boxes(array) with shape [4, 2]
"""
num_boxes = dt_boxes.shape[0]
sorted_boxes = sorted(dt_boxes, key=lambda x:... |
Sort text boxes in order from top to bottom, left to right
args:
dt_boxes(array):detected text boxes with shape [4, 2]
return:
sorted boxes(array) with shape [4, 2]
| sorted_boxes | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/postprocess.py | Apache-2.0 |
def resize_image_type0(self, img):
"""
resize image to a size multiple of 32 which is required by the network
args:
img(array): array with shape [h, w, c]
return(tuple):
img, (ratio_h, ratio_w)
"""
limit_side_len = self.limit_side_len
h, w,... |
resize image to a size multiple of 32 which is required by the network
args:
img(array): array with shape [h, w, c]
return(tuple):
img, (ratio_h, ratio_w)
| resize_image_type0 | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_db_detection/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_db_detection/preprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# step2: run
outputs, ser_inputs = self.infer(inputs)
# step3: merge
pipe_outputs = []
for output, ser_input in zip(outpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_kie/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_kie/inference.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# step2: run
outputs = self.infer(inputs)
# step3: merge
pipe_outputs = []
for output in outputs:
d = default... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_kie/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_kie/inference.py | Apache-2.0 |
def filter_empty_contents(self, ocr_info):
"""
find out the empty texts and remove the links
"""
new_ocr_info = []
empty_index = []
for idx, info in enumerate(ocr_info):
if len(info["transcription"]) > 0:
new_ocr_info.append(copy.deepcopy(info)... |
find out the empty texts and remove the links
| filter_empty_contents | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_kie/preprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_kie/preprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/inference.py | Apache-2.0 |
def decode(self, structure_probs, bbox_preds, shape_list):
"""convert text-label into text-index.
"""
ignored_tokens = self.get_ignored_tokens()
end_idx = self.dict[self.end_str]
structure_idx = structure_probs.argmax(axis=2)
structure_probs = structure_probs.max(axis=2)... | convert text-label into text-index.
| decode | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/postprocess.py | Apache-2.0 |
def decode_label(self, batch):
"""convert text-label into text-index.
"""
structure_idx = batch[1]
gt_bbox_list = batch[2]
shape_list = batch[-1]
ignored_tokens = self.get_ignored_tokens()
end_idx = self.dict[self.end_str]
structure_batch_list = []
... | convert text-label into text-index.
| decode_label | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/postprocess.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/ocr/ocr_table_recognition/postprocess.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
key = self.input_keys[0]
is_list = False
if isinstance(inputs[0][key], (list, tuple)):
inputs = [input[key] for input in inpu... |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/segmentation/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/segmentation/inference.py | Apache-2.0 |
def __call__(self, inputs):
"""
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
"""
# step2: run
outputs = self.infer(inputs)
return outputs |
step1: parser inputs
step2: run
step3: merge results
input: a list of dict
| __call__ | python | PaddlePaddle/models | paddlecv/ppcv/ops/models/speech/inference.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/models/speech/inference.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 | paddlecv/ppcv/ops/output/detection.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/output/detection.py | Apache-2.0 |
def get_pseudo_color_map(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.
Returns:
(numpy.ndarray): the... |
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 | paddlecv/ppcv/ops/output/segmentation.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/output/segmentation.py | Apache-2.0 |
def get_color_map_list(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 with a custom color map. Default... |
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.
Returns:
... | get_color_map_list | python | PaddlePaddle/models | paddlecv/ppcv/ops/output/segmentation.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/ops/output/segmentation.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 | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/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)
logger.info("The model path is {}".format(path))
return path | Get model path from WEIGHTS_HOME, if not exists,
download it from url.
| get_model_path | python | PaddlePaddle/models | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/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)
logger.info("The config path is {}".format(path))
return path | Get config path from CONFIGS_HOME, if not exists,
download it from url.
| get_config_path | python | PaddlePaddle/models | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/download.py | Apache-2.0 |
def get_dict_path(path):
"""Get dict path from DICTS_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)
logger.info("The dict path is {}".format(path))
return path | Get dict path from DICTS_HOME, if not exists,
download it from url.
| get_dict_path | python | PaddlePaddle/models | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/download.py | Apache-2.0 |
def get_font_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, FONTS_HOME)
return path | Get config path from CONFIGS_HOME, if not exists,
download it from url.
| get_font_path | python | PaddlePaddle/models | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/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 | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/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 | paddlecv/ppcv/utils/download.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/download.py | Apache-2.0 |
def setup_logger(name="ppcv", output=None):
"""
Initialize logger and set its verbosity level to INFO.
Args:
name (str): the root module name of this logger
output (str): a file name or a directory to save log. If None, will not save log file.
If ends with ".txt" or ".log", assum... |
Initialize logger and set its verbosity level to INFO.
Args:
name (str): the root module name of this logger
output (str): a file name or a directory to save log. If None, will not save log file.
If ends with ".txt" or ".log", assumed to be a file name.
Otherwise, logs w... | setup_logger | python | PaddlePaddle/models | paddlecv/ppcv/utils/logger.py | https://github.com/PaddlePaddle/models/blob/master/paddlecv/ppcv/utils/logger.py | Apache-2.0 |
def accuracy_paddle(output, target, topk=(1, )):
"""Computes the accuracy over the k top predictions for the specified values of k"""
with paddle.no_grad():
maxk = max(topk)
batch_size = target.shape[0]
_, pred = output.topk(maxk, 1, True, True)
pred = pred.t()
correct =... | Computes the accuracy over the k top predictions for the specified values of k | accuracy_paddle | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/metric.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/metric.py | Apache-2.0 |
def synchronize_between_processes(self):
"""
Warning: does not synchronize the deque!
"""
t = paddle.to_tensor([self.count, self.total], dtype='float64')
t = t.numpy().tolist()
self.count = int(t[0])
self.total = t[1] |
Warning: does not synchronize the deque!
| synchronize_between_processes | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/utils.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/utils.py | Apache-2.0 |
def accuracy(output, target, topk=(1, )):
"""Computes the accuracy over the k top predictions for the specified values of k"""
with paddle.no_grad():
maxk = max(topk)
batch_size = target.shape[0]
_, pred = output.topk(maxk, 1, True, True)
pred = pred.t()
correct = pred.e... | Computes the accuracy over the k top predictions for the specified values of k | accuracy | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/utils.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/utils.py | Apache-2.0 |
def has_file_allowed_extension(filename: str,
extensions: Tuple[str, ...]) -> bool:
"""Checks if a file is an allowed extension.
Args:
filename (string): path to a file
extensions (tuple of strings): extensions to consider (lowercase)
Returns:
bool: T... | Checks if a file is an allowed extension.
Args:
filename (string): path to a file
extensions (tuple of strings): extensions to consider (lowercase)
Returns:
bool: True if the filename ends with one of given extensions
| has_file_allowed_extension | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | Apache-2.0 |
def find_classes(directory: str) -> Tuple[List[str], Dict[str, int]]:
"""Finds the class folders in a dataset.
See :class:`DatasetFolder` for details.
"""
classes = sorted(
entry.name for entry in os.scandir(directory) if entry.is_dir())
if not classes:
raise FileNotFoundError(
... | Finds the class folders in a dataset.
See :class:`DatasetFolder` for details.
| find_classes | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | Apache-2.0 |
def make_dataset(
directory: str,
class_to_idx: Optional[Dict[str, int]]=None,
extensions: Optional[Tuple[str, ...]]=None,
is_valid_file: Optional[Callable[[str], bool]]=None, ) -> List[Tuple[
str, int]]:
"""Generates a list of samples of a form (path_to_sample, class).
... | Generates a list of samples of a form (path_to_sample, class).
See :class:`DatasetFolder` for details.
Note: The class_to_idx parameter is here optional and will use the logic of the ``find_classes`` function
by default.
| make_dataset | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | Apache-2.0 |
def make_dataset(
directory: str,
class_to_idx: Dict[str, int],
extensions: Optional[Tuple[str, ...]]=None,
is_valid_file: Optional[Callable[[str], bool]]=None, ) -> List[
Tuple[str, int]]:
"""Generates a list of samples of a form (path_to_sample, ... | Generates a list of samples of a form (path_to_sample, class).
This can be overridden to e.g. read files from a compressed zip file instead of from the disk.
Args:
directory (str): root dataset directory, corresponding to ``self.root``.
class_to_idx (Dict[str, int]): Dictionary... | make_dataset | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | Apache-2.0 |
def __getitem__(self, index: int) -> Tuple[Any, Any]:
"""
Args:
index (int): Index
Returns:
tuple: (sample, target) where target is class_index of the target class.
"""
path, target = self.samples[index]
sample = self.loader(path)
if self.... |
Args:
index (int): Index
Returns:
tuple: (sample, target) where target is class_index of the target class.
| __getitem__ | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/datasets/folder.py | Apache-2.0 |
def _make_divisible(v: float, divisor: int,
min_value: Optional[int]=None) -> int:
"""
This function is taken from the original tf repo.
It ensures that all layers have a channel number that is divisible by 8
It can be seen here:
https://github.com/tensorflow/models/blob/master/r... |
This function is taken from the original tf repo.
It ensures that all layers have a channel number that is divisible by 8
It can be seen here:
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py
| _make_divisible | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | Apache-2.0 |
def __init__(
self,
inverted_residual_setting: List[InvertedResidualConfig],
last_channel: int,
num_classes: int=1000,
block: Optional[Callable[..., nn.Layer]]=None,
norm_layer: Optional[Callable[..., nn.Layer]]=None,
dropout: float=0.2... |
MobileNet V3 main class
Args:
inverted_residual_setting (List[InvertedResidualConfig]): Network structure
last_channel (int): The number of channels on the penultimate layer
num_classes (int): Number of classes
block (Optional[Callable[..., nn.Layer]]): ... | __init__ | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | Apache-2.0 |
def mobilenet_v3_large(pretrained: bool=False,
progress: bool=True,
**kwargs: Any) -> MobileNetV3:
"""
Constructs a large MobileNetV3 architecture from
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool): If Tr... |
Constructs a large MobileNetV3 architecture from
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
progress (bool): If True, displays a progress bar of the download to stderr
| mobilenet_v3_large | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | Apache-2.0 |
def mobilenet_v3_small(pretrained: bool=False,
progress: bool=True,
**kwargs: Any) -> MobileNetV3:
"""
Constructs a small MobileNetV3 architecture from
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool): If Tr... |
Constructs a small MobileNetV3 architecture from
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
progress (bool): If True, displays a progress bar of the download to stderr
| mobilenet_v3_small | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/models/mobilenet_v3_paddle.py | Apache-2.0 |
def get_params(transform_num: int) -> Tuple[int, Tensor, Tensor]:
"""Get parameters for autoaugment transformation
Returns:
params required by the autoaugment transformation
"""
policy_id = int(paddle.randint(low=0, high=transform_num, shape=(1, )))
probs = paddle.ra... | Get parameters for autoaugment transformation
Returns:
params required by the autoaugment transformation
| get_params | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/autoaugment.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/autoaugment.py | Apache-2.0 |
def forward(self, img: Tensor):
"""
img (PIL Image or Tensor): Image to be transformed.
Returns:
PIL Image or Tensor: AutoAugmented image.
"""
fill = self.fill
if isinstance(img, Tensor):
if isinstance(fill, (int, float)):
fill... |
img (PIL Image or Tensor): Image to be transformed.
Returns:
PIL Image or Tensor: AutoAugmented image.
| forward | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/autoaugment.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/autoaugment.py | Apache-2.0 |
def to_tensor(pic):
"""Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor.
See :class:`~paddlevision.transforms.ToTensor` for more details.
Args:
pic (PIL Image or numpy.ndarray): Image to be converted to tensor.
Returns:
Tensor: Converted image.
"""
if not (F_pil._is_pil_... | Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor.
See :class:`~paddlevision.transforms.ToTensor` for more details.
Args:
pic (PIL Image or numpy.ndarray): Image to be converted to tensor.
Returns:
Tensor: Converted image.
| to_tensor | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
def normalize(tensor: Tensor,
mean: List[float],
std: List[float],
inplace: bool=False) -> Tensor:
"""Normalize a float tensor image with mean and standard deviation.
This transform does not support PIL Image.
.. note::
This transform acts out of place by d... | Normalize a float tensor image with mean and standard deviation.
This transform does not support PIL Image.
.. note::
This transform acts out of place by default, i.e., it does not mutates the input tensor.
See :class:`~paddlevision.transforms.Normalize` for more details.
Args:
tensor... | normalize | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
def resize(img: Tensor,
size: List[int],
interpolation: InterpolationMode=InterpolationMode.BILINEAR,
max_size: Optional[int]=None,
antialias: Optional[bool]=None) -> Tensor:
r"""Resize the input image to the given size.
If the image is paddle Tensor, it is expected
... | Resize the input image to the given size.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
.. warning::
The output image might be different depending on its type: when downsampling, the interpolation of PIL images
... | resize | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
def pad(img: Tensor,
padding: List[int],
fill: int=0,
padding_mode: str="constant") -> Tensor:
r"""Pad the given image on all sides with the given "pad" value.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means at most 2 leading dimensions for mo... | Pad the given image on all sides with the given "pad" value.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means at most 2 leading dimensions for mode reflect and symmetric,
at most 3 leading dimensions for mode edge,
and an arbitrary number of leading dimensions for... | pad | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
def crop(img: Tensor, top: int, left: int, height: int, width: int) -> Tensor:
"""Crop the given image at specified location and output size.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.
If image size is smaller than ... | Crop the given image at specified location and output size.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.
If image size is smaller than output size along any edge, image is padded with 0 and then cropped.
Args:
... | crop | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
def center_crop(img: Tensor, output_size: List[int]) -> Tensor:
"""Crops the given image at the center.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.
If image size is smaller than output size along any edge, image is p... | Crops the given image at the center.
If the image is paddle Tensor, it is expected
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.
If image size is smaller than output size along any edge, image is padded with 0 and then center cropped.
Args:
img (PIL Image... | center_crop | python | PaddlePaddle/models | tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | https://github.com/PaddlePaddle/models/blob/master/tutorials/mobilenetv3_prod/Step1-5/mobilenetv3_paddle/paddlevision/transforms/functional.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.