From 3a09f50afc6b4b58ce332c72bb1842d7931cd637 Mon Sep 17 00:00:00 2001 From: Guoxia Wang Date: Fri, 19 Nov 2021 17:35:48 +0800 Subject: [PATCH] Add NHWC TODO (#96) * Add TODO LIST --- scripts/perf_runner.sh | 4 +++- static/backbones/iresnet.py | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/perf_runner.sh b/scripts/perf_runner.sh index 002a5e703f982..267c8d3cb7982 100644 --- a/scripts/perf_runner.sh +++ b/scripts/perf_runner.sh @@ -32,7 +32,9 @@ fi if [ $dtype = "fp16" ]; then fp16=True - data_format=NHWC + data_format=NCHW +# TODO(GuoxiaWang): remove NCHW when PRelu support NHWC +# data_format=NHWC else fp16=False data_format=NCHW diff --git a/static/backbones/iresnet.py b/static/backbones/iresnet.py index 6de8bedc747ca..7396c52e708ed 100644 --- a/static/backbones/iresnet.py +++ b/static/backbones/iresnet.py @@ -65,7 +65,7 @@ def __init__(self, units = [3, 8, 36, 3] filter_list = [64, 64, 128, 256, 512] num_stages = 4 - + if data_format == 'NHWC': image = paddle.tensor.transpose(image, [0, 2, 3, 1]) @@ -86,6 +86,7 @@ def __init__(self, momentum=0.9, data_layout=data_format, is_test=False if is_train else True) + # TODO(GuoxiaWang): add data_format attr input_blob = paddle.static.nn.prelu( input_blob, mode="channel", @@ -95,18 +96,20 @@ def __init__(self, for i in range(num_stages): for j in range(units[i]): input_blob = self.residual_unit_v3( - input_blob, - filter_list[i + 1], - 3, - 2 if j == 0 else 1, - 1, - is_train, data_format) + input_blob, filter_list[i + 1], 3, 2 + if j == 0 else 1, 1, is_train, data_format) fc1 = self.get_fc1(input_blob, is_train, dropout, data_format) self.output_dict['feature'] = fc1 - def residual_unit_v3(self, in_data, num_filter, filter_size, stride, pad, - is_train, data_format="NCHW"): + def residual_unit_v3(self, + in_data, + num_filter, + filter_size, + stride, + pad, + is_train, + data_format="NCHW"): bn1 = paddle.static.nn.batch_norm( input=in_data, @@ -132,7 +135,7 @@ def residual_unit_v3(self, in_data, num_filter, filter_size, stride, pad, momentum=0.9, data_layout=data_format, is_test=False if is_train else True) - # prelu = paddle.nn.functional.relu6(bn2) + # TODO(GuoxiaWang): add data_format attr prelu = paddle.static.nn.prelu( bn2, mode="channel",