Skip to content

Commit

Permalink
exit 1 when travis check failed (PaddlePaddle#214)
Browse files Browse the repository at this point in the history
* exit1 in travis failed
  • Loading branch information
heavengate authored Feb 6, 2020
1 parent fcfdbd2 commit 1475bb0
Show file tree
Hide file tree
Showing 16 changed files with 982 additions and 873 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .travis/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# add python requirements for unittests here, note install Cython
# and pycocotools directly is not supported in travis ci.
tqdm
9 changes: 6 additions & 3 deletions .travis/unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 .
Expand Down
28 changes: 14 additions & 14 deletions inference/tools/detection_result_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions inference/tools/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def colormap(rgb=False):
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))
Expand All @@ -106,8 +106,8 @@ def colormap(rgb=False):

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)
Expand Down
5 changes: 5 additions & 0 deletions ppdet/core/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
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']


Expand Down
8 changes: 3 additions & 5 deletions ppdet/data/tools/x2coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
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):
Expand Down Expand Up @@ -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')
Expand Down
91 changes: 51 additions & 40 deletions ppdet/modeling/backbones/cb_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(self,
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):
Expand Down Expand Up @@ -102,19 +102,26 @@ def __init__(self,

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,
Expand Down Expand Up @@ -145,7 +152,8 @@ def _conv_norm(self,
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(
Expand All @@ -155,8 +163,8 @@ def _conv_norm(self,
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],
Expand All @@ -173,19 +181,20 @@ def _conv_norm(self,
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)

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))

Expand All @@ -194,11 +203,12 @@ def _conv_norm(self,
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)
Expand Down Expand Up @@ -262,7 +272,7 @@ def bottleneck(self, input, num_filters, stride, is_first, name, dcn=False):
act=act,
groups=g,
name=_name,
dcn=(i==1 and dcn))
dcn=(i == 1 and dcn))
short = self._shortcut(
input,
num_filters * expand,
Expand All @@ -273,8 +283,7 @@ def bottleneck(self, input, num_filters, stride, is_first, name, dcn=False):
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."
Expand Down Expand Up @@ -313,10 +322,10 @@ def layer_warp(self, input, stage_num):
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
Expand All @@ -335,11 +344,12 @@ def layer_warp(self, input, stage_num):

# 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

Expand All @@ -349,9 +359,9 @@ def c1_stage(self, input):
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],
Expand All @@ -377,14 +387,15 @@ def c1_stage(self, input):
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
Expand Down Expand Up @@ -414,11 +425,11 @@ def __call__(self, input):
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)
Expand Down
Loading

0 comments on commit 1475bb0

Please sign in to comment.