提交 12db91d8 编写于 作者: M mamingjie-China

update copy right

上级 534eda3e
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -225,7 +225,6 @@ def generate_minibatch(batch_data, label_padding_value=255): ...@@ -225,7 +225,6 @@ def generate_minibatch(batch_data, label_padding_value=255):
data[1].append(('padding', [im_h, im_w])) data[1].append(('padding', [im_h, im_w]))
padding_batch.append((padding_im, data[1], data[2])) padding_batch.append((padding_im, data[1], data[2]))
elif len(data) > 1: elif len(data) > 1:
if isinstance(data[1], np.ndarray) and len(data[1].shape) > 1: if isinstance(data[1], np.ndarray) and len(data[1].shape) > 1:
# padding the image and label of segmentation during the training # padding the image and label of segmentation during the training
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -25,6 +25,7 @@ from .voc import VOCDetection ...@@ -25,6 +25,7 @@ from .voc import VOCDetection
from .dataset import is_pic from .dataset import is_pic
from .dataset import get_encoding from .dataset import get_encoding
class EasyDataDet(VOCDetection): class EasyDataDet(VOCDetection):
"""读取EasyDataDet格式的检测数据集,并对样本进行相应的处理。 """读取EasyDataDet格式的检测数据集,并对样本进行相应的处理。
...@@ -95,8 +96,8 @@ class EasyDataDet(VOCDetection): ...@@ -95,8 +96,8 @@ class EasyDataDet(VOCDetection):
if not osp.isfile(json_file): if not osp.isfile(json_file):
continue continue
if not osp.exists(img_file): if not osp.exists(img_file):
raise IOError( raise IOError('The image file {} is not exist!'.format(
'The image file {} is not exist!'.format(img_file)) img_file))
with open(json_file, mode='r', \ with open(json_file, mode='r', \
encoding=get_encoding(json_file)) as j: encoding=get_encoding(json_file)) as j:
json_info = json.load(j) json_info = json.load(j)
...@@ -127,21 +128,15 @@ class EasyDataDet(VOCDetection): ...@@ -127,21 +128,15 @@ class EasyDataDet(VOCDetection):
mask = decode(mask_dict) mask = decode(mask_dict)
gt_poly[i] = self.mask2polygon(mask) gt_poly[i] = self.mask2polygon(mask)
annotations['annotations'].append({ annotations['annotations'].append({
'iscrowd': 'iscrowd': 0,
0, 'image_id': int(im_id[0]),
'image_id':
int(im_id[0]),
'bbox': [x1, y1, x2 - x1 + 1, y2 - y1 + 1], 'bbox': [x1, y1, x2 - x1 + 1, y2 - y1 + 1],
'area': 'area': float((x2 - x1 + 1) * (y2 - y1 + 1)),
float((x2 - x1 + 1) * (y2 - y1 + 1)), 'segmentation': [[x1, y1, x1, y2, x2, y2, x2, y1]]
'segmentation': if gt_poly[i] is None else gt_poly[i],
[[x1, y1, x1, y2, x2, y2, x2, y1]] if gt_poly[i] is None else gt_poly[i], 'category_id': cname2cid[cname],
'category_id': 'id': ann_ct,
cname2cid[cname], 'difficult': 0
'id':
ann_ct,
'difficult':
0
}) })
ann_ct += 1 ann_ct += 1
im_info = { im_info = {
...@@ -162,14 +157,10 @@ class EasyDataDet(VOCDetection): ...@@ -162,14 +157,10 @@ class EasyDataDet(VOCDetection):
self.file_list.append([img_file, voc_rec]) self.file_list.append([img_file, voc_rec])
ct += 1 ct += 1
annotations['images'].append({ annotations['images'].append({
'height': 'height': im_h,
im_h, 'width': im_w,
'width': 'id': int(im_id[0]),
im_w, 'file_name': osp.split(img_file)[1]
'id':
int(im_id[0]),
'file_name':
osp.split(img_file)[1]
}) })
if not len(self.file_list) > 0: if not len(self.file_list) > 0:
...@@ -184,7 +175,7 @@ class EasyDataDet(VOCDetection): ...@@ -184,7 +175,7 @@ class EasyDataDet(VOCDetection):
def mask2polygon(self, mask): def mask2polygon(self, mask):
contours, hierarchy = cv2.findContours( contours, hierarchy = cv2.findContours(
(mask).astype(np.uint8), cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) (mask).astype(np.uint8), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
segmentation = [] segmentation = []
for contour in contours: for contour in contours:
contour_list = contour.flatten().tolist() contour_list = contour.flatten().tolist()
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -25,6 +25,7 @@ from .dataset import Dataset ...@@ -25,6 +25,7 @@ from .dataset import Dataset
from .dataset import get_encoding from .dataset import get_encoding
from .dataset import is_pic from .dataset import is_pic
class EasyDataSeg(Dataset): class EasyDataSeg(Dataset):
"""读取EasyDataSeg语义分割任务数据集,并对样本进行相应的处理。 """读取EasyDataSeg语义分割任务数据集,并对样本进行相应的处理。
...@@ -79,8 +80,8 @@ class EasyDataSeg(Dataset): ...@@ -79,8 +80,8 @@ class EasyDataSeg(Dataset):
if not osp.isfile(json_file): if not osp.isfile(json_file):
continue continue
if not osp.exists(img_file): if not osp.exists(img_file):
raise IOError( raise IOError('The image file {} is not exist!'.format(
'The image file {} is not exist!'.format(img_file)) img_file))
with open(json_file, mode='r', \ with open(json_file, mode='r', \
encoding=get_encoding(json_file)) as j: encoding=get_encoding(json_file)) as j:
json_info = json.load(j) json_info = json.load(j)
...@@ -97,7 +98,8 @@ class EasyDataSeg(Dataset): ...@@ -97,7 +98,8 @@ class EasyDataSeg(Dataset):
mask_dict['counts'] = obj['mask'].encode() mask_dict['counts'] = obj['mask'].encode()
mask = decode(mask_dict) mask = decode(mask_dict)
mask *= cid mask *= cid
conflict_index = np.where(((lable_npy > 0) & (mask == cid)) == True) conflict_index = np.where(((lable_npy > 0) &
(mask == cid)) == True)
mask[conflict_index] = 0 mask[conflict_index] = 0
lable_npy += mask lable_npy += mask
self.file_list.append([img_file, lable_npy]) self.file_list.append([img_file, lable_npy])
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -278,8 +278,8 @@ class PageAllocator(object): ...@@ -278,8 +278,8 @@ class PageAllocator(object):
def set_alloc_info(self, alloc_pos, used_pages): def set_alloc_info(self, alloc_pos, used_pages):
""" set allocating position to new value """ set allocating position to new value
""" """
memcopy(self._base[4:12], struct.pack( memcopy(self._base[4:12],
str('II'), alloc_pos, used_pages)) struct.pack(str('II'), alloc_pos, used_pages))
def set_page_status(self, start, page_num, status): def set_page_status(self, start, page_num, status):
""" set pages from 'start' to 'end' with new same status 'status' """ set pages from 'start' to 'end' with new same status 'status'
...@@ -525,8 +525,8 @@ class SharedMemoryMgr(object): ...@@ -525,8 +525,8 @@ class SharedMemoryMgr(object):
logger.info('destroy [%s]' % (self)) logger.info('destroy [%s]' % (self))
if not self._released and not self._allocator.empty(): if not self._released and not self._allocator.empty():
logger.debug( logger.debug('not empty when delete this SharedMemoryMgr[%s]' %
'not empty when delete this SharedMemoryMgr[%s]' % (self)) (self))
else: else:
self._released = True self._released = True
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -246,8 +246,8 @@ class BaseAPI: ...@@ -246,8 +246,8 @@ class BaseAPI:
logging.info( logging.info(
"Load pretrain weights from {}.".format(pretrain_weights), "Load pretrain weights from {}.".format(pretrain_weights),
use_color=True) use_color=True)
paddlex.utils.utils.load_pretrain_weights(self.exe, self.train_prog, paddlex.utils.utils.load_pretrain_weights(
pretrain_weights, fuse_bn) self.exe, self.train_prog, pretrain_weights, fuse_bn)
# 进行裁剪 # 进行裁剪
if sensitivities_file is not None: if sensitivities_file is not None:
import paddleslim import paddleslim
...@@ -351,7 +351,9 @@ class BaseAPI: ...@@ -351,7 +351,9 @@ class BaseAPI:
logging.info("Model saved in {}.".format(save_dir)) logging.info("Model saved in {}.".format(save_dir))
def export_inference_model(self, save_dir): def export_inference_model(self, save_dir):
test_input_names = [var.name for var in list(self.test_inputs.values())] test_input_names = [
var.name for var in list(self.test_inputs.values())
]
test_outputs = list(self.test_outputs.values()) test_outputs = list(self.test_outputs.values())
with fluid.scope_guard(self.scope): with fluid.scope_guard(self.scope):
if self.__class__.__name__ == 'MaskRCNN': if self.__class__.__name__ == 'MaskRCNN':
...@@ -389,7 +391,8 @@ class BaseAPI: ...@@ -389,7 +391,8 @@ class BaseAPI:
# 模型保存成功的标志 # 模型保存成功的标志
open(osp.join(save_dir, '.success'), 'w').close() open(osp.join(save_dir, '.success'), 'w').close()
logging.info("Model for inference deploy saved in {}.".format(save_dir)) logging.info("Model for inference deploy saved in {}.".format(
save_dir))
def train_loop(self, def train_loop(self,
num_epochs, num_epochs,
...@@ -516,10 +519,12 @@ class BaseAPI: ...@@ -516,10 +519,12 @@ class BaseAPI:
eta = ((num_epochs - i) * total_num_steps - step - 1 eta = ((num_epochs - i) * total_num_steps - step - 1
) * avg_step_time ) * avg_step_time
if time_eval_one_epoch is not None: if time_eval_one_epoch is not None:
eval_eta = (total_eval_times - i // save_interval_epochs eval_eta = (
total_eval_times - i // save_interval_epochs
) * time_eval_one_epoch ) * time_eval_one_epoch
else: else:
eval_eta = (total_eval_times - i // save_interval_epochs eval_eta = (
total_eval_times - i // save_interval_epochs
) * total_num_steps_eval * avg_step_time ) * total_num_steps_eval * avg_step_time
eta_str = seconds_to_hms(eta + eval_eta) eta_str = seconds_to_hms(eta + eval_eta)
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -103,8 +103,8 @@ def load_model(model_dir, fixed_input_shape=None): ...@@ -103,8 +103,8 @@ def load_model(model_dir, fixed_input_shape=None):
model.model_type, info['Transforms'], info['BatchTransforms']) model.model_type, info['Transforms'], info['BatchTransforms'])
model.eval_transforms = copy.deepcopy(model.test_transforms) model.eval_transforms = copy.deepcopy(model.test_transforms)
else: else:
model.test_transforms = build_transforms(model.model_type, model.test_transforms = build_transforms(
info['Transforms'], to_rgb) model.model_type, info['Transforms'], to_rgb)
model.eval_transforms = copy.deepcopy(model.test_transforms) model.eval_transforms = copy.deepcopy(model.test_transforms)
if '_Attributes' in info: if '_Attributes' in info:
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -280,8 +280,9 @@ class MaskRCNN(FasterRCNN): ...@@ -280,8 +280,9 @@ class MaskRCNN(FasterRCNN):
total_steps = math.ceil(eval_dataset.num_samples * 1.0 / batch_size) total_steps = math.ceil(eval_dataset.num_samples * 1.0 / batch_size)
results = list() results = list()
logging.info("Start to evaluating(total_samples={}, total_steps={})...". logging.info(
format(eval_dataset.num_samples, total_steps)) "Start to evaluating(total_samples={}, total_steps={})...".format(
eval_dataset.num_samples, total_steps))
for step, data in tqdm.tqdm( for step, data in tqdm.tqdm(
enumerate(data_generator()), total=total_steps): enumerate(data_generator()), total=total_steps):
images = np.array([d[0] for d in data]).astype('float32') images = np.array([d[0] for d in data]).astype('float32')
...@@ -325,7 +326,8 @@ class MaskRCNN(FasterRCNN): ...@@ -325,7 +326,8 @@ class MaskRCNN(FasterRCNN):
zip(['bbox_map', 'segm_map'], zip(['bbox_map', 'segm_map'],
[ap_stats[0][1], ap_stats[1][1]])) [ap_stats[0][1], ap_stats[1][1]]))
else: else:
metrics = OrderedDict(zip(['bbox_map', 'segm_map'], [0.0, 0.0])) metrics = OrderedDict(
zip(['bbox_map', 'segm_map'], [0.0, 0.0]))
elif metric == 'COCO': elif metric == 'COCO':
if isinstance(ap_stats[0], np.ndarray) and isinstance(ap_stats[1], if isinstance(ap_stats[0], np.ndarray) and isinstance(ap_stats[1],
np.ndarray): np.ndarray):
...@@ -429,8 +431,8 @@ class MaskRCNN(FasterRCNN): ...@@ -429,8 +431,8 @@ class MaskRCNN(FasterRCNN):
if transforms is None: if transforms is None:
transforms = self.test_transforms transforms = self.test_transforms
im, im_resize_info, im_shape = FasterRCNN._preprocess( im, im_resize_info, im_shape = FasterRCNN._preprocess(
img_file_list, transforms, self.model_type, self.__class__.__name__, img_file_list, transforms, self.model_type,
thread_num) self.__class__.__name__, thread_num)
with fluid.scope_guard(self.scope): with fluid.scope_guard(self.scope):
result = self.exe.run(self.test_prog, result = self.exe.run(self.test_prog,
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -80,7 +80,9 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization): ...@@ -80,7 +80,9 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
self._support_activation_quantize_type = [ self._support_activation_quantize_type = [
'range_abs_max', 'moving_average_abs_max', 'abs_max' 'range_abs_max', 'moving_average_abs_max', 'abs_max'
] ]
self._support_weight_quantize_type = ['abs_max', 'channel_wise_abs_max'] self._support_weight_quantize_type = [
'abs_max', 'channel_wise_abs_max'
]
self._support_algo_type = ['KL', 'abs_max', 'min_max'] self._support_algo_type = ['KL', 'abs_max', 'min_max']
self._support_quantize_op_type = \ self._support_quantize_op_type = \
list(set(QuantizationTransformPass._supported_quantizable_op_type + list(set(QuantizationTransformPass._supported_quantizable_op_type +
...@@ -240,8 +242,8 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization): ...@@ -240,8 +242,8 @@ class PaddleXPostTrainingQuantization(PostTrainingQuantization):
'[Calculate weight] Weight_id={}/{}, time_each_weight={} s.'. '[Calculate weight] Weight_id={}/{}, time_each_weight={} s.'.
format( format(
str(ct), str(ct),
str(len(self._quantized_weight_var_name)), str(end - str(len(self._quantized_weight_var_name)),
start))) str(end - start)))
ct += 1 ct += 1
ct = 1 ct = 1
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -288,8 +288,8 @@ def get_params_ratios(sensitivities_file, eval_metric_loss=0.05): ...@@ -288,8 +288,8 @@ def get_params_ratios(sensitivities_file, eval_metric_loss=0.05):
if not osp.exists(sensitivities_file): if not osp.exists(sensitivities_file):
raise Exception('The sensitivities file is not exists!') raise Exception('The sensitivities file is not exists!')
sensitivitives = paddleslim.prune.load_sensitivities(sensitivities_file) sensitivitives = paddleslim.prune.load_sensitivities(sensitivities_file)
params_ratios = paddleslim.prune.get_ratios_by_loss( params_ratios = paddleslim.prune.get_ratios_by_loss(sensitivitives,
sensitivitives, eval_metric_loss) eval_metric_loss)
return params_ratios return params_ratios
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -47,8 +47,7 @@ def visualize(model, sensitivities_file, save_dir='./'): ...@@ -47,8 +47,7 @@ def visualize(model, sensitivities_file, save_dir='./'):
y.append(loss_thresh) y.append(loss_thresh)
plt.plot(x, y, color='green', linewidth=0.5, marker='o', markersize=3) plt.plot(x, y, color='green', linewidth=0.5, marker='o', markersize=3)
my_x_ticks = np.arange( my_x_ticks = np.arange(
min(np.array(x)) - 0.01, min(np.array(x)) - 0.01, max(np.array(x)) + 0.01, 0.05)
max(np.array(x)) + 0.01, 0.05)
my_y_ticks = np.arange(0.05, 1, 0.05) my_y_ticks = np.arange(0.05, 1, 0.05)
plt.xticks(my_x_ticks, rotation=15, fontsize=8) plt.xticks(my_x_ticks, rotation=15, fontsize=8)
plt.yticks(my_y_ticks, fontsize=8) plt.yticks(my_y_ticks, fontsize=8)
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -158,8 +158,8 @@ def loadRes(coco_obj, anns): ...@@ -158,8 +158,8 @@ def loadRes(coco_obj, anns):
for id, ann in enumerate(anns): for id, ann in enumerate(anns):
ann['id'] = id + 1 ann['id'] = id + 1
elif 'bbox' in anns[0] and not anns[0]['bbox'] == []: elif 'bbox' in anns[0] and not anns[0]['bbox'] == []:
res.dataset['categories'] = copy.deepcopy( res.dataset['categories'] = copy.deepcopy(coco_obj.dataset[
coco_obj.dataset['categories']) 'categories'])
for id, ann in enumerate(anns): for id, ann in enumerate(anns):
bb = ann['bbox'] bb = ann['bbox']
x1, x2, y1, y2 = [bb[0], bb[0] + bb[2], bb[1], bb[1] + bb[3]] x1, x2, y1, y2 = [bb[0], bb[0] + bb[2], bb[1], bb[1] + bb[3]]
...@@ -169,8 +169,8 @@ def loadRes(coco_obj, anns): ...@@ -169,8 +169,8 @@ def loadRes(coco_obj, anns):
ann['id'] = id + 1 ann['id'] = id + 1
ann['iscrowd'] = 0 ann['iscrowd'] = 0
elif 'segmentation' in anns[0]: elif 'segmentation' in anns[0]:
res.dataset['categories'] = copy.deepcopy( res.dataset['categories'] = copy.deepcopy(coco_obj.dataset[
coco_obj.dataset['categories']) 'categories'])
for id, ann in enumerate(anns): for id, ann in enumerate(anns):
# now only support compressed RLE format as segmentation results # now only support compressed RLE format as segmentation results
ann['area'] = maskUtils.area(ann['segmentation']) ann['area'] = maskUtils.area(ann['segmentation'])
...@@ -179,8 +179,8 @@ def loadRes(coco_obj, anns): ...@@ -179,8 +179,8 @@ def loadRes(coco_obj, anns):
ann['id'] = id + 1 ann['id'] = id + 1
ann['iscrowd'] = 0 ann['iscrowd'] = 0
elif 'keypoints' in anns[0]: elif 'keypoints' in anns[0]:
res.dataset['categories'] = copy.deepcopy( res.dataset['categories'] = copy.deepcopy(coco_obj.dataset[
coco_obj.dataset['categories']) 'categories'])
for id, ann in enumerate(anns): for id, ann in enumerate(anns):
s = ann['keypoints'] s = ann['keypoints']
x = s[0::3] x = s[0::3]
...@@ -375,8 +375,8 @@ def mask2out(results, clsid2catid, resolution, thresh_binarize=0.5): ...@@ -375,8 +375,8 @@ def mask2out(results, clsid2catid, resolution, thresh_binarize=0.5):
expand_bbox = expand_boxes(bbox, scale) expand_bbox = expand_boxes(bbox, scale)
expand_bbox = expand_bbox.astype(np.int32) expand_bbox = expand_bbox.astype(np.int32)
padded_mask = np.zeros((resolution + 2, resolution + 2), padded_mask = np.zeros(
dtype=np.float32) (resolution + 2, resolution + 2), dtype=np.float32)
for j in range(num): for j in range(num):
xmin, ymin, xmax, ymax = expand_bbox[j].tolist() xmin, ymin, xmax, ymax = expand_bbox[j].tolist()
...@@ -404,7 +404,8 @@ def mask2out(results, clsid2catid, resolution, thresh_binarize=0.5): ...@@ -404,7 +404,8 @@ def mask2out(results, clsid2catid, resolution, thresh_binarize=0.5):
im_mask[y0:y1, x0:x1] = resized_mask[(y0 - ymin):(y1 - ymin), ( im_mask[y0:y1, x0:x1] = resized_mask[(y0 - ymin):(y1 - ymin), (
x0 - xmin):(x1 - xmin)] x0 - xmin):(x1 - xmin)]
segm = mask_util.encode( segm = mask_util.encode(
np.array(im_mask[:, :, np.newaxis], order='F'))[0] np.array(
im_mask[:, :, np.newaxis], order='F'))[0]
catid = clsid2catid[clsid] catid = clsid2catid[clsid]
segm['counts'] = segm['counts'].decode('utf8') segm['counts'] = segm['counts'].decode('utf8')
coco_res = { coco_res = {
...@@ -571,8 +572,8 @@ def prune_zero_padding(gt_box, gt_label, difficult=None): ...@@ -571,8 +572,8 @@ def prune_zero_padding(gt_box, gt_label, difficult=None):
gt_box[i, 2] == 0 and gt_box[i, 3] == 0: gt_box[i, 2] == 0 and gt_box[i, 3] == 0:
break break
valid_cnt += 1 valid_cnt += 1
return (gt_box[:valid_cnt], gt_label[:valid_cnt], return (gt_box[:valid_cnt], gt_label[:valid_cnt], difficult[:valid_cnt]
difficult[:valid_cnt] if difficult is not None else None) if difficult is not None else None)
def bbox_area(bbox, is_bbox_normalized): def bbox_area(bbox, is_bbox_normalized):
...@@ -694,8 +695,9 @@ class DetectionMAP(object): ...@@ -694,8 +695,9 @@ class DetectionMAP(object):
""" """
mAP = 0. mAP = 0.
valid_cnt = 0 valid_cnt = 0
for id, (score_pos, count) in enumerate( for id, (
zip(self.class_score_poss, self.class_gt_counts)): score_pos, count
) in enumerate(zip(self.class_score_poss, self.class_gt_counts)):
if count == 0: continue if count == 0: continue
if len(score_pos) == 0: if len(score_pos) == 0:
valid_cnt += 1 valid_cnt += 1
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -24,8 +24,8 @@ class ConfusionMatrix(object): ...@@ -24,8 +24,8 @@ class ConfusionMatrix(object):
""" """
def __init__(self, num_classes=2, streaming=False): def __init__(self, num_classes=2, streaming=False):
self.confusion_matrix = np.zeros([num_classes, num_classes], self.confusion_matrix = np.zeros(
dtype='int64') [num_classes, num_classes], dtype='int64')
self.num_classes = num_classes self.num_classes = num_classes
self.streaming = streaming self.streaming = streaming
...@@ -42,15 +42,15 @@ class ConfusionMatrix(object): ...@@ -42,15 +42,15 @@ class ConfusionMatrix(object):
pred = np.asarray(pred)[mask] pred = np.asarray(pred)[mask]
one = np.ones_like(pred) one = np.ones_like(pred)
# Accumuate ([row=label, col=pred], 1) into sparse matrix # Accumuate ([row=label, col=pred], 1) into sparse matrix
spm = csr_matrix((one, (label, pred)), spm = csr_matrix(
shape=(self.num_classes, self.num_classes)) (one, (label, pred)), shape=(self.num_classes, self.num_classes))
spm = spm.todense() spm = spm.todense()
self.confusion_matrix += spm self.confusion_matrix += spm
def zero_matrix(self): def zero_matrix(self):
""" Clear confusion matrix """ """ Clear confusion matrix """
self.confusion_matrix = np.zeros([self.num_classes, self.num_classes], self.confusion_matrix = np.zeros(
dtype='int64') [self.num_classes, self.num_classes], dtype='int64')
def mean_iou(self): def mean_iou(self):
iou_list = [] iou_list = []
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -404,7 +404,8 @@ def draw_pr_curve(eval_details_file=None, ...@@ -404,7 +404,8 @@ def draw_pr_curve(eval_details_file=None,
plt.plot(x, sr_array, color=color, label=nm, linewidth=1) plt.plot(x, sr_array, color=color, label=nm, linewidth=1)
plt.legend(loc="lower left", fontsize=5) plt.legend(loc="lower left", fontsize=5)
plt.savefig( plt.savefig(
os.path.join(save_dir, os.path.join(
save_dir,
"./{}_pr_curve(iou-{}).png".format(style, iou_thresh)), "./{}_pr_curve(iou-{}).png".format(style, iou_thresh)),
dpi=800) dpi=800)
plt.close() plt.close()
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -30,10 +30,10 @@ class MobileNetV2: ...@@ -30,10 +30,10 @@ class MobileNetV2:
self.output_stride = output_stride self.output_stride = output_stride
self.end_points = end_points self.end_points = end_points
self.decode_points = decode_points self.decode_points = decode_points
self.bottleneck_params_list = [(1, 16, 1, 1), (6, 24, 2, 2), self.bottleneck_params_list = [
(6, 32, 3, 2), (6, 64, 4, 2), (1, 16, 1, 1), (6, 24, 2, 2), (6, 32, 3, 2), (6, 64, 4, 2),
(6, 96, 3, 1), (6, 160, 3, 2), (6, 96, 3, 1), (6, 160, 3, 2), (6, 320, 1, 1)
(6, 320, 1, 1)] ]
self.modify_bottle_params(output_stride) self.modify_bottle_params(output_stride)
def __call__(self, input): def __call__(self, input):
...@@ -104,8 +104,7 @@ class MobileNetV2: ...@@ -104,8 +104,7 @@ class MobileNetV2:
output = fluid.layers.pool2d( output = fluid.layers.pool2d(
input=output, pool_type='avg', global_pooling=True) input=output, pool_type='avg', global_pooling=True)
output = fluid.layers.fc( output = fluid.layers.fc(input=output,
input=output,
size=self.num_classes, size=self.num_classes,
param_attr=ParamAttr(name='fc10_weights'), param_attr=ParamAttr(name='fc10_weights'),
bias_attr=ParamAttr(name='fc10_offset')) bias_attr=ParamAttr(name='fc10_offset'))
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -148,7 +148,8 @@ def separate_conv(input, ...@@ -148,7 +148,8 @@ def separate_conv(input,
name=name_scope + 'weights', name=name_scope + 'weights',
regularizer=fluid.regularizer.L2DecayRegularizer( regularizer=fluid.regularizer.L2DecayRegularizer(
regularization_coeff=0.0), regularization_coeff=0.0),
initializer=fluid.initializer.TruncatedNormal(loc=0.0, scale=0.33)) initializer=fluid.initializer.TruncatedNormal(
loc=0.0, scale=0.33))
with scope('depthwise'): with scope('depthwise'):
input = conv( input = conv(
input, input,
...@@ -166,7 +167,8 @@ def separate_conv(input, ...@@ -166,7 +167,8 @@ def separate_conv(input,
param_attr = fluid.ParamAttr( param_attr = fluid.ParamAttr(
name=name_scope + 'weights', name=name_scope + 'weights',
regularizer=None, regularizer=None,
initializer=fluid.initializer.TruncatedNormal(loc=0.0, scale=0.06)) initializer=fluid.initializer.TruncatedNormal(
loc=0.0, scale=0.06))
with scope('pointwise'): with scope('pointwise'):
input = conv( input = conv(
input, channel, 1, 1, groups=1, padding=0, param_attr=param_attr) input, channel, 1, 1, groups=1, padding=0, param_attr=param_attr)
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -24,8 +24,9 @@ def softmax_with_loss(logit, ...@@ -24,8 +24,9 @@ def softmax_with_loss(logit,
ignore_index=255): ignore_index=255):
ignore_mask = fluid.layers.cast(ignore_mask, 'float32') ignore_mask = fluid.layers.cast(ignore_mask, 'float32')
label = fluid.layers.elementwise_min( label = fluid.layers.elementwise_min(
label, fluid.layers.assign( label,
np.array([num_classes - 1], dtype=np.int32))) fluid.layers.assign(np.array(
[num_classes - 1], dtype=np.int32)))
logit = fluid.layers.transpose(logit, [0, 2, 3, 1]) logit = fluid.layers.transpose(logit, [0, 2, 3, 1])
logit = fluid.layers.reshape(logit, [-1, num_classes]) logit = fluid.layers.reshape(logit, [-1, num_classes])
label = fluid.layers.reshape(label, [-1, 1]) label = fluid.layers.reshape(label, [-1, 1])
...@@ -60,8 +61,8 @@ def softmax_with_loss(logit, ...@@ -60,8 +61,8 @@ def softmax_with_loss(logit,
'Expect weight is a list, string or Variable, but receive {}'. 'Expect weight is a list, string or Variable, but receive {}'.
format(type(weight))) format(type(weight)))
weight = fluid.layers.reshape(weight, [1, num_classes]) weight = fluid.layers.reshape(weight, [1, num_classes])
weighted_label_one_hot = fluid.layers.elementwise_mul( weighted_label_one_hot = fluid.layers.elementwise_mul(label_one_hot,
label_one_hot, weight) weight)
probs = fluid.layers.softmax(logit) probs = fluid.layers.softmax(logit)
loss = fluid.layers.cross_entropy( loss = fluid.layers.cross_entropy(
probs, probs,
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -96,10 +96,11 @@ class ShuffleNetV2(): ...@@ -96,10 +96,11 @@ class ShuffleNetV2():
pool_stride=1, pool_stride=1,
pool_padding=0, pool_padding=0,
pool_type='avg') pool_type='avg')
output = fluid.layers.fc( output = fluid.layers.fc(input=output,
input=output,
size=self.num_classes, size=self.num_classes,
param_attr=ParamAttr(initializer=MSRA(), name='fc6_weights'), param_attr=ParamAttr(
initializer=MSRA(),
name='fc6_weights'),
bias_attr=ParamAttr(name='fc6_offset')) bias_attr=ParamAttr(name='fc6_offset'))
return output return output
...@@ -122,7 +123,8 @@ class ShuffleNetV2(): ...@@ -122,7 +123,8 @@ class ShuffleNetV2():
groups=num_groups, groups=num_groups,
act=None, act=None,
use_cudnn=use_cudnn, use_cudnn=use_cudnn,
param_attr=ParamAttr(initializer=MSRA(), name=name + '_weights'), param_attr=ParamAttr(
initializer=MSRA(), name=name + '_weights'),
bias_attr=False) bias_attr=False)
out = int((input.shape[2] - 1) / float(stride) + 1) out = int((input.shape[2] - 1) / float(stride) + 1)
bn_name = name + '_bn' bn_name = name + '_bn'
......
# coding: utf8 # coding: utf8
# copyright (c) 2019 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -69,8 +69,7 @@ class Xception(): ...@@ -69,8 +69,7 @@ class Xception():
def __call__( def __call__(
self, self,
input, input, ):
):
self.stride = 2 self.stride = 2
self.block_point = 0 self.block_point = 0
self.short_cuts = dict() self.short_cuts = dict()
...@@ -140,7 +139,8 @@ class Xception(): ...@@ -140,7 +139,8 @@ class Xception():
param_attr = fluid.ParamAttr( param_attr = fluid.ParamAttr(
name=name_scope + 'weights', name=name_scope + 'weights',
regularizer=None, regularizer=None,
initializer=fluid.initializer.TruncatedNormal(loc=0.0, scale=0.09)) initializer=fluid.initializer.TruncatedNormal(
loc=0.0, scale=0.09))
with scope("entry_flow"): with scope("entry_flow"):
with scope("conv1"): with scope("conv1"):
data = bn_relu( data = bn_relu(
...@@ -178,10 +178,10 @@ class Xception(): ...@@ -178,10 +178,10 @@ class Xception():
for i in range(block_num): for i in range(block_num):
block_point = block_point + 1 block_point = block_point + 1
with scope("block" + str(i + 1)): with scope("block" + str(i + 1)):
stride = strides[i] if check_stride( stride = strides[i] if check_stride(s * strides[i],
s * strides[i], output_stride) else 1 output_stride) else 1
data, short_cuts = self.xception_block( data, short_cuts = self.xception_block(data, chns[i],
data, chns[i], [1, 1, stride]) [1, 1, stride])
s = s * stride s = s * stride
if check_points(block_point, self.decode_points): if check_points(block_point, self.decode_points):
self.short_cuts[block_point] = short_cuts[1] self.short_cuts[block_point] = short_cuts[1]
...@@ -205,8 +205,8 @@ class Xception(): ...@@ -205,8 +205,8 @@ class Xception():
for i in range(block_num): for i in range(block_num):
block_point = block_point + 1 block_point = block_point + 1
with scope("block" + str(i + 1)): with scope("block" + str(i + 1)):
stride = strides[i] if check_stride( stride = strides[i] if check_stride(s * strides[i],
s * strides[i], output_stride) else 1 output_stride) else 1
data, short_cuts = self.xception_block( data, short_cuts = self.xception_block(
data, chns[i], [1, 1, strides[i]], skip_conv=False) data, chns[i], [1, 1, strides[i]], skip_conv=False)
s = s * stride s = s * stride
...@@ -302,8 +302,7 @@ class Xception(): ...@@ -302,8 +302,7 @@ class Xception():
initializer=fluid.initializer.TruncatedNormal( initializer=fluid.initializer.TruncatedNormal(
loc=0.0, scale=0.09)) loc=0.0, scale=0.09))
with scope('shortcut'): with scope('shortcut'):
skip = bn( skip = bn(conv(
conv(
input, input,
channels[-1], channels[-1],
1, 1,
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -170,7 +170,8 @@ def expand_segms(segms, x, y, height, width, ratio): ...@@ -170,7 +170,8 @@ def expand_segms(segms, x, y, height, width, ratio):
0).astype(mask.dtype) 0).astype(mask.dtype)
expanded_mask[y:y + height, x:x + width] = mask expanded_mask[y:y + height, x:x + width] = mask
rle = mask_util.encode( rle = mask_util.encode(
np.array(expanded_mask, order='F', dtype=np.uint8)) np.array(
expanded_mask, order='F', dtype=np.uint8))
return rle return rle
expanded_segms = [] expanded_segms = []
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -69,8 +69,8 @@ def random_crop(im, ...@@ -69,8 +69,8 @@ def random_crop(im,
(float(im.shape[1]) / im.shape[0]) / (w**2)) (float(im.shape[1]) / im.shape[0]) / (w**2))
scale_max = min(scale[1], bound) scale_max = min(scale[1], bound)
scale_min = min(scale[0], bound) scale_min = min(scale[0], bound)
target_area = im.shape[0] * im.shape[1] * np.random.uniform( target_area = im.shape[0] * im.shape[1] * np.random.uniform(scale_min,
scale_min, scale_max) scale_max)
target_size = math.sqrt(target_area) target_size = math.sqrt(target_area)
w = int(target_size * w) w = int(target_size * w)
h = int(target_size * h) h = int(target_size * h)
...@@ -146,6 +146,7 @@ def brightness(im, brightness_lower, brightness_upper): ...@@ -146,6 +146,7 @@ def brightness(im, brightness_lower, brightness_upper):
im += delta im += delta
return im return im
def rotate(im, rotate_lower, rotate_upper): def rotate(im, rotate_lower, rotate_upper):
rotate_delta = np.random.uniform(rotate_lower, rotate_upper) rotate_delta = np.random.uniform(rotate_lower, rotate_upper)
im = im.rotate(int(rotate_delta)) im = im.rotate(int(rotate_delta))
......
# coding: utf8 # coding: utf8
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -48,6 +48,7 @@ def _draw_rectangle_and_cname(img, xmin, ymin, xmax, ymax, cname, color): ...@@ -48,6 +48,7 @@ def _draw_rectangle_and_cname(img, xmin, ymin, xmax, ymax, cname, color):
thickness=line_width) thickness=line_width)
return img return img
def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0): def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0):
""" """
Args: Args:
...@@ -64,8 +65,8 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0): ...@@ -64,8 +65,8 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0):
if isinstance(im, np.ndarray): if isinstance(im, np.ndarray):
if len(im.shape) != 3: if len(im.shape) != 3:
raise Exception( raise Exception(
"im should be 3-dimension, but now is {}-dimensions". "im should be 3-dimension, but now is {}-dimensions".format(
format(len(im.shape))) len(im.shape)))
else: else:
try: try:
im = cv2.imread(im).astype('float32') im = cv2.imread(im).astype('float32')
...@@ -73,9 +74,8 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0): ...@@ -73,9 +74,8 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0):
raise TypeError('Can\'t read The image file {}!'.format(im)) raise TypeError('Can\'t read The image file {}!'.format(im))
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
if vdl_writer is not None: if vdl_writer is not None:
vdl_writer.add_image(tag='0. OriginalImage/' + str(step), vdl_writer.add_image(
img=im, tag='0. OriginalImage/' + str(step), img=im, step=0)
step=0)
op_id = 1 op_id = 1
for op in transforms: for op in transforms:
if isinstance(op, ClsTransform): if isinstance(op, ClsTransform):
...@@ -96,13 +96,18 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0): ...@@ -96,13 +96,18 @@ def cls_compose(im, label=None, transforms=None, vdl_writer=None, step=0):
outputs = (im, label) outputs = (im, label)
if vdl_writer is not None: if vdl_writer is not None:
tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step) tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step)
vdl_writer.add_image(tag=tag, vdl_writer.add_image(tag=tag, img=im, step=0)
img=im,
step=0)
op_id += 1 op_id += 1
def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=None, step=0,
labels=[], catid2color=None): def det_compose(im,
im_info=None,
label_info=None,
transforms=None,
vdl_writer=None,
step=0,
labels=[],
catid2color=None):
def decode_image(im_file, im_info, label_info): def decode_image(im_file, im_info, label_info):
if im_info is None: if im_info is None:
im_info = dict() im_info = dict()
...@@ -148,9 +153,8 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N ...@@ -148,9 +153,8 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N
if len(outputs) == 3: if len(outputs) == 3:
label_info = outputs[2] label_info = outputs[2]
if vdl_writer is not None: if vdl_writer is not None:
vdl_writer.add_image(tag='0. OriginalImage/' + str(step), vdl_writer.add_image(
img=im, tag='0. OriginalImage/' + str(step), img=im, step=0)
step=0)
op_id = 1 op_id = 1
bboxes = label_info['gt_bbox'] bboxes = label_info['gt_bbox']
transforms = [None] + transforms transforms = [None] + transforms
...@@ -167,7 +171,8 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N ...@@ -167,7 +171,8 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N
im = outputs[0] im = outputs[0]
vdl_im = im vdl_im = im
if vdl_writer is not None: if vdl_writer is not None:
if isinstance(op, pdx.cv.transforms.det_transforms.ResizeByShort): if isinstance(op,
pdx.cv.transforms.det_transforms.ResizeByShort):
scale = outputs[1]['im_resize_info'][2] scale = outputs[1]['im_resize_info'][2]
bboxes = bboxes * scale bboxes = bboxes * scale
elif isinstance(op, pdx.cv.transforms.det_transforms.Resize): elif isinstance(op, pdx.cv.transforms.det_transforms.Resize):
...@@ -180,23 +185,25 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N ...@@ -180,23 +185,25 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N
else: else:
h_scale = float(target_size[0]) / h h_scale = float(target_size[0]) / h
w_scale = float(target_size[1]) / w w_scale = float(target_size[1]) / w
bboxes[:,0] = bboxes[:,0] * w_scale bboxes[:, 0] = bboxes[:, 0] * w_scale
bboxes[:,1] = bboxes[:,1] * h_scale bboxes[:, 1] = bboxes[:, 1] * h_scale
bboxes[:,2] = bboxes[:,2] * w_scale bboxes[:, 2] = bboxes[:, 2] * w_scale
bboxes[:,3] = bboxes[:,3] * h_scale bboxes[:, 3] = bboxes[:, 3] * h_scale
else: else:
bboxes = outputs[2]['gt_bbox'] bboxes = outputs[2]['gt_bbox']
if not isinstance(op, pdx.cv.transforms.det_transforms.RandomHorizontalFlip): if not isinstance(
op,
pdx.cv.transforms.det_transforms.RandomHorizontalFlip):
for i in range(bboxes.shape[0]): for i in range(bboxes.shape[0]):
bbox = bboxes[i] bbox = bboxes[i]
cname = labels[outputs[2]['gt_class'][i][0]-1] cname = labels[outputs[2]['gt_class'][i][0] - 1]
vdl_im = _draw_rectangle_and_cname(vdl_im, vdl_im = _draw_rectangle_and_cname(
vdl_im,
int(bbox[0]), int(bbox[0]),
int(bbox[1]), int(bbox[1]),
int(bbox[2]), int(bbox[2]),
int(bbox[3]), int(bbox[3]), cname,
cname, catid2color[outputs[2]['gt_class'][i][0] - 1])
catid2color[outputs[2]['gt_class'][i][0]-1])
if isinstance(op, pdx.cv.transforms.det_transforms.Normalize): if isinstance(op, pdx.cv.transforms.det_transforms.Normalize):
continue continue
else: else:
...@@ -210,19 +217,23 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N ...@@ -210,19 +217,23 @@ def det_compose(im, im_info=None, label_info=None, transforms=None, vdl_writer=N
tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step) tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step)
if op is None: if op is None:
tag = str(op_id) + '. OriginalImageWithGTBox/' + str(step) tag = str(op_id) + '. OriginalImageWithGTBox/' + str(step)
vdl_writer.add_image(tag=tag, vdl_writer.add_image(tag=tag, img=vdl_im, step=0)
img=vdl_im,
step=0)
op_id += 1 op_id += 1
def seg_compose(im, im_info=None, label=None, transforms=None, vdl_writer=None, step=0):
def seg_compose(im,
im_info=None,
label=None,
transforms=None,
vdl_writer=None,
step=0):
if im_info is None: if im_info is None:
im_info = list() im_info = list()
if isinstance(im, np.ndarray): if isinstance(im, np.ndarray):
if len(im.shape) != 3: if len(im.shape) != 3:
raise Exception( raise Exception(
"im should be 3-dimensions, but now is {}-dimensions". "im should be 3-dimensions, but now is {}-dimensions".format(
format(len(im.shape))) len(im.shape)))
else: else:
try: try:
im = cv2.imread(im).astype('float32') im = cv2.imread(im).astype('float32')
...@@ -233,9 +244,8 @@ def seg_compose(im, im_info=None, label=None, transforms=None, vdl_writer=None, ...@@ -233,9 +244,8 @@ def seg_compose(im, im_info=None, label=None, transforms=None, vdl_writer=None,
if not isinstance(label, np.ndarray): if not isinstance(label, np.ndarray):
label = np.asarray(Image.open(label)) label = np.asarray(Image.open(label))
if vdl_writer is not None: if vdl_writer is not None:
vdl_writer.add_image(tag='0. OriginalImage' + '/' + str(step), vdl_writer.add_image(
img=im, tag='0. OriginalImage' + '/' + str(step), img=im, step=0)
step=0)
op_id = 1 op_id = 1
for op in transforms: for op in transforms:
if isinstance(op, SegTransform): if isinstance(op, SegTransform):
...@@ -255,11 +265,10 @@ def seg_compose(im, im_info=None, label=None, transforms=None, vdl_writer=None, ...@@ -255,11 +265,10 @@ def seg_compose(im, im_info=None, label=None, transforms=None, vdl_writer=None,
outputs = (im, im_info) outputs = (im, im_info)
if vdl_writer is not None: if vdl_writer is not None:
tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step) tag = str(op_id) + '. ' + op.__class__.__name__ + '/' + str(step)
vdl_writer.add_image(tag=tag, vdl_writer.add_image(tag=tag, img=im, step=0)
img=im,
step=0)
op_id += 1 op_id += 1
def visualize(dataset, img_count=3, save_dir='vdl_output'): def visualize(dataset, img_count=3, save_dir='vdl_output'):
'''对数据预处理/增强中间结果进行可视化。 '''对数据预处理/增强中间结果进行可视化。
可使用VisualDL查看中间结果: 可使用VisualDL查看中间结果:
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
import os import os
def _find_classes(dir): def _find_classes(dir):
# Faster and available in Python 3.5 and above # Faster and available in Python 3.5 and above
classes = [d.name for d in os.scandir(dir) if d.is_dir()] classes = [d.name for d in os.scandir(dir) if d.is_dir()]
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -138,8 +138,10 @@ class ReaderConfig(object): ...@@ -138,8 +138,10 @@ class ReaderConfig(object):
... ...
""" """
def __init__(self, dataset_dir, is_test): def __init__(self, dataset_dir, is_test):
image_paths, labels, self.num_classes = self.get_dataset_info(dataset_dir, is_test) image_paths, labels, self.num_classes = self.get_dataset_info(
dataset_dir, is_test)
random_per = np.random.permutation(range(len(image_paths))) random_per = np.random.permutation(range(len(image_paths)))
self.image_paths = image_paths[random_per] self.image_paths = image_paths[random_per]
self.labels = labels[random_per] self.labels = labels[random_per]
...@@ -147,7 +149,8 @@ class ReaderConfig(object): ...@@ -147,7 +149,8 @@ class ReaderConfig(object):
def get_reader(self): def get_reader(self):
def reader(): def reader():
IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.tif', '.tiff', '.webp') IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm',
'.tif', '.tiff', '.webp')
target_size = 256 target_size = 256
crop_size = 224 crop_size = 224
...@@ -171,7 +174,8 @@ class ReaderConfig(object): ...@@ -171,7 +174,8 @@ class ReaderConfig(object):
return reader return reader
def get_dataset_info(self, dataset_dir, is_test=False): def get_dataset_info(self, dataset_dir, is_test=False):
IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.tif', '.tiff', '.webp') IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm',
'.tif', '.tiff', '.webp')
# read # read
if is_test: if is_test:
...@@ -199,7 +203,8 @@ class ReaderConfig(object): ...@@ -199,7 +203,8 @@ class ReaderConfig(object):
def create_reader(list_image_path, list_label=None, is_test=False): def create_reader(list_image_path, list_label=None, is_test=False):
def reader(): def reader():
IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm', '.tif', '.tiff', '.webp') IMG_EXTENSIONS = ('.jpg', '.jpeg', '.png', '.ppm', '.bmp', '.pgm',
'.tif', '.tiff', '.webp')
target_size = 256 target_size = 256
crop_size = 224 crop_size = 224
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -29,8 +29,9 @@ def log(level=2, message="", use_color=False): ...@@ -29,8 +29,9 @@ def log(level=2, message="", use_color=False):
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time_array) current_time = time.strftime("%Y-%m-%d %H:%M:%S", time_array)
if paddlex.log_level >= level: if paddlex.log_level >= level:
if use_color: if use_color:
print("\033[1;31;40m{} [{}]\t{}\033[0m".format(current_time, levels[ print("\033[1;31;40m{} [{}]\t{}\033[0m".format(
level], message).encode("utf-8").decode("latin1")) current_time, levels[level], message).encode("utf-8").decode(
"latin1"))
else: else:
print("{} [{}]\t{}".format(current_time, levels[level], message) print("{} [{}]\t{}".format(current_time, levels[level], message)
.encode("utf-8").decode("latin1")) .encode("utf-8").decode("latin1"))
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -531,8 +531,8 @@ def save_mask_inference_model(dirname, ...@@ -531,8 +531,8 @@ def save_mask_inference_model(dirname,
if isinstance(target_vars, Variable): if isinstance(target_vars, Variable):
target_vars = [target_vars] target_vars = [target_vars]
elif export_for_deployment: elif export_for_deployment:
if not (bool(target_vars) if not (bool(target_vars) and
and all(isinstance(var, Variable) for var in target_vars)): all(isinstance(var, Variable) for var in target_vars)):
raise ValueError("'target_vars' should be a list of Variable.") raise ValueError("'target_vars' should be a list of Variable.")
main_program = _get_valid_program(main_program) main_program = _get_valid_program(main_program)
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -50,6 +50,7 @@ def get_environ_info(): ...@@ -50,6 +50,7 @@ def get_environ_info():
info['num'] = fluid.core.get_cuda_device_count() info['num'] = fluid.core.get_cuda_device_count()
return info return info
def path_normalization(path): def path_normalization(path):
win_sep = "\\" win_sep = "\\"
other_sep = "/" other_sep = "/"
...@@ -59,6 +60,7 @@ def path_normalization(path): ...@@ -59,6 +60,7 @@ def path_normalization(path):
path = other_sep.join(path.split(win_sep)) path = other_sep.join(path.split(win_sep))
return path return path
def parse_param_file(param_file, return_shape=True): def parse_param_file(param_file, return_shape=True):
from paddle.fluid.proto.framework_pb2 import VarType from paddle.fluid.proto.framework_pb2 import VarType
f = open(param_file, 'rb') f = open(param_file, 'rb')
......
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
...@@ -29,13 +29,11 @@ def train(model_dir=None, sensitivities_file=None, eval_metric_loss=0.05): ...@@ -29,13 +29,11 @@ def train(model_dir=None, sensitivities_file=None, eval_metric_loss=0.05):
# 定义训练和验证时的transforms # 定义训练和验证时的transforms
train_transforms = transforms.Compose([ train_transforms = transforms.Compose([
transforms.RandomCrop(crop_size=224), transforms.RandomCrop(crop_size=224),
transforms.RandomHorizontalFlip(), transforms.RandomHorizontalFlip(), transforms.Normalize()
transforms.Normalize()
]) ])
eval_transforms = transforms.Compose([ eval_transforms = transforms.Compose([
transforms.ResizeByShort(short_size=256), transforms.ResizeByShort(short_size=256),
transforms.CenterCrop(crop_size=224), transforms.CenterCrop(crop_size=224), transforms.Normalize()
transforms.Normalize()
]) ])
# 定义训练和验证所用的数据集 # 定义训练和验证所用的数据集
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
...@@ -28,17 +28,14 @@ def train(model_dir, sensitivities_file, eval_metric_loss): ...@@ -28,17 +28,14 @@ def train(model_dir, sensitivities_file, eval_metric_loss):
# 定义训练和验证时的transforms # 定义训练和验证时的transforms
train_transforms = transforms.Compose([ train_transforms = transforms.Compose([
transforms.MixupImage(mixup_epoch=250), transforms.MixupImage(mixup_epoch=250), transforms.RandomDistort(),
transforms.RandomDistort(), transforms.RandomExpand(), transforms.RandomCrop(), transforms.Resize(
transforms.RandomExpand(), target_size=608, interp='RANDOM'),
transforms.RandomCrop(), transforms.RandomHorizontalFlip(), transforms.Normalize()
transforms.Resize(target_size=608, interp='RANDOM'),
transforms.RandomHorizontalFlip(),
transforms.Normalize()
]) ])
eval_transforms = transforms.Compose([ eval_transforms = transforms.Compose([
transforms.Resize(target_size=608, interp='CUBIC'), transforms.Resize(
transforms.Normalize() target_size=608, interp='CUBIC'), transforms.Normalize()
]) ])
# 定义训练和验证所用的数据集 # 定义训练和验证所用的数据集
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. #copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); #Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. #you may not use this file except in compliance with the License.
...@@ -28,15 +28,12 @@ def train(model_dir, sensitivities_file, eval_metric_loss): ...@@ -28,15 +28,12 @@ def train(model_dir, sensitivities_file, eval_metric_loss):
# 定义训练和验证时的transforms # 定义训练和验证时的transforms
train_transforms = transforms.Compose([ train_transforms = transforms.Compose([
transforms.RandomHorizontalFlip(), transforms.RandomHorizontalFlip(), transforms.ResizeRangeScaling(),
transforms.ResizeRangeScaling(), transforms.RandomPaddingCrop(crop_size=512), transforms.Normalize()
transforms.RandomPaddingCrop(crop_size=512),
transforms.Normalize()
]) ])
eval_transforms = transforms.Compose([ eval_transforms = transforms.Compose([
transforms.ResizeByLong(long_size=512), transforms.ResizeByLong(long_size=512),
transforms.Padding(target_size=512), transforms.Padding(target_size=512), transforms.Normalize()
transforms.Normalize()
]) ])
# 定义训练和验证所用的数据集 # 定义训练和验证所用的数据集
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册