Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#43 from AIPG/Issue/AIBT-1187
Browse files Browse the repository at this point in the history
Deleted unnecessary mkldnn parameter
  • Loading branch information
Uss, Wojciech authored and GitHub Enterprise committed Oct 18, 2018
2 parents 2d4466b + cb08ee0 commit abb4543
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
4 changes: 1 addition & 3 deletions fluid/object_detection/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
add_arg('mean_value_B', float, 127.5, "Mean value for B channel which will be subtracted.") #123.68
add_arg('mean_value_G', float, 127.5, "Mean value for G channel which will be subtracted.") #116.78
add_arg('mean_value_R', float, 127.5, "Mean value for R channel which will be subtracted.") #103.94
parser.add_argument('--use_mkldnn', action='store_true', help='If set, use MKL-DNN library.')
parser.add_argument('--profile', action='store_true', help='If set, do profiling.')
# yapf: enable

Expand All @@ -52,8 +51,7 @@ def eval(args, data_args, test_list):
use_cudnn = True if args.use_gpu else False

locs, confs, box, box_var = mobile_net(num_classes, image, image_shape,
use_cudnn=use_cudnn,
use_mkldnn=args.use_mkldnn)
use_cudnn=use_cudnn)
nmsed_out = fluid.layers.detection_output(
locs, confs, box, box_var, nms_threshold=args.nms_threshold)
loss = fluid.layers.ssd_loss(locs, confs, gt_box, gt_label, box, box_var)
Expand Down
57 changes: 23 additions & 34 deletions fluid/object_detection/mobilenet_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def conv_bn(input,
channels=None,
num_groups=1,
act='relu',
use_cudnn=True,
use_mkldnn=False):
use_cudnn=True):
parameter_attr = ParamAttr(learning_rate=0.1, initializer=MSRA())
conv = fluid.layers.conv2d(
input=input,
Expand All @@ -24,40 +23,36 @@ def conv_bn(input,
groups=num_groups,
act=None,
use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn,
param_attr=parameter_attr,
bias_attr=False)
parameter_attr = ParamAttr(learning_rate=0.1, initializer=MSRA())
bias_attr = ParamAttr(learning_rate=0.2)
return fluid.layers.batch_norm(input=conv, act=act, use_mkldnn=use_mkldnn)
return fluid.layers.batch_norm(input=conv, act=act)


def depthwise_separable(input, num_filters1, num_filters2, num_groups, stride,
scale, use_cudnn=True, use_mkldnn=False):
scale, use_cudnn=True):
depthwise_conv = conv_bn(
input=input,
filter_size=3,
num_filters=int(num_filters1 * scale),
stride=stride,
padding=1,
num_groups=int(num_groups * scale),
use_cudnn=use_cudnn,
# to be instrumented when depthwise conv2d op will handle use_mkldnn
use_mkldnn=False)
use_cudnn=use_cudnn)

pointwise_conv = conv_bn(
input=depthwise_conv,
filter_size=1,
num_filters=int(num_filters2 * scale),
stride=1,
padding=0,
use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
return pointwise_conv


def extra_block(input, num_filters1, num_filters2, num_groups, stride, scale,
use_cudnn=True, use_mkldnn=False):
use_cudnn=True):
# 1x1 conv
pointwise_conv = conv_bn(
input=input,
Expand All @@ -66,8 +61,7 @@ def extra_block(input, num_filters1, num_filters2, num_groups, stride, scale,
stride=1,
num_groups=int(num_groups * scale),
padding=0,
use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)

# 3x3 conv
normal_conv = conv_bn(
Expand All @@ -77,54 +71,49 @@ def extra_block(input, num_filters1, num_filters2, num_groups, stride, scale,
stride=2,
num_groups=int(num_groups * scale),
padding=1,
use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
return normal_conv


def mobile_net(num_classes, img, img_shape, scale=1.0, use_cudnn=True,
use_mkldnn=False):
def mobile_net(num_classes, img, img_shape, scale=1.0, use_cudnn=True):
# 300x300
tmp = conv_bn(img, 3, int(32 * scale), 2, 1, 3, use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
tmp = conv_bn(img, 3, int(32 * scale), 2, 1, 3, use_cudnn=use_cudnn)
# 150x150
tmp = depthwise_separable(tmp, 32, 64, 32, 1, scale, use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
tmp = depthwise_separable(tmp, 64, 128, 64, 2, scale, use_cudnn=use_cudnn,
use_mkldnn=use_mkldnn)
tmp = depthwise_separable(tmp, 32, 64, 32, 1, scale, use_cudnn=use_cudnn)
tmp = depthwise_separable(tmp, 64, 128, 64, 2, scale, use_cudnn=use_cudnn)
# 75x75
tmp = depthwise_separable(tmp, 128, 128, 128, 1, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
tmp = depthwise_separable(tmp, 128, 256, 128, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
# 38x38
tmp = depthwise_separable(tmp, 256, 256, 256, 1, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
tmp = depthwise_separable(tmp, 256, 512, 256, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)

# 19x19
for i in range(5):
tmp = depthwise_separable(tmp, 512, 512, 512, 1, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
module11 = tmp
tmp = depthwise_separable(tmp, 512, 1024, 512, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)

# 10x10
module13 = depthwise_separable(tmp, 1024, 1024, 1024, 1, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
module14 = extra_block(module13, 256, 512, 1, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
# 5x5
module15 = extra_block(module14, 128, 256, 1, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
# 3x3
module16 = extra_block(module15, 128, 256, 1, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)
# 2x2
module17 = extra_block(module16, 64, 128, 1, 2, scale,
use_cudnn=use_cudnn, use_mkldnn=use_mkldnn)
use_cudnn=use_cudnn)

mbox_locs, mbox_confs, box, box_var = fluid.layers.multi_box_head(
inputs=[module11, module13, module14, module15, module16, module17],
Expand Down
2 changes: 0 additions & 2 deletions fluid/object_detection/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
add_arg('mean_value_G', float, 127.5, "Mean value for G channel which will be subtracted.") #116.78
add_arg('mean_value_R', float, 127.5, "Mean value for R channel which will be subtracted.") #103.94
add_arg('is_toy', int, 0, "Toy for quick debug, 0 means using all data, while n means using only n sample.")
parser.add_argument('--use_mkldnn', action='store_true', help='If set, use MKL-DNN library.')
parser.add_argument('--test', action='store_true', help='If set, test the model.')
#yapf: enable

Expand Down Expand Up @@ -67,7 +66,6 @@ def train(args,
use_cudnn = True if args.use_gpu else False

locs, confs, box, box_var = mobile_net(num_classes, image, image_shape,
use_mkldnn=args.use_mkldnn,
use_cudnn=use_cudnn)
nmsed_out = fluid.layers.detection_output(
locs, confs, box, box_var, nms_threshold=args.nms_threshold)
Expand Down

0 comments on commit abb4543

Please sign in to comment.