From 1475bb0538dd821b01d980670aca50273f72b92e Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Thu, 6 Feb 2020 19:35:24 +0800 Subject: [PATCH] exit 1 when travis check failed (#214) * exit1 in travis failed --- .travis.yml | 1 + .travis/requirements.txt | 3 + .travis/unittest.sh | 9 +- inference/tools/detection_result_pb2.py | 28 +- inference/tools/vis.py | 8 +- ppdet/core/config/schema.py | 5 + ppdet/data/tools/x2coco.py | 8 +- ppdet/modeling/backbones/cb_resnet.py | 91 +- ppdet/modeling/backbones/hrfpn.py | 82 +- ppdet/modeling/backbones/hrnet.py | 338 +++++--- ppdet/modeling/backbones/res2net.py | 148 ++-- ppdet/modeling/losses/iou_loss.py | 43 +- ppdet/modeling/losses/yolo_loss.py | 4 +- ppdet/modeling/roi_heads/cascade_head.py | 32 +- ppdet/utils/oid_eval.py | 1009 +++++++++++----------- slim/sensitive/sensitive.py | 46 +- 16 files changed, 982 insertions(+), 873 deletions(-) create mode 100644 .travis/requirements.txt diff --git a/.travis.yml b/.travis.yml index dece82da0..c47b1ef89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ script: - .travis/precommit.sh || exit_code=$(( exit_code | $? )) - docker run -i --rm -v "$PWD:/py_unittest" paddlepaddle/paddle:latest /bin/bash -c 'cd /py_unittest; sh .travis/unittest.sh' || exit_code=$(( exit_code | $? )) + - if [ $exit_code -eq 0 ]; then true; else exit 1; fi; notifications: email: diff --git a/.travis/requirements.txt b/.travis/requirements.txt new file mode 100644 index 000000000..c04a1d495 --- /dev/null +++ b/.travis/requirements.txt @@ -0,0 +1,3 @@ +# add python requirements for unittests here, note install Cython +# and pycocotools directly is not supported in travis ci. +tqdm diff --git a/.travis/unittest.sh b/.travis/unittest.sh index c4d1b79cc..58fee7fe8 100755 --- a/.travis/unittest.sh +++ b/.travis/unittest.sh @@ -3,6 +3,8 @@ abort(){ echo "Run unittest failed" 1>&2 echo "Please check your code" 1>&2 + echo " 1. you can run unit tests by 'bash .travis/unittest.sh' locally" 1>&2 + echo " 2. you can add python requirements in .travis/requirements.txt if you use new requirements in unit tests" 1>&2 exit 1 } @@ -18,10 +20,11 @@ unittest(){ trap 'abort' 0 set -e -# install python dependencies -if [ -f "requirements.txt" ]; then - pip install -r requirements.txt +# install travis python dependencies +if [ -f ".travis/requirements.txt" ]; then + pip install -r .travis/requirements.txt fi + export PYTHONPATH=`pwd`:$PYTHONPATH unittest . diff --git a/inference/tools/detection_result_pb2.py b/inference/tools/detection_result_pb2.py index 153a41df4..bb7acae60 100644 --- a/inference/tools/detection_result_pb2.py +++ b/inference/tools/detection_result_pb2.py @@ -134,8 +134,7 @@ _DETECTIONBOX = _descriptor.Descriptor( extension_ranges=[], oneofs=[], serialized_start=43, - serialized_end=175, -) + serialized_end=175) _DETECTIONRESULT = _descriptor.Descriptor( name='DetectionResult', @@ -186,8 +185,7 @@ _DETECTIONRESULT = _descriptor.Descriptor( extension_ranges=[], oneofs=[], serialized_start=177, - serialized_end=267, -) + serialized_end=267) _DETECTIONRESULT.fields_by_name['detection_boxes'].message_type = _DETECTIONBOX DESCRIPTOR.message_types_by_name['DetectionBox'] = _DETECTIONBOX @@ -195,20 +193,22 @@ DESCRIPTOR.message_types_by_name['DetectionResult'] = _DETECTIONRESULT DetectionBox = _reflection.GeneratedProtocolMessageType( 'DetectionBox', - (_message.Message,), - dict(DESCRIPTOR=_DETECTIONBOX, - __module__='detection_result_pb2' - # @@protoc_insertion_point(class_scope:PaddleSolution.DetectionBox) - )) + (_message.Message, ), + dict( + DESCRIPTOR=_DETECTIONBOX, + __module__='detection_result_pb2' + # @@protoc_insertion_point(class_scope:PaddleSolution.DetectionBox) + )) _sym_db.RegisterMessage(DetectionBox) DetectionResult = _reflection.GeneratedProtocolMessageType( 'DetectionResult', - (_message.Message,), - dict(DESCRIPTOR=_DETECTIONRESULT, - __module__='detection_result_pb2' - # @@protoc_insertion_point(class_scope:PaddleSolution.DetectionResult) - )) + (_message.Message, ), + dict( + DESCRIPTOR=_DETECTIONRESULT, + __module__='detection_result_pb2' + # @@protoc_insertion_point(class_scope:PaddleSolution.DetectionResult) + )) _sym_db.RegisterMessage(DetectionResult) # @@protoc_insertion_point(module_scope) diff --git a/inference/tools/vis.py b/inference/tools/vis.py index f27ae1f83..d0f9fc841 100644 --- a/inference/tools/vis.py +++ b/inference/tools/vis.py @@ -85,8 +85,8 @@ if __name__ == "__main__": for box in detection_result.detection_boxes: if box.score >= Flags.threshold: box_class = getattr(box, 'class') - text_class_score_str = "%s %.2f" % (class2LabelMap.get( - str(box_class)), box.score) + text_class_score_str = "%s %.2f" % ( + class2LabelMap.get(str(box_class)), box.score) text_point = (int(box.left_top_x), int(box.left_top_y)) ptLeftTop = (int(box.left_top_x), int(box.left_top_y)) @@ -106,8 +106,8 @@ if __name__ == "__main__": text_box_left_top = (text_point[0], text_point[1] - text_size[0][1]) - text_box_right_bottom = (text_point[0] + - text_size[0][0], text_point[1]) + text_box_right_bottom = ( + text_point[0] + text_size[0][0], text_point[1]) cv2.rectangle(img, text_box_left_top, text_box_right_bottom, color, -1, 8) diff --git a/ppdet/core/config/schema.py b/ppdet/core/config/schema.py index 6b55cd50f..0d2b0dabf 100644 --- a/ppdet/core/config/schema.py +++ b/ppdet/core/config/schema.py @@ -23,14 +23,19 @@ import re try: from docstring_parser import parse as doc_parse except Exception: + def doc_parse(*args): pass + + try: from typeguard import check_type except Exception: + def check_type(*args): pass + __all__ = ['SchemaValue', 'SchemaDict', 'SharedConfig', 'extract_schema'] diff --git a/ppdet/data/tools/x2coco.py b/ppdet/data/tools/x2coco.py index dec0e2359..53faa3f5c 100644 --- a/ppdet/data/tools/x2coco.py +++ b/ppdet/data/tools/x2coco.py @@ -25,11 +25,11 @@ import shutil import numpy as np import PIL.ImageDraw - label_to_num = {} categories_list = [] labels_list = [] + class MyEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, np.integer): @@ -287,16 +287,14 @@ def main(): indent=4, cls=MyEncoder) if args.val_proportion != 0: - val_data_coco = deal_json(args.dataset_type, - args.output_dir + '/val', + val_data_coco = deal_json(args.dataset_type, args.output_dir + '/val', args.json_input_dir) val_json_path = osp.join(args.output_dir + '/annotations', 'instance_val.json') json.dump( val_data_coco, open(val_json_path, 'w'), indent=4, cls=MyEncoder) if args.test_proportion != 0: - test_data_coco = deal_json(args.dataset_type, - args.output_dir + '/test', + test_data_coco = deal_json(args.dataset_type, args.output_dir + '/test', args.json_input_dir) test_json_path = osp.join(args.output_dir + '/annotations', 'instance_test.json') diff --git a/ppdet/modeling/backbones/cb_resnet.py b/ppdet/modeling/backbones/cb_resnet.py index 47b7ead78..dc1ca209a 100644 --- a/ppdet/modeling/backbones/cb_resnet.py +++ b/ppdet/modeling/backbones/cb_resnet.py @@ -64,8 +64,8 @@ class CBResNet(object): variant='b', feature_maps=[2, 3, 4, 5], dcn_v2_stages=[], - nonlocal_stages = [], - repeat_num = 2): + nonlocal_stages=[], + repeat_num=2): super(CBResNet, self).__init__() if isinstance(feature_maps, Integral): @@ -102,19 +102,26 @@ class CBResNet(object): self.nonlocal_stages = nonlocal_stages self.nonlocal_mod_cfg = { - 50 : 2, - 101 : 5, - 152 : 8, - 200 : 12, + 50: 2, + 101: 5, + 152: 8, + 200: 12, } self.stage_filters = [64, 128, 256, 512] self._c1_out_chan_num = 64 self.na = NameAdapter(self) - def _conv_offset(self, input, filter_size, stride, padding, act=None, name=None): + def _conv_offset(self, + input, + filter_size, + stride, + padding, + act=None, + name=None): out_channel = filter_size * filter_size * 3 - out = fluid.layers.conv2d(input, + out = fluid.layers.conv2d( + input, num_filters=out_channel, filter_size=filter_size, stride=stride, @@ -145,7 +152,8 @@ class CBResNet(object): padding=(filter_size - 1) // 2, groups=groups, act=None, - param_attr=ParamAttr(name=name + "_weights_"+str(self.curr_level)), + param_attr=ParamAttr( + name=name + "_weights_" + str(self.curr_level)), bias_attr=False) else: offset_mask = self._conv_offset( @@ -155,8 +163,8 @@ class CBResNet(object): padding=(filter_size - 1) // 2, act=None, name=name + "_conv_offset_" + str(self.curr_level)) - offset_channel = filter_size ** 2 * 2 - mask_channel = filter_size ** 2 + offset_channel = filter_size**2 * 2 + mask_channel = filter_size**2 offset, mask = fluid.layers.split( input=offset_mask, num_or_sections=[offset_channel, mask_channel], @@ -173,7 +181,8 @@ class CBResNet(object): groups=groups, deformable_groups=1, im2col_step=1, - param_attr=ParamAttr(name=name + "_weights_"+str(self.curr_level)), + param_attr=ParamAttr( + name=name + "_weights_" + str(self.curr_level)), bias_attr=False) bn_name = self.na.fix_conv_norm_name(name) @@ -181,11 +190,11 @@ class CBResNet(object): norm_lr = 0. if self.freeze_norm else 1. norm_decay = self.norm_decay pattr = ParamAttr( - name=bn_name + '_scale_'+str(self.curr_level), + name=bn_name + '_scale_' + str(self.curr_level), learning_rate=norm_lr, regularizer=L2Decay(norm_decay)) battr = ParamAttr( - name=bn_name + '_offset_'+str(self.curr_level), + name=bn_name + '_offset_' + str(self.curr_level), learning_rate=norm_lr, regularizer=L2Decay(norm_decay)) @@ -194,11 +203,12 @@ class CBResNet(object): out = fluid.layers.batch_norm( input=conv, act=act, - name=bn_name + '.output.1_'+str(self.curr_level), + name=bn_name + '.output.1_' + str(self.curr_level), param_attr=pattr, bias_attr=battr, - moving_mean_name=bn_name + '_mean_'+str(self.curr_level), - moving_variance_name=bn_name + '_variance_'+str(self.curr_level), + moving_mean_name=bn_name + '_mean_' + str(self.curr_level), + moving_variance_name=bn_name + '_variance_' + + str(self.curr_level), use_global_stats=global_stats) scale = fluid.framework._get_var(pattr.name) bias = fluid.framework._get_var(battr.name) @@ -262,7 +272,7 @@ class CBResNet(object): act=act, groups=g, name=_name, - dcn=(i==1 and dcn)) + dcn=(i == 1 and dcn)) short = self._shortcut( input, num_filters * expand, @@ -273,8 +283,7 @@ class CBResNet(object): if callable(getattr(self, '_squeeze_excitation', None)): residual = self._squeeze_excitation( input=residual, num_channels=num_filters, name='fc' + name) - return fluid.layers.elementwise_add( - x=short, y=residual, act='relu') + return fluid.layers.elementwise_add(x=short, y=residual, act='relu') def basicblock(self, input, num_filters, stride, is_first, name, dcn=False): assert dcn is False, "Not implemented yet." @@ -313,10 +322,10 @@ class CBResNet(object): is_first = False if stage_num != 2 else True dcn = True if stage_num in self.dcn_v2_stages else False - nonlocal_mod = 1000 if stage_num in self.nonlocal_stages: - nonlocal_mod = self.nonlocal_mod_cfg[self.depth] if stage_num==4 else 2 + nonlocal_mod = self.nonlocal_mod_cfg[ + self.depth] if stage_num == 4 else 2 # Make the layer name and parameter name consistent # with ImageNet pre-trained model @@ -335,11 +344,12 @@ class CBResNet(object): # add non local model dim_in = conv.shape[1] - nonlocal_name = "nonlocal_conv{}_lvl{}".format( stage_num, self.curr_level ) + nonlocal_name = "nonlocal_conv{}_lvl{}".format(stage_num, + self.curr_level) if i % nonlocal_mod == nonlocal_mod - 1: - conv = add_space_nonlocal( - conv, dim_in, dim_in, - nonlocal_name + '_{}'.format(i), int(dim_in / 2) ) + conv = add_space_nonlocal(conv, dim_in, dim_in, + nonlocal_name + '_{}'.format(i), + int(dim_in / 2)) return conv @@ -349,9 +359,9 @@ class CBResNet(object): conv1_name = self.na.fix_c1_stage_name() if self.variant in ['c', 'd']: - conv1_1_name= "conv1_1" - conv1_2_name= "conv1_2" - conv1_3_name= "conv1_3" + conv1_1_name = "conv1_1" + conv1_2_name = "conv1_2" + conv1_3_name = "conv1_3" conv_def = [ [out_chan // 2, 3, 2, conv1_1_name], [out_chan // 2, 3, 1, conv1_2_name], @@ -377,14 +387,15 @@ class CBResNet(object): pool_type='max') return output - def connect( self, left, right, name ): + def connect(self, left, right, name): ch_right = right.shape[1] - conv = self._conv_norm( left, - num_filters=ch_right, - filter_size=1, - stride=1, - act="relu", - name=name+"_connect") + conv = self._conv_norm( + left, + num_filters=ch_right, + filter_size=1, + stride=1, + act="relu", + name=name + "_connect") shape = fluid.layers.shape(right) shape_hw = fluid.layers.slice(shape, axes=[0], starts=[2], ends=[4]) out_shape_ = shape_hw @@ -414,11 +425,11 @@ class CBResNet(object): for num in range(1, self.repeat_num): self.curr_level = num res = self.c1_stage(input) - for i in range( len(res_endpoints) ): - res = self.connect( res_endpoints[i], res, "test_c"+str(i+1) ) - res = self.layer_warp(res, i+2) + for i in range(len(res_endpoints)): + res = self.connect(res_endpoints[i], res, "test_c" + str(i + 1)) + res = self.layer_warp(res, i + 2) res_endpoints[i] = res - if self.freeze_at >= i+2: + if self.freeze_at >= i + 2: res.stop_gradient = True return OrderedDict([('res{}_sum'.format(self.feature_maps[idx]), feat) diff --git a/ppdet/modeling/backbones/hrfpn.py b/ppdet/modeling/backbones/hrfpn.py index 1f1d65433..37377f121 100644 --- a/ppdet/modeling/backbones/hrfpn.py +++ b/ppdet/modeling/backbones/hrfpn.py @@ -40,35 +40,36 @@ class HRFPN(object): spatial_scale (list): feature map scaling factor """ - def __init__(self, - num_chan=256, - pooling_type="avg", - share_conv=False, - spatial_scale=[1./64, 1./32, 1./16, 1./8, 1./4], - ): + def __init__( + self, + num_chan=256, + pooling_type="avg", + share_conv=False, + spatial_scale=[1. / 64, 1. / 32, 1. / 16, 1. / 8, 1. / 4], ): self.num_chan = num_chan self.pooling_type = pooling_type self.share_conv = share_conv self.spatial_scale = spatial_scale return - + def get_output(self, body_dict): num_out = len(self.spatial_scale) body_name_list = list(body_dict.keys()) - + num_backbone_stages = len(body_name_list) - + outs = [] outs.append(body_dict[body_name_list[0]]) - + # resize for i in range(1, len(body_dict)): - resized = self.resize_input_tensor(body_dict[body_name_list[i]], outs[0], 2**i) - outs.append( resized ) - + resized = self.resize_input_tensor(body_dict[body_name_list[i]], + outs[0], 2**i) + outs.append(resized) + # concat - out = fluid.layers.concat( outs, axis=1 ) - + out = fluid.layers.concat(outs, axis=1) + # reduction out = fluid.layers.conv2d( input=out, @@ -78,34 +79,40 @@ class HRFPN(object): padding=0, param_attr=ParamAttr(name='hrfpn_reduction_weights'), bias_attr=False) - + # conv outs = [out] for i in range(1, num_out): - outs.append(self.pooling(out, size=2**i, stride=2**i, pooling_type=self.pooling_type)) + outs.append( + self.pooling( + out, size=2**i, stride=2**i, + pooling_type=self.pooling_type)) outputs = [] - + for i in range(num_out): - conv_name = "shared_fpn_conv" if self.share_conv else "shared_fpn_conv_"+str(i) + conv_name = "shared_fpn_conv" if self.share_conv else "shared_fpn_conv_" + str( + i) conv = fluid.layers.conv2d( - input=outs[i], - num_filters=self.num_chan, - filter_size=3, - stride=1, - padding=1, - param_attr=ParamAttr(name=conv_name+"_weights"), - bias_attr=False) - outputs.append( conv ) - - for idx in range(0, num_out-len(body_name_list)): - body_name_list.append("fpn_res5_sum_subsampled_{}x".format( 2**(idx+1) )) - + input=outs[i], + num_filters=self.num_chan, + filter_size=3, + stride=1, + padding=1, + param_attr=ParamAttr(name=conv_name + "_weights"), + bias_attr=False) + outputs.append(conv) + + for idx in range(0, num_out - len(body_name_list)): + body_name_list.append("fpn_res5_sum_subsampled_{}x".format(2**(idx + + 1))) + outputs = outputs[::-1] body_name_list = body_name_list[::-1] - - res_dict = OrderedDict([(body_name_list[k], outputs[k]) for k in range(len(body_name_list))]) + + res_dict = OrderedDict([(body_name_list[k], outputs[k]) + for k in range(len(body_name_list))]) return res_dict, self.spatial_scale - + def resize_input_tensor(self, body_input, ref_output, scale): shape = fluid.layers.shape(ref_output) shape_hw = fluid.layers.slice(shape, axes=[0], starts=[2], ends=[4]) @@ -115,12 +122,11 @@ class HRFPN(object): body_output = fluid.layers.resize_bilinear( body_input, scale=scale, actual_shape=out_shape) return body_output - + def pooling(self, input, size, stride, pooling_type): - pool = fluid.layers.pool2d(input=input, + pool = fluid.layers.pool2d( + input=input, pool_size=size, pool_stride=stride, pool_type=pooling_type) return pool - - \ No newline at end of file diff --git a/ppdet/modeling/backbones/hrnet.py b/ppdet/modeling/backbones/hrnet.py index 323e1dcc2..2849d942a 100644 --- a/ppdet/modeling/backbones/hrnet.py +++ b/ppdet/modeling/backbones/hrnet.py @@ -64,7 +64,7 @@ class HRNet(object): assert 0 <= freeze_at <= 4, "freeze_at should be 0, 1, 2, 3 or 4" assert len(feature_maps) > 0, "need one or more feature maps" assert norm_type in ['bn', 'sync_bn'] - + self.width = width self.has_se = has_se self.channels = { @@ -76,7 +76,7 @@ class HRNet(object): 48: [[48, 96], [48, 96, 192], [48, 96, 192, 384]], 60: [[60, 120], [60, 120, 240], [60, 120, 240, 480]], 64: [[64, 128], [64, 128, 256], [64, 128, 256, 512]], - } + } self.freeze_at = freeze_at self.norm_type = norm_type @@ -86,24 +86,26 @@ class HRNet(object): self.feature_maps = feature_maps self.end_points = [] return - + def net(self, input, class_dim=1000): width = self.width - channels_2, channels_3, channels_4 = self.channels[width] + channels_2, channels_3, channels_4 = self.channels[width] num_modules_2, num_modules_3, num_modules_4 = 1, 4, 3 - - x = self.conv_bn_layer(input=input, - filter_size=3, - num_filters=64, - stride=2, - if_act=True, - name='layer1_1') - x = self.conv_bn_layer(input=x, - filter_size=3, - num_filters=64, - stride=2, - if_act=True, - name='layer1_2') + + x = self.conv_bn_layer( + input=input, + filter_size=3, + num_filters=64, + stride=2, + if_act=True, + name='layer1_1') + x = self.conv_bn_layer( + input=x, + filter_size=3, + num_filters=64, + stride=2, + if_act=True, + name='layer1_2') la1 = self.layer1(x, name='layer2') tr1 = self.transition_layer([la1], [256], channels_2, name='tr1') @@ -112,19 +114,20 @@ class HRNet(object): st3 = self.stage(tr2, num_modules_3, channels_3, name='st3') tr3 = self.transition_layer(st3, channels_3, channels_4, name='tr3') st4 = self.stage(tr3, num_modules_4, channels_4, name='st4') - + self.end_points = st4 return st4[-1] - + def layer1(self, input, name=None): conv = input for i in range(4): - conv = self.bottleneck_block(conv, - num_filters=64, - downsample=True if i == 0 else False, - name=name+'_'+str(i+1)) + conv = self.bottleneck_block( + conv, + num_filters=64, + downsample=True if i == 0 else False, + name=name + '_' + str(i + 1)) return conv - + def transition_layer(self, x, in_channels, out_channels, name=None): num_in = len(in_channels) num_out = len(out_channels) @@ -132,19 +135,21 @@ class HRNet(object): for i in range(num_out): if i < num_in: if in_channels[i] != out_channels[i]: - residual = self.conv_bn_layer(x[i], - filter_size=3, - num_filters=out_channels[i], - name=name+'_layer_'+str(i+1)) + residual = self.conv_bn_layer( + x[i], + filter_size=3, + num_filters=out_channels[i], + name=name + '_layer_' + str(i + 1)) out.append(residual) else: out.append(x[i]) else: - residual = self.conv_bn_layer(x[-1], - filter_size=3, - num_filters=out_channels[i], - stride=2, - name=name+'_layer_'+str(i+1)) + residual = self.conv_bn_layer( + x[-1], + filter_size=3, + num_filters=out_channels[i], + stride=2, + name=name + '_layer_' + str(i + 1)) out.append(residual) return out @@ -153,9 +158,11 @@ class HRNet(object): for i in range(len(channels)): residual = x[i] for j in range(block_num): - residual = self.basic_block(residual, - channels[i], - name=name+'_branch_layer_'+str(i+1)+'_'+str(j+1)) + residual = self.basic_block( + residual, + channels[i], + name=name + '_branch_layer_' + str(i + 1) + '_' + + str(j + 1)) out.append(residual) return out @@ -165,167 +172,215 @@ class HRNet(object): residual = x[i] for j in range(len(channels)): if j > i: - y = self.conv_bn_layer(x[j], - filter_size=1, - num_filters=channels[i], - if_act=False, - name=name+'_layer_'+str(i+1)+'_'+str(j+1)) - y = fluid.layers.resize_nearest(input=y, scale=2 ** (j - i)) + y = self.conv_bn_layer( + x[j], + filter_size=1, + num_filters=channels[i], + if_act=False, + name=name + '_layer_' + str(i + 1) + '_' + str(j + 1)) + y = fluid.layers.resize_nearest(input=y, scale=2**(j - i)) residual = fluid.layers.elementwise_add( x=residual, y=y, act=None) elif j < i: y = x[j] for k in range(i - j): if k == i - j - 1: - y = self.conv_bn_layer(y, - filter_size=3, - num_filters=channels[i], - stride=2,if_act=False, - name=name+'_layer_'+str(i+1)+'_'+str(j+1)+'_'+str(k+1)) + y = self.conv_bn_layer( + y, + filter_size=3, + num_filters=channels[i], + stride=2, + if_act=False, + name=name + '_layer_' + str(i + 1) + '_' + + str(j + 1) + '_' + str(k + 1)) else: - y = self.conv_bn_layer(y, - filter_size=3, - num_filters=channels[j], - stride=2, - name=name+'_layer_'+str(i+1)+'_'+str(j+1)+'_'+str(k+1)) + y = self.conv_bn_layer( + y, + filter_size=3, + num_filters=channels[j], + stride=2, + name=name + '_layer_' + str(i + 1) + '_' + + str(j + 1) + '_' + str(k + 1)) residual = fluid.layers.elementwise_add( - x=residual, y=y, act=None) + x=residual, y=y, act=None) residual = fluid.layers.relu(residual) out.append(residual) return out - - def high_resolution_module(self, x, channels, multi_scale_output=True, name=None): + + def high_resolution_module(self, + x, + channels, + multi_scale_output=True, + name=None): residual = self.branches(x, 4, channels, name=name) - out = self.fuse_layers(residual, channels, multi_scale_output=multi_scale_output, name=name) + out = self.fuse_layers( + residual, + channels, + multi_scale_output=multi_scale_output, + name=name) return out - - def stage(self, x, num_modules, channels, multi_scale_output=True, name=None): + + def stage(self, + x, + num_modules, + channels, + multi_scale_output=True, + name=None): out = x for i in range(num_modules): if i == num_modules - 1 and multi_scale_output == False: - out = self.high_resolution_module(out, - channels, - multi_scale_output=False, - name=name+'_'+str(i+1)) + out = self.high_resolution_module( + out, + channels, + multi_scale_output=False, + name=name + '_' + str(i + 1)) else: - out = self.high_resolution_module(out, - channels, - name=name+'_'+str(i+1)) + out = self.high_resolution_module( + out, channels, name=name + '_' + str(i + 1)) return out - + def last_cls_out(self, x, name=None): out = [] num_filters_list = [128, 256, 512, 1024] for i in range(len(x)): - out.append(self.conv_bn_layer(input=x[i], - filter_size=1, - num_filters=num_filters_list[i], - name=name+'conv_'+str(i+1))) + out.append( + self.conv_bn_layer( + input=x[i], + filter_size=1, + num_filters=num_filters_list[i], + name=name + 'conv_' + str(i + 1))) return out - - def basic_block(self, input, num_filters, stride=1, downsample=False, name=None): + def basic_block(self, + input, + num_filters, + stride=1, + downsample=False, + name=None): residual = input - conv = self.conv_bn_layer(input=input, - filter_size=3, - num_filters=num_filters, - stride=stride, - name=name+'_conv1') - conv = self.conv_bn_layer(input=conv, - filter_size=3, - num_filters=num_filters, - if_act=False, - name=name+'_conv2') + conv = self.conv_bn_layer( + input=input, + filter_size=3, + num_filters=num_filters, + stride=stride, + name=name + '_conv1') + conv = self.conv_bn_layer( + input=conv, + filter_size=3, + num_filters=num_filters, + if_act=False, + name=name + '_conv2') if downsample: - residual = self.conv_bn_layer(input=input, - filter_size=1, - num_filters=num_filters, - if_act=False, - name=name+'_downsample') + residual = self.conv_bn_layer( + input=input, + filter_size=1, + num_filters=num_filters, + if_act=False, + name=name + '_downsample') if self.has_se: conv = self.squeeze_excitation( input=conv, num_channels=num_filters, reduction_ratio=16, - name='fc'+name) + name='fc' + name) return fluid.layers.elementwise_add(x=residual, y=conv, act='relu') - - def bottleneck_block(self, input, num_filters, stride=1, downsample=False, name=None): + def bottleneck_block(self, + input, + num_filters, + stride=1, + downsample=False, + name=None): residual = input - conv = self.conv_bn_layer(input=input, - filter_size=1, - num_filters=num_filters, - name=name+'_conv1') - conv = self.conv_bn_layer(input=conv, - filter_size=3, - num_filters=num_filters, - stride=stride, - name=name+'_conv2') - conv = self.conv_bn_layer(input=conv, - filter_size=1, - num_filters=num_filters*4, - if_act=False, - name=name+'_conv3') + conv = self.conv_bn_layer( + input=input, + filter_size=1, + num_filters=num_filters, + name=name + '_conv1') + conv = self.conv_bn_layer( + input=conv, + filter_size=3, + num_filters=num_filters, + stride=stride, + name=name + '_conv2') + conv = self.conv_bn_layer( + input=conv, + filter_size=1, + num_filters=num_filters * 4, + if_act=False, + name=name + '_conv3') if downsample: - residual = self.conv_bn_layer(input=input, - filter_size=1, - num_filters=num_filters*4, - if_act=False, - name=name+'_downsample') + residual = self.conv_bn_layer( + input=input, + filter_size=1, + num_filters=num_filters * 4, + if_act=False, + name=name + '_downsample') if self.has_se: conv = self.squeeze_excitation( input=conv, num_channels=num_filters * 4, reduction_ratio=16, - name='fc'+name) + name='fc' + name) return fluid.layers.elementwise_add(x=residual, y=conv, act='relu') - - def squeeze_excitation(self, input, num_channels, reduction_ratio, name=None): + + def squeeze_excitation(self, + input, + num_channels, + reduction_ratio, + name=None): pool = fluid.layers.pool2d( input=input, pool_size=0, pool_type='avg', global_pooling=True) stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0) - squeeze = fluid.layers.fc(input=pool, - size=num_channels / reduction_ratio, - act='relu', - param_attr=fluid.param_attr.ParamAttr( - initializer=fluid.initializer.Uniform( - -stdv, stdv),name=name+'_sqz_weights'), - bias_attr=ParamAttr(name=name+'_sqz_offset')) + squeeze = fluid.layers.fc( + input=pool, + size=num_channels / reduction_ratio, + act='relu', + param_attr=fluid.param_attr.ParamAttr( + initializer=fluid.initializer.Uniform(-stdv, stdv), + name=name + '_sqz_weights'), + bias_attr=ParamAttr(name=name + '_sqz_offset')) stdv = 1.0 / math.sqrt(squeeze.shape[1] * 1.0) - excitation = fluid.layers.fc(input=squeeze, - size=num_channels, - act='sigmoid', - param_attr=fluid.param_attr.ParamAttr( - initializer=fluid.initializer.Uniform( - -stdv, stdv),name=name+'_exc_weights'), - bias_attr=ParamAttr(name=name+'_exc_offset')) + excitation = fluid.layers.fc( + input=squeeze, + size=num_channels, + act='sigmoid', + param_attr=fluid.param_attr.ParamAttr( + initializer=fluid.initializer.Uniform(-stdv, stdv), + name=name + '_exc_weights'), + bias_attr=ParamAttr(name=name + '_exc_offset')) scale = fluid.layers.elementwise_mul(x=input, y=excitation, axis=0) return scale - - def conv_bn_layer(self,input, filter_size, num_filters, stride=1, padding=1, num_groups=1, if_act=True, name=None): + + def conv_bn_layer(self, + input, + filter_size, + num_filters, + stride=1, + padding=1, + num_groups=1, + if_act=True, + name=None): conv = fluid.layers.conv2d( input=input, num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size-1)//2, + padding=(filter_size - 1) // 2, groups=num_groups, act=None, - param_attr=ParamAttr(initializer=MSRA(), name=name+'_weights'), + param_attr=ParamAttr( + initializer=MSRA(), name=name + '_weights'), bias_attr=False) bn_name = name + '_bn' - bn = self._bn( input=conv, bn_name=bn_name ) + bn = self._bn(input=conv, bn_name=bn_name) if if_act: bn = fluid.layers.relu(bn) return bn - - def _bn(self, - input, - act=None, - bn_name=None): + + def _bn(self, input, act=None, bn_name=None): norm_lr = 0. if self.freeze_norm else 1. norm_decay = self.norm_decay pattr = ParamAttr( @@ -336,7 +391,7 @@ class HRNet(object): name=bn_name + '_offset', learning_rate=norm_lr, regularizer=L2Decay(norm_decay)) - + global_stats = True if self.freeze_norm else False out = fluid.layers.batch_norm( input=input, @@ -353,7 +408,7 @@ class HRNet(object): scale.stop_gradient = True bias.stop_gradient = True return out - + def __call__(self, input): assert isinstance(input, Variable) assert not (set(self.feature_maps) - set([2, 3, 4, 5])), \ @@ -363,15 +418,14 @@ class HRNet(object): res = input feature_maps = self.feature_maps - self.net( input ) + self.net(input) for i in feature_maps: - res = self.end_points[i-2] + res = self.end_points[i - 2] if i in self.feature_maps: res_endpoints.append(res) if self.freeze_at >= i: res.stop_gradient = True - + return OrderedDict([('res{}_sum'.format(self.feature_maps[idx]), feat) for idx, feat in enumerate(res_endpoints)]) - diff --git a/ppdet/modeling/backbones/res2net.py b/ppdet/modeling/backbones/res2net.py index ffac0353d..d30ce0b80 100644 --- a/ppdet/modeling/backbones/res2net.py +++ b/ppdet/modeling/backbones/res2net.py @@ -54,31 +54,34 @@ class Res2Net(ResNet): """ __shared__ = ['norm_type', 'freeze_norm', 'weight_prefix_name'] - def __init__(self, - depth=50, - width=26, - scales=4, - freeze_at=2, - norm_type='bn', - freeze_norm=True, - norm_decay=0., - variant='b', - feature_maps=[2, 3, 4, 5], - dcn_v2_stages=[], - weight_prefix_name='', - nonlocal_stages=[],): - super(Res2Net, self).__init__(depth=depth, - freeze_at=freeze_at, - norm_type=norm_type, - freeze_norm=freeze_norm, - norm_decay=norm_decay, - variant=variant, - feature_maps=feature_maps, - dcn_v2_stages=dcn_v2_stages, - weight_prefix_name=weight_prefix_name, - nonlocal_stages=nonlocal_stages) - - assert depth >= 50, "just support depth>=50 in res2net, but got depth=".format(depth) + def __init__( + self, + depth=50, + width=26, + scales=4, + freeze_at=2, + norm_type='bn', + freeze_norm=True, + norm_decay=0., + variant='b', + feature_maps=[2, 3, 4, 5], + dcn_v2_stages=[], + weight_prefix_name='', + nonlocal_stages=[], ): + super(Res2Net, self).__init__( + depth=depth, + freeze_at=freeze_at, + norm_type=norm_type, + freeze_norm=freeze_norm, + norm_decay=norm_decay, + variant=variant, + feature_maps=feature_maps, + dcn_v2_stages=dcn_v2_stages, + weight_prefix_name=weight_prefix_name, + nonlocal_stages=nonlocal_stages) + + assert depth >= 50, "just support depth>=50 in res2net, but got depth=".format( + depth) # res2net config self.scales = scales self.width = width @@ -96,60 +99,62 @@ class Res2Net(ResNet): name, dcn_v2=False): conv0 = self._conv_norm( - input=input, - num_filters=num_filters1, - filter_size=1, - stride=1, - act='relu', + input=input, + num_filters=num_filters1, + filter_size=1, + stride=1, + act='relu', name=name + '_branch2a') xs = fluid.layers.split(conv0, self.scales, 1) ys = [] for s in range(self.scales - 1): if s == 0 or stride == 2: - ys.append(self._conv_norm(input=xs[s], - num_filters=num_filters1//self.scales, - stride=stride, - filter_size=3, - act='relu', - name=name+ '_branch2b_' + str(s+1), - dcn_v2=dcn_v2)) + ys.append( + self._conv_norm( + input=xs[s], + num_filters=num_filters1 // self.scales, + stride=stride, + filter_size=3, + act='relu', + name=name + '_branch2b_' + str(s + 1), + dcn_v2=dcn_v2)) else: - ys.append(self._conv_norm(input=xs[s]+ys[-1], - num_filters=num_filters1//self.scales, - stride=stride, - filter_size=3, - act='relu', - name=name+ '_branch2b_' + str(s+1), - dcn_v2=dcn_v2)) + ys.append( + self._conv_norm( + input=xs[s] + ys[-1], + num_filters=num_filters1 // self.scales, + stride=stride, + filter_size=3, + act='relu', + name=name + '_branch2b_' + str(s + 1), + dcn_v2=dcn_v2)) if stride == 1: ys.append(xs[-1]) else: - ys.append(fluid.layers.pool2d(input=xs[-1], - pool_size=3, - pool_stride=stride, - pool_padding=1, - pool_type='avg')) + ys.append( + fluid.layers.pool2d( + input=xs[-1], + pool_size=3, + pool_stride=stride, + pool_padding=1, + pool_type='avg')) conv1 = fluid.layers.concat(ys, axis=1) conv2 = self._conv_norm( input=conv1, num_filters=num_filters2, filter_size=1, - act=None, - name=name+"_branch2c") + act=None, + name=name + "_branch2c") - short = self._shortcut(input, - num_filters2, - stride, - is_first, - name=name + "_branch1") + short = self._shortcut( + input, num_filters2, stride, is_first, name=name + "_branch1") return fluid.layers.elementwise_add( x=short, y=conv2, act='relu', name=name + ".add.output.5") - def layer_warp(self, input, stage_num): """ Args: @@ -167,14 +172,15 @@ class Res2Net(ResNet): ch_out = self.stage_filters[stage_num - 2] is_first = False if stage_num != 2 else True dcn_v2 = True if stage_num in self.dcn_v2_stages else False - - num_filters1 = self.num_filters1[stage_num-2] - num_filters2 = self.num_filters2[stage_num-2] - + + num_filters1 = self.num_filters1[stage_num - 2] + num_filters2 = self.num_filters2[stage_num - 2] + nonlocal_mod = 1000 if stage_num in self.nonlocal_stages: - nonlocal_mod = self.nonlocal_mod_cfg[self.depth] if stage_num==4 else 2 - + nonlocal_mod = self.nonlocal_mod_cfg[ + self.depth] if stage_num == 4 else 2 + # Make the layer name and parameter name consistent # with ImageNet pre-trained model conv = input @@ -190,14 +196,14 @@ class Res2Net(ResNet): is_first=is_first, name=conv_name, dcn_v2=dcn_v2) - + # add non local model dim_in = conv.shape[1] - nonlocal_name = "nonlocal_conv{}".format( stage_num ) + nonlocal_name = "nonlocal_conv{}".format(stage_num) if i % nonlocal_mod == nonlocal_mod - 1: - conv = add_space_nonlocal( - conv, dim_in, dim_in, - nonlocal_name + '_{}'.format(i), int(dim_in / 2) ) + conv = add_space_nonlocal(conv, dim_in, dim_in, + nonlocal_name + '_{}'.format(i), + int(dim_in / 2)) return conv @@ -217,7 +223,7 @@ class Res2NetC5(Res2Net): variant='b', feature_maps=[5], weight_prefix_name=''): - super(Res2NetC5, self).__init__(depth, width, scales, - freeze_at, norm_type, freeze_norm, - norm_decay, variant, feature_maps) + super(Res2NetC5, self).__init__(depth, width, scales, freeze_at, + norm_type, freeze_norm, norm_decay, + variant, feature_maps) self.severed_head = True diff --git a/ppdet/modeling/losses/iou_loss.py b/ppdet/modeling/losses/iou_loss.py index 253d00b09..39cb1b9b1 100644 --- a/ppdet/modeling/losses/iou_loss.py +++ b/ppdet/modeling/losses/iou_loss.py @@ -36,16 +36,25 @@ class IouLoss(object): max_height (int): max height of input to support random shape input max_width (int): max width of input to support random shape input """ - def __init__(self, - loss_weight=2.5, - max_height=608, - max_width=608): + + def __init__(self, loss_weight=2.5, max_height=608, max_width=608): self._loss_weight = loss_weight self._MAX_HI = max_height self._MAX_WI = max_width - def __call__(self, x, y, w, h, tx, ty, tw, th, - anchors, downsample_ratio, batch_size, eps=1.e-10): + def __call__(self, + x, + y, + w, + h, + tx, + ty, + tw, + th, + anchors, + downsample_ratio, + batch_size, + eps=1.e-10): ''' Args: x | y | w | h ([Variables]): the output of yolov3 for encoded x|y|w|h @@ -55,10 +64,10 @@ class IouLoss(object): batch_size (int): training batch size eps (float): the decimal to prevent the denominator eqaul zero ''' - x1, y1, x2, y2 = self._bbox_transform(x, y, w, h, anchors, - downsample_ratio, batch_size, False) - x1g, y1g, x2g, y2g = self._bbox_transform(tx, ty, tw, th, - anchors, downsample_ratio, batch_size, True) + x1, y1, x2, y2 = self._bbox_transform( + x, y, w, h, anchors, downsample_ratio, batch_size, False) + x1g, y1g, x2g, y2g = self._bbox_transform( + tx, ty, tw, th, anchors, downsample_ratio, batch_size, True) x2 = fluid.layers.elementwise_max(x1, x2) y2 = fluid.layers.elementwise_max(y1, y2) @@ -76,14 +85,16 @@ class IouLoss(object): intsctk = (xkis2 - xkis1) * (ykis2 - ykis1) intsctk = intsctk * fluid.layers.greater_than( xkis2, xkis1) * fluid.layers.greater_than(ykis2, ykis1) - unionk = (x2 - x1) * (y2 - y1) + (x2g - x1g) * (y2g - y1g) - intsctk + eps + unionk = (x2 - x1) * (y2 - y1) + (x2g - x1g) * (y2g - y1g + ) - intsctk + eps iouk = intsctk / unionk loss_iou = 1. - iouk * iouk loss_iou = loss_iou * self._loss_weight return loss_iou - def _bbox_transform(self, dcx, dcy, dw, dh, anchors, downsample_ratio, batch_size, is_gt): + def _bbox_transform(self, dcx, dcy, dw, dh, anchors, downsample_ratio, + batch_size, is_gt): grid_x = int(self._MAX_WI / downsample_ratio) grid_y = int(self._MAX_HI / downsample_ratio) an_num = len(anchors) // 2 @@ -125,14 +136,16 @@ class IouLoss(object): anchor_w_np = np.array(anchor_w_) anchor_w_np = np.reshape(anchor_w_np, newshape=[1, an_num, 1, 1]) anchor_w_np = np.tile(anchor_w_np, reps=[batch_size, 1, grid_y, grid_x]) - anchor_w_max = self._create_tensor_from_numpy(anchor_w_np.astype(np.float32)) + anchor_w_max = self._create_tensor_from_numpy( + anchor_w_np.astype(np.float32)) anchor_w = fluid.layers.crop(x=anchor_w_max, shape=dcx) anchor_w.stop_gradient = True anchor_h_ = [anchors[i] for i in range(0, len(anchors)) if i % 2 == 1] anchor_h_np = np.array(anchor_h_) anchor_h_np = np.reshape(anchor_h_np, newshape=[1, an_num, 1, 1]) anchor_h_np = np.tile(anchor_h_np, reps=[batch_size, 1, grid_y, grid_x]) - anchor_h_max = self._create_tensor_from_numpy(anchor_h_np.astype(np.float32)) + anchor_h_max = self._create_tensor_from_numpy( + anchor_h_np.astype(np.float32)) anchor_h = fluid.layers.crop(x=anchor_h_max, shape=dcx) anchor_h.stop_gradient = True # e^tw e^th @@ -147,7 +160,6 @@ class IouLoss(object): exp_dh.stop_gradient = True pw.stop_gradient = True ph.stop_gradient = True - x1 = cx - 0.5 * pw y1 = cy - 0.5 * ph @@ -169,4 +181,3 @@ class IouLoss(object): default_initializer=NumpyArrayInitializer(numpy_array)) paddle_array.stop_gradient = True return paddle_array - diff --git a/ppdet/modeling/losses/yolo_loss.py b/ppdet/modeling/losses/yolo_loss.py index a0ffdfcfc..6b6d51a51 100644 --- a/ppdet/modeling/losses/yolo_loss.py +++ b/ppdet/modeling/losses/yolo_loss.py @@ -131,8 +131,8 @@ class YOLOv3Loss(object): loss_h = fluid.layers.abs(h - th) * tscale_tobj loss_h = fluid.layers.reduce_sum(loss_h, dim=[1, 2, 3]) if self._iou_loss is not None: - loss_iou = self._iou_loss(x, y, w, h, tx, ty, tw, th, - anchors, downsample, self._batch_size) + loss_iou = self._iou_loss(x, y, w, h, tx, ty, tw, th, anchors, + downsample, self._batch_size) loss_iou = loss_iou * tscale_tobj loss_iou = fluid.layers.reduce_sum(loss_iou, dim=[1, 2, 3]) loss_ious.append(fluid.layers.reduce_mean(loss_iou)) diff --git a/ppdet/modeling/roi_heads/cascade_head.py b/ppdet/modeling/roi_heads/cascade_head.py index ad574242c..e32584bd3 100644 --- a/ppdet/modeling/roi_heads/cascade_head.py +++ b/ppdet/modeling/roi_heads/cascade_head.py @@ -219,29 +219,33 @@ class CascadeBBoxHead(object): return {'bbox': box_out, 'score': boxes_cls_prob_mean} pred_result = self.nms(bboxes=box_out, scores=boxes_cls_prob_mean) return {"bbox": pred_result} - - def get_prediction_cls_aware(self, - im_info, - im_shape, - cascade_cls_prob, - cascade_decoded_box, - cascade_bbox_reg_weights): + + def get_prediction_cls_aware(self, im_info, im_shape, cascade_cls_prob, + cascade_decoded_box, cascade_bbox_reg_weights): ''' get_prediction_cls_aware: predict bbox for each class ''' cascade_num_stage = 3 cascade_eval_weight = [0.2, 0.3, 0.5] # merge 3 stages results - sum_cascade_cls_prob = sum([ prob*cascade_eval_weight[idx] for idx, prob in enumerate(cascade_cls_prob) ]) - sum_cascade_decoded_box = sum([ bbox*cascade_eval_weight[idx] for idx, bbox in enumerate(cascade_decoded_box) ]) + sum_cascade_cls_prob = sum([ + prob * cascade_eval_weight[idx] + for idx, prob in enumerate(cascade_cls_prob) + ]) + sum_cascade_decoded_box = sum([ + bbox * cascade_eval_weight[idx] + for idx, bbox in enumerate(cascade_decoded_box) + ]) self.im_scale = fluid.layers.slice(im_info, [1], starts=[2], ends=[3]) - im_scale_lod = fluid.layers.sequence_expand(self.im_scale, sum_cascade_decoded_box) - + im_scale_lod = fluid.layers.sequence_expand(self.im_scale, + sum_cascade_decoded_box) + sum_cascade_decoded_box = sum_cascade_decoded_box / im_scale_lod - + decoded_bbox = sum_cascade_decoded_box - decoded_bbox = fluid.layers.reshape(decoded_bbox, shape=(-1, self.num_classes, 4) ) - + decoded_bbox = fluid.layers.reshape( + decoded_bbox, shape=(-1, self.num_classes, 4)) + box_out = fluid.layers.box_clip(input=decoded_bbox, im_info=im_shape) pred_result = self.nms(bboxes=box_out, scores=sum_cascade_cls_prob) return {"bbox": pred_result} diff --git a/ppdet/utils/oid_eval.py b/ppdet/utils/oid_eval.py index 21d4813f5..0a5a0c534 100644 --- a/ppdet/utils/oid_eval.py +++ b/ppdet/utils/oid_eval.py @@ -26,519 +26,518 @@ from .coco_eval import bbox2out import logging logger = logging.getLogger(__name__) - __all__ = ['bbox2out', 'get_category_info'] + def get_category_info(anno_file=None, with_background=True, use_default_label=False): - clsid2catid = { k:k for k in range(1, 501) } + clsid2catid = {k: k for k in range(1, 501)} catid2name = { - 0:"background", - 1:"Infant bed", - 2:"Rose", - 3:"Flag", - 4:"Flashlight", - 5:"Sea turtle", - 6:"Camera", - 7:"Animal", - 8:"Glove", - 9:"Crocodile", - 10:"Cattle", - 11:"House", - 12:"Guacamole", - 13:"Penguin", - 14:"Vehicle registration plate", - 15:"Bench", - 16:"Ladybug", - 17:"Human nose", - 18:"Watermelon", - 19:"Flute", - 20:"Butterfly", - 21:"Washing machine", - 22:"Raccoon", - 23:"Segway", - 24:"Taco", - 25:"Jellyfish", - 26:"Cake", - 27:"Pen", - 28:"Cannon", - 29:"Bread", - 30:"Tree", - 31:"Shellfish", - 32:"Bed", - 33:"Hamster", - 34:"Hat", - 35:"Toaster", - 36:"Sombrero", - 37:"Tiara", - 38:"Bowl", - 39:"Dragonfly", - 40:"Moths and butterflies", - 41:"Antelope", - 42:"Vegetable", - 43:"Torch", - 44:"Building", - 45:"Power plugs and sockets", - 46:"Blender", - 47:"Billiard table", - 48:"Cutting board", - 49:"Bronze sculpture", - 50:"Turtle", - 51:"Broccoli", - 52:"Tiger", - 53:"Mirror", - 54:"Bear", - 55:"Zucchini", - 56:"Dress", - 57:"Volleyball", - 58:"Guitar", - 59:"Reptile", - 60:"Golf cart", - 61:"Tart", - 62:"Fedora", - 63:"Carnivore", - 64:"Car", - 65:"Lighthouse", - 66:"Coffeemaker", - 67:"Food processor", - 68:"Truck", - 69:"Bookcase", - 70:"Surfboard", - 71:"Footwear", - 72:"Bench", - 73:"Necklace", - 74:"Flower", - 75:"Radish", - 76:"Marine mammal", - 77:"Frying pan", - 78:"Tap", - 79:"Peach", - 80:"Knife", - 81:"Handbag", - 82:"Laptop", - 83:"Tent", - 84:"Ambulance", - 85:"Christmas tree", - 86:"Eagle", - 87:"Limousine", - 88:"Kitchen & dining room table", - 89:"Polar bear", - 90:"Tower", - 91:"Football", - 92:"Willow", - 93:"Human head", - 94:"Stop sign", - 95:"Banana", - 96:"Mixer", - 97:"Binoculars", - 98:"Dessert", - 99:"Bee", - 100:"Chair", - 101:"Wood-burning stove", - 102:"Flowerpot", - 103:"Beaker", - 104:"Oyster", - 105:"Woodpecker", - 106:"Harp", - 107:"Bathtub", - 108:"Wall clock", - 109:"Sports uniform", - 110:"Rhinoceros", - 111:"Beehive", - 112:"Cupboard", - 113:"Chicken", - 114:"Man", - 115:"Blue jay", - 116:"Cucumber", - 117:"Balloon", - 118:"Kite", - 119:"Fireplace", - 120:"Lantern", - 121:"Missile", - 122:"Book", - 123:"Spoon", - 124:"Grapefruit", - 125:"Squirrel", - 126:"Orange", - 127:"Coat", - 128:"Punching bag", - 129:"Zebra", - 130:"Billboard", - 131:"Bicycle", - 132:"Door handle", - 133:"Mechanical fan", - 134:"Ring binder", - 135:"Table", - 136:"Parrot", - 137:"Sock", - 138:"Vase", - 139:"Weapon", - 140:"Shotgun", - 141:"Glasses", - 142:"Seahorse", - 143:"Belt", - 144:"Watercraft", - 145:"Window", - 146:"Giraffe", - 147:"Lion", - 148:"Tire", - 149:"Vehicle", - 150:"Canoe", - 151:"Tie", - 152:"Shelf", - 153:"Picture frame", - 154:"Printer", - 155:"Human leg", - 156:"Boat", - 157:"Slow cooker", - 158:"Croissant", - 159:"Candle", - 160:"Pancake", - 161:"Pillow", - 162:"Coin", - 163:"Stretcher", - 164:"Sandal", - 165:"Woman", - 166:"Stairs", - 167:"Harpsichord", - 168:"Stool", - 169:"Bus", - 170:"Suitcase", - 171:"Human mouth", - 172:"Juice", - 173:"Skull", - 174:"Door", - 175:"Violin", - 176:"Chopsticks", - 177:"Digital clock", - 178:"Sunflower", - 179:"Leopard", - 180:"Bell pepper", - 181:"Harbor seal", - 182:"Snake", - 183:"Sewing machine", - 184:"Goose", - 185:"Helicopter", - 186:"Seat belt", - 187:"Coffee cup", - 188:"Microwave oven", - 189:"Hot dog", - 190:"Countertop", - 191:"Serving tray", - 192:"Dog bed", - 193:"Beer", - 194:"Sunglasses", - 195:"Golf ball", - 196:"Waffle", - 197:"Palm tree", - 198:"Trumpet", - 199:"Ruler", - 200:"Helmet", - 201:"Ladder", - 202:"Office building", - 203:"Tablet computer", - 204:"Toilet paper", - 205:"Pomegranate", - 206:"Skirt", - 207:"Gas stove", - 208:"Cookie", - 209:"Cart", - 210:"Raven", - 211:"Egg", - 212:"Burrito", - 213:"Goat", - 214:"Kitchen knife", - 215:"Skateboard", - 216:"Salt and pepper shakers", - 217:"Lynx", - 218:"Boot", - 219:"Platter", - 220:"Ski", - 221:"Swimwear", - 222:"Swimming pool", - 223:"Drinking straw", - 224:"Wrench", - 225:"Drum", - 226:"Ant", - 227:"Human ear", - 228:"Headphones", - 229:"Fountain", - 230:"Bird", - 231:"Jeans", - 232:"Television", - 233:"Crab", - 234:"Microphone", - 235:"Home appliance", - 236:"Snowplow", - 237:"Beetle", - 238:"Artichoke", - 239:"Jet ski", - 240:"Stationary bicycle", - 241:"Human hair", - 242:"Brown bear", - 243:"Starfish", - 244:"Fork", - 245:"Lobster", - 246:"Corded phone", - 247:"Drink", - 248:"Saucer", - 249:"Carrot", - 250:"Insect", - 251:"Clock", - 252:"Castle", - 253:"Tennis racket", - 254:"Ceiling fan", - 255:"Asparagus", - 256:"Jaguar", - 257:"Musical instrument", - 258:"Train", - 259:"Cat", - 260:"Rifle", - 261:"Dumbbell", - 262:"Mobile phone", - 263:"Taxi", - 264:"Shower", - 265:"Pitcher", - 266:"Lemon", - 267:"Invertebrate", - 268:"Turkey", - 269:"High heels", - 270:"Bust", - 271:"Elephant", - 272:"Scarf", - 273:"Barrel", - 274:"Trombone", - 275:"Pumpkin", - 276:"Box", - 277:"Tomato", - 278:"Frog", - 279:"Bidet", - 280:"Human face", - 281:"Houseplant", - 282:"Van", - 283:"Shark", - 284:"Ice cream", - 285:"Swim cap", - 286:"Falcon", - 287:"Ostrich", - 288:"Handgun", - 289:"Whiteboard", - 290:"Lizard", - 291:"Pasta", - 292:"Snowmobile", - 293:"Light bulb", - 294:"Window blind", - 295:"Muffin", - 296:"Pretzel", - 297:"Computer monitor", - 298:"Horn", - 299:"Furniture", - 300:"Sandwich", - 301:"Fox", - 302:"Convenience store", - 303:"Fish", - 304:"Fruit", - 305:"Earrings", - 306:"Curtain", - 307:"Grape", - 308:"Sofa bed", - 309:"Horse", - 310:"Luggage and bags", - 311:"Desk", - 312:"Crutch", - 313:"Bicycle helmet", - 314:"Tick", - 315:"Airplane", - 316:"Canary", - 317:"Spatula", - 318:"Watch", - 319:"Lily", - 320:"Kitchen appliance", - 321:"Filing cabinet", - 322:"Aircraft", - 323:"Cake stand", - 324:"Candy", - 325:"Sink", - 326:"Mouse", - 327:"Wine", - 328:"Wheelchair", - 329:"Goldfish", - 330:"Refrigerator", - 331:"French fries", - 332:"Drawer", - 333:"Treadmill", - 334:"Picnic basket", - 335:"Dice", - 336:"Cabbage", - 337:"Football helmet", - 338:"Pig", - 339:"Person", - 340:"Shorts", - 341:"Gondola", - 342:"Honeycomb", - 343:"Doughnut", - 344:"Chest of drawers", - 345:"Land vehicle", - 346:"Bat", - 347:"Monkey", - 348:"Dagger", - 349:"Tableware", - 350:"Human foot", - 351:"Mug", - 352:"Alarm clock", - 353:"Pressure cooker", - 354:"Human hand", - 355:"Tortoise", - 356:"Baseball glove", - 357:"Sword", - 358:"Pear", - 359:"Miniskirt", - 360:"Traffic sign", - 361:"Girl", - 362:"Roller skates", - 363:"Dinosaur", - 364:"Porch", - 365:"Human beard", - 366:"Submarine sandwich", - 367:"Screwdriver", - 368:"Strawberry", - 369:"Wine glass", - 370:"Seafood", - 371:"Racket", - 372:"Wheel", - 373:"Sea lion", - 374:"Toy", - 375:"Tea", - 376:"Tennis ball", - 377:"Waste container", - 378:"Mule", - 379:"Cricket ball", - 380:"Pineapple", - 381:"Coconut", - 382:"Doll", - 383:"Coffee table", - 384:"Snowman", - 385:"Lavender", - 386:"Shrimp", - 387:"Maple", - 388:"Cowboy hat", - 389:"Goggles", - 390:"Rugby ball", - 391:"Caterpillar", - 392:"Poster", - 393:"Rocket", - 394:"Organ", - 395:"Saxophone", - 396:"Traffic light", - 397:"Cocktail", - 398:"Plastic bag", - 399:"Squash", - 400:"Mushroom", - 401:"Hamburger", - 402:"Light switch", - 403:"Parachute", - 404:"Teddy bear", - 405:"Winter melon", - 406:"Deer", - 407:"Musical keyboard", - 408:"Plumbing fixture", - 409:"Scoreboard", - 410:"Baseball bat", - 411:"Envelope", - 412:"Adhesive tape", - 413:"Briefcase", - 414:"Paddle", - 415:"Bow and arrow", - 416:"Telephone", - 417:"Sheep", - 418:"Jacket", - 419:"Boy", - 420:"Pizza", - 421:"Otter", - 422:"Office supplies", - 423:"Couch", - 424:"Cello", - 425:"Bull", - 426:"Camel", - 427:"Ball", - 428:"Duck", - 429:"Whale", - 430:"Shirt", - 431:"Tank", - 432:"Motorcycle", - 433:"Accordion", - 434:"Owl", - 435:"Porcupine", - 436:"Sun hat", - 437:"Nail", - 438:"Scissors", - 439:"Swan", - 440:"Lamp", - 441:"Crown", - 442:"Piano", - 443:"Sculpture", - 444:"Cheetah", - 445:"Oboe", - 446:"Tin can", - 447:"Mango", - 448:"Tripod", - 449:"Oven", - 450:"Mouse", - 451:"Barge", - 452:"Coffee", - 453:"Snowboard", - 454:"Common fig", - 455:"Salad", - 456:"Marine invertebrates", - 457:"Umbrella", - 458:"Kangaroo", - 459:"Human arm", - 460:"Measuring cup", - 461:"Snail", - 462:"Loveseat", - 463:"Suit", - 464:"Teapot", - 465:"Bottle", - 466:"Alpaca", - 467:"Kettle", - 468:"Trousers", - 469:"Popcorn", - 470:"Centipede", - 471:"Spider", - 472:"Sparrow", - 473:"Plate", - 474:"Bagel", - 475:"Personal care", - 476:"Apple", - 477:"Brassiere", - 478:"Bathroom cabinet", - 479:"studio couch", - 480:"Computer keyboard", - 481:"Table tennis racket", - 482:"Sushi", - 483:"Cabinetry", - 484:"Street light", - 485:"Towel", - 486:"Nightstand", - 487:"Rabbit", - 488:"Dolphin", - 489:"Dog", - 490:"Jug", - 491:"Wok", - 492:"Fire hydrant", - 493:"Human eye", - 494:"Skyscraper", - 495:"Backpack", - 496:"Potato", - 497:"Paper towel", - 498:"Lifejacket", - 499:"Bicycle wheel", - 500:"Toilet", + 0: "background", + 1: "Infant bed", + 2: "Rose", + 3: "Flag", + 4: "Flashlight", + 5: "Sea turtle", + 6: "Camera", + 7: "Animal", + 8: "Glove", + 9: "Crocodile", + 10: "Cattle", + 11: "House", + 12: "Guacamole", + 13: "Penguin", + 14: "Vehicle registration plate", + 15: "Bench", + 16: "Ladybug", + 17: "Human nose", + 18: "Watermelon", + 19: "Flute", + 20: "Butterfly", + 21: "Washing machine", + 22: "Raccoon", + 23: "Segway", + 24: "Taco", + 25: "Jellyfish", + 26: "Cake", + 27: "Pen", + 28: "Cannon", + 29: "Bread", + 30: "Tree", + 31: "Shellfish", + 32: "Bed", + 33: "Hamster", + 34: "Hat", + 35: "Toaster", + 36: "Sombrero", + 37: "Tiara", + 38: "Bowl", + 39: "Dragonfly", + 40: "Moths and butterflies", + 41: "Antelope", + 42: "Vegetable", + 43: "Torch", + 44: "Building", + 45: "Power plugs and sockets", + 46: "Blender", + 47: "Billiard table", + 48: "Cutting board", + 49: "Bronze sculpture", + 50: "Turtle", + 51: "Broccoli", + 52: "Tiger", + 53: "Mirror", + 54: "Bear", + 55: "Zucchini", + 56: "Dress", + 57: "Volleyball", + 58: "Guitar", + 59: "Reptile", + 60: "Golf cart", + 61: "Tart", + 62: "Fedora", + 63: "Carnivore", + 64: "Car", + 65: "Lighthouse", + 66: "Coffeemaker", + 67: "Food processor", + 68: "Truck", + 69: "Bookcase", + 70: "Surfboard", + 71: "Footwear", + 72: "Bench", + 73: "Necklace", + 74: "Flower", + 75: "Radish", + 76: "Marine mammal", + 77: "Frying pan", + 78: "Tap", + 79: "Peach", + 80: "Knife", + 81: "Handbag", + 82: "Laptop", + 83: "Tent", + 84: "Ambulance", + 85: "Christmas tree", + 86: "Eagle", + 87: "Limousine", + 88: "Kitchen & dining room table", + 89: "Polar bear", + 90: "Tower", + 91: "Football", + 92: "Willow", + 93: "Human head", + 94: "Stop sign", + 95: "Banana", + 96: "Mixer", + 97: "Binoculars", + 98: "Dessert", + 99: "Bee", + 100: "Chair", + 101: "Wood-burning stove", + 102: "Flowerpot", + 103: "Beaker", + 104: "Oyster", + 105: "Woodpecker", + 106: "Harp", + 107: "Bathtub", + 108: "Wall clock", + 109: "Sports uniform", + 110: "Rhinoceros", + 111: "Beehive", + 112: "Cupboard", + 113: "Chicken", + 114: "Man", + 115: "Blue jay", + 116: "Cucumber", + 117: "Balloon", + 118: "Kite", + 119: "Fireplace", + 120: "Lantern", + 121: "Missile", + 122: "Book", + 123: "Spoon", + 124: "Grapefruit", + 125: "Squirrel", + 126: "Orange", + 127: "Coat", + 128: "Punching bag", + 129: "Zebra", + 130: "Billboard", + 131: "Bicycle", + 132: "Door handle", + 133: "Mechanical fan", + 134: "Ring binder", + 135: "Table", + 136: "Parrot", + 137: "Sock", + 138: "Vase", + 139: "Weapon", + 140: "Shotgun", + 141: "Glasses", + 142: "Seahorse", + 143: "Belt", + 144: "Watercraft", + 145: "Window", + 146: "Giraffe", + 147: "Lion", + 148: "Tire", + 149: "Vehicle", + 150: "Canoe", + 151: "Tie", + 152: "Shelf", + 153: "Picture frame", + 154: "Printer", + 155: "Human leg", + 156: "Boat", + 157: "Slow cooker", + 158: "Croissant", + 159: "Candle", + 160: "Pancake", + 161: "Pillow", + 162: "Coin", + 163: "Stretcher", + 164: "Sandal", + 165: "Woman", + 166: "Stairs", + 167: "Harpsichord", + 168: "Stool", + 169: "Bus", + 170: "Suitcase", + 171: "Human mouth", + 172: "Juice", + 173: "Skull", + 174: "Door", + 175: "Violin", + 176: "Chopsticks", + 177: "Digital clock", + 178: "Sunflower", + 179: "Leopard", + 180: "Bell pepper", + 181: "Harbor seal", + 182: "Snake", + 183: "Sewing machine", + 184: "Goose", + 185: "Helicopter", + 186: "Seat belt", + 187: "Coffee cup", + 188: "Microwave oven", + 189: "Hot dog", + 190: "Countertop", + 191: "Serving tray", + 192: "Dog bed", + 193: "Beer", + 194: "Sunglasses", + 195: "Golf ball", + 196: "Waffle", + 197: "Palm tree", + 198: "Trumpet", + 199: "Ruler", + 200: "Helmet", + 201: "Ladder", + 202: "Office building", + 203: "Tablet computer", + 204: "Toilet paper", + 205: "Pomegranate", + 206: "Skirt", + 207: "Gas stove", + 208: "Cookie", + 209: "Cart", + 210: "Raven", + 211: "Egg", + 212: "Burrito", + 213: "Goat", + 214: "Kitchen knife", + 215: "Skateboard", + 216: "Salt and pepper shakers", + 217: "Lynx", + 218: "Boot", + 219: "Platter", + 220: "Ski", + 221: "Swimwear", + 222: "Swimming pool", + 223: "Drinking straw", + 224: "Wrench", + 225: "Drum", + 226: "Ant", + 227: "Human ear", + 228: "Headphones", + 229: "Fountain", + 230: "Bird", + 231: "Jeans", + 232: "Television", + 233: "Crab", + 234: "Microphone", + 235: "Home appliance", + 236: "Snowplow", + 237: "Beetle", + 238: "Artichoke", + 239: "Jet ski", + 240: "Stationary bicycle", + 241: "Human hair", + 242: "Brown bear", + 243: "Starfish", + 244: "Fork", + 245: "Lobster", + 246: "Corded phone", + 247: "Drink", + 248: "Saucer", + 249: "Carrot", + 250: "Insect", + 251: "Clock", + 252: "Castle", + 253: "Tennis racket", + 254: "Ceiling fan", + 255: "Asparagus", + 256: "Jaguar", + 257: "Musical instrument", + 258: "Train", + 259: "Cat", + 260: "Rifle", + 261: "Dumbbell", + 262: "Mobile phone", + 263: "Taxi", + 264: "Shower", + 265: "Pitcher", + 266: "Lemon", + 267: "Invertebrate", + 268: "Turkey", + 269: "High heels", + 270: "Bust", + 271: "Elephant", + 272: "Scarf", + 273: "Barrel", + 274: "Trombone", + 275: "Pumpkin", + 276: "Box", + 277: "Tomato", + 278: "Frog", + 279: "Bidet", + 280: "Human face", + 281: "Houseplant", + 282: "Van", + 283: "Shark", + 284: "Ice cream", + 285: "Swim cap", + 286: "Falcon", + 287: "Ostrich", + 288: "Handgun", + 289: "Whiteboard", + 290: "Lizard", + 291: "Pasta", + 292: "Snowmobile", + 293: "Light bulb", + 294: "Window blind", + 295: "Muffin", + 296: "Pretzel", + 297: "Computer monitor", + 298: "Horn", + 299: "Furniture", + 300: "Sandwich", + 301: "Fox", + 302: "Convenience store", + 303: "Fish", + 304: "Fruit", + 305: "Earrings", + 306: "Curtain", + 307: "Grape", + 308: "Sofa bed", + 309: "Horse", + 310: "Luggage and bags", + 311: "Desk", + 312: "Crutch", + 313: "Bicycle helmet", + 314: "Tick", + 315: "Airplane", + 316: "Canary", + 317: "Spatula", + 318: "Watch", + 319: "Lily", + 320: "Kitchen appliance", + 321: "Filing cabinet", + 322: "Aircraft", + 323: "Cake stand", + 324: "Candy", + 325: "Sink", + 326: "Mouse", + 327: "Wine", + 328: "Wheelchair", + 329: "Goldfish", + 330: "Refrigerator", + 331: "French fries", + 332: "Drawer", + 333: "Treadmill", + 334: "Picnic basket", + 335: "Dice", + 336: "Cabbage", + 337: "Football helmet", + 338: "Pig", + 339: "Person", + 340: "Shorts", + 341: "Gondola", + 342: "Honeycomb", + 343: "Doughnut", + 344: "Chest of drawers", + 345: "Land vehicle", + 346: "Bat", + 347: "Monkey", + 348: "Dagger", + 349: "Tableware", + 350: "Human foot", + 351: "Mug", + 352: "Alarm clock", + 353: "Pressure cooker", + 354: "Human hand", + 355: "Tortoise", + 356: "Baseball glove", + 357: "Sword", + 358: "Pear", + 359: "Miniskirt", + 360: "Traffic sign", + 361: "Girl", + 362: "Roller skates", + 363: "Dinosaur", + 364: "Porch", + 365: "Human beard", + 366: "Submarine sandwich", + 367: "Screwdriver", + 368: "Strawberry", + 369: "Wine glass", + 370: "Seafood", + 371: "Racket", + 372: "Wheel", + 373: "Sea lion", + 374: "Toy", + 375: "Tea", + 376: "Tennis ball", + 377: "Waste container", + 378: "Mule", + 379: "Cricket ball", + 380: "Pineapple", + 381: "Coconut", + 382: "Doll", + 383: "Coffee table", + 384: "Snowman", + 385: "Lavender", + 386: "Shrimp", + 387: "Maple", + 388: "Cowboy hat", + 389: "Goggles", + 390: "Rugby ball", + 391: "Caterpillar", + 392: "Poster", + 393: "Rocket", + 394: "Organ", + 395: "Saxophone", + 396: "Traffic light", + 397: "Cocktail", + 398: "Plastic bag", + 399: "Squash", + 400: "Mushroom", + 401: "Hamburger", + 402: "Light switch", + 403: "Parachute", + 404: "Teddy bear", + 405: "Winter melon", + 406: "Deer", + 407: "Musical keyboard", + 408: "Plumbing fixture", + 409: "Scoreboard", + 410: "Baseball bat", + 411: "Envelope", + 412: "Adhesive tape", + 413: "Briefcase", + 414: "Paddle", + 415: "Bow and arrow", + 416: "Telephone", + 417: "Sheep", + 418: "Jacket", + 419: "Boy", + 420: "Pizza", + 421: "Otter", + 422: "Office supplies", + 423: "Couch", + 424: "Cello", + 425: "Bull", + 426: "Camel", + 427: "Ball", + 428: "Duck", + 429: "Whale", + 430: "Shirt", + 431: "Tank", + 432: "Motorcycle", + 433: "Accordion", + 434: "Owl", + 435: "Porcupine", + 436: "Sun hat", + 437: "Nail", + 438: "Scissors", + 439: "Swan", + 440: "Lamp", + 441: "Crown", + 442: "Piano", + 443: "Sculpture", + 444: "Cheetah", + 445: "Oboe", + 446: "Tin can", + 447: "Mango", + 448: "Tripod", + 449: "Oven", + 450: "Mouse", + 451: "Barge", + 452: "Coffee", + 453: "Snowboard", + 454: "Common fig", + 455: "Salad", + 456: "Marine invertebrates", + 457: "Umbrella", + 458: "Kangaroo", + 459: "Human arm", + 460: "Measuring cup", + 461: "Snail", + 462: "Loveseat", + 463: "Suit", + 464: "Teapot", + 465: "Bottle", + 466: "Alpaca", + 467: "Kettle", + 468: "Trousers", + 469: "Popcorn", + 470: "Centipede", + 471: "Spider", + 472: "Sparrow", + 473: "Plate", + 474: "Bagel", + 475: "Personal care", + 476: "Apple", + 477: "Brassiere", + 478: "Bathroom cabinet", + 479: "studio couch", + 480: "Computer keyboard", + 481: "Table tennis racket", + 482: "Sushi", + 483: "Cabinetry", + 484: "Street light", + 485: "Towel", + 486: "Nightstand", + 487: "Rabbit", + 488: "Dolphin", + 489: "Dog", + 490: "Jug", + 491: "Wok", + 492: "Fire hydrant", + 493: "Human eye", + 494: "Skyscraper", + 495: "Backpack", + 496: "Potato", + 497: "Paper towel", + 498: "Lifejacket", + 499: "Bicycle wheel", + 500: "Toilet", } - + if not with_background: clsid2catid = {k - 1: v for k, v in clsid2catid.items()} return clsid2catid, catid2name - \ No newline at end of file diff --git a/slim/sensitive/sensitive.py b/slim/sensitive/sensitive.py index 2e8f41c58..a8e95abf0 100644 --- a/slim/sensitive/sensitive.py +++ b/slim/sensitive/sensitive.py @@ -35,7 +35,6 @@ set_paddle_flags( FLAGS_eager_delete_tensor_gb=0, # enable GC to save memory ) - from paddle import fluid from ppdet.experimental import mixed_precision_context from ppdet.core.workspace import load_config, merge_config, create @@ -85,11 +84,16 @@ def main(): eval_prog = eval_prog.clone(True) if FLAGS.print_params: - print("-------------------------All parameters in current graph----------------------") + print( + "-------------------------All parameters in current graph----------------------" + ) for block in eval_prog.blocks: for param in block.all_parameters(): - print("parameter name: {}\tshape: {}".format(param.name, param.shape)) - print("------------------------------------------------------------------------------") + print("parameter name: {}\tshape: {}".format(param.name, + param.shape)) + print( + "------------------------------------------------------------------------------" + ) return eval_reader = create_reader(cfg.EvalReader) @@ -104,7 +108,7 @@ def main(): if cfg.metric == 'WIDERFACE': extra_keys = ['im_id', 'im_shape', 'gt_box'] eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog, - extra_keys) + extra_keys) exe.run(startup_prog) @@ -133,16 +137,16 @@ def main(): compiled_eval_prog = fluid.compiler.CompiledProgram(program) - results = eval_run(exe, compiled_eval_prog, eval_loader, - eval_keys, eval_values, eval_cls) + results = eval_run(exe, compiled_eval_prog, eval_loader, eval_keys, + eval_values, eval_cls) resolution = None if 'mask' in results[0]: resolution = model.mask_head.resolution dataset = cfg['EvalReader']['dataset'] box_ap_stats = eval_results( - results, - cfg.metric, - cfg.num_classes, + results, + cfg.metric, + cfg.num_classes, resolution, is_bbox_normalized, FLAGS.output_eval, @@ -151,18 +155,21 @@ def main(): return box_ap_stats[0] pruned_params = FLAGS.pruned_params - - assert (FLAGS.pruned_params is not None), "FLAGS.pruned_params is empty!!! Please set it by '--pruned_params' option." + + assert ( + FLAGS.pruned_params is not None + ), "FLAGS.pruned_params is empty!!! Please set it by '--pruned_params' option." pruned_params = FLAGS.pruned_params.strip().split(",") logger.info("pruned params: {}".format(pruned_params)) pruned_ratios = [float(n) for n in FLAGS.pruned_ratios.strip().split(" ")] logger.info("pruned ratios: {}".format(pruned_ratios)) - sensitivity(eval_prog, - place, - pruned_params, - test, - sensitivities_file=FLAGS.sensitivities_file, - pruned_ratios=pruned_ratios) + sensitivity( + eval_prog, + place, + pruned_params, + test, + sensitivities_file=FLAGS.sensitivities_file, + pruned_ratios=pruned_ratios) if __name__ == '__main__': @@ -195,7 +202,8 @@ if __name__ == '__main__': "--pruned_ratios", default="0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9", type=str, - help="The ratios pruned iteratively for each parameter when calculating sensitivities.") + help="The ratios pruned iteratively for each parameter when calculating sensitivities." + ) parser.add_argument( "-P", "--print_params", -- GitLab