未验证 提交 1ecf8334 编写于 作者: L littletomatodonkey 提交者: GitHub

fix pred (#450)

* fix pred

* fix resnest

* fix hrnet se

* fix se for export
上级 0df5ba63
......@@ -83,13 +83,12 @@ class SEBlock(nn.Layer):
def forward(self, inputs):
pool = self.pool2d_gap(inputs)
pool = paddle.reshape(pool, shape=[-1, self._num_channels])
pool = paddle.squeeze(pool, axis=[2, 3])
squeeze = self.squeeze(pool)
squeeze = F.relu(squeeze)
excitation = self.excitation(squeeze)
excitation = paddle.clip(x=excitation, min=0, max=1)
excitation = paddle.reshape(
excitation, shape=[-1, self._num_channels, 1, 1])
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
out = inputs * excitation
return out
......
......@@ -322,8 +322,7 @@ class SELayer(nn.Layer):
self.squeeze = Linear(
num_channels,
med_ch,
act="relu",
param_attr=ParamAttr(
weight_attr=ParamAttr(
initializer=Uniform(-stdv, stdv), name=name + "_sqz_weights"),
bias_attr=ParamAttr(name=name + '_sqz_offset'))
......@@ -331,18 +330,18 @@ class SELayer(nn.Layer):
self.excitation = Linear(
med_ch,
num_filters,
act="sigmoid",
param_attr=ParamAttr(
weight_attr=ParamAttr(
initializer=Uniform(-stdv, stdv), name=name + "_exc_weights"),
bias_attr=ParamAttr(name=name + '_exc_offset'))
def forward(self, input):
pool = self.pool2d_gap(input)
pool = paddle.reshape(pool, shape=[-1, self._num_channels])
pool = paddle.squeeze(pool, axis=[2, 3])
squeeze = self.squeeze(pool)
squeeze = F.relu(squeeze)
excitation = self.excitation(squeeze)
excitation = paddle.reshape(
excitation, shape=[-1, self._num_channels, 1, 1])
excitation = F.sigmoid(excitation)
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
out = input * excitation
return out
......
......@@ -85,7 +85,8 @@ class rSoftmax(nn.Layer):
x = paddle.reshape(
x=x,
shape=[
batch, cardinality, radix, int(r * h * w / cardinality / radix)
batch, cardinality, radix,
int(r * h * w / cardinality / radix)
])
x = paddle.transpose(x=x, perm=[0, 2, 1, 3])
x = nn.functional.softmax(x, axis=1)
......@@ -164,7 +165,7 @@ class SplatConv(nn.Layer):
atten = self.conv3(gap)
atten = self.rsoftmax(atten)
atten = paddle.reshape(x=atten, shape=[-1, atten.shape[1], 1, 1])
atten = paddle.unsqueeze(x=atten, axis=[2, 3])
if self.radix > 1:
attens = paddle.split(atten, num_or_sections=self.radix, axis=1)
......
......@@ -223,13 +223,12 @@ class SELayer(nn.Layer):
def forward(self, input):
pool = self.pool2d_gap(input)
pool = paddle.reshape(pool, shape=[-1, self._num_channels])
pool = paddle.squeeze(pool, axis=[2, 3])
squeeze = self.squeeze(pool)
squeeze = F.relu(squeeze)
excitation = self.excitation(squeeze)
excitation = F.sigmoid(excitation)
excitation = paddle.reshape(
excitation, shape=[-1, self._num_channels, 1, 1])
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
out = input * excitation
return out
......
......@@ -157,13 +157,12 @@ class SELayer(nn.Layer):
def forward(self, input):
pool = self.pool2d_gap(input)
pool = paddle.reshape(pool, shape=[-1, self._num_channels])
pool = paddle.squeeze(pool, axis=[2, 3])
squeeze = self.squeeze(pool)
squeeze = self.relu(squeeze)
excitation = self.excitation(squeeze)
excitation = self.sigmoid(excitation)
excitation = paddle.reshape(
excitation, shape=[-1, self._num_channels, 1, 1])
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
out = input * excitation
return out
......
......@@ -164,13 +164,12 @@ class SELayer(nn.Layer):
def forward(self, input):
pool = self.pool2d_gap(input)
pool = paddle.reshape(pool, shape=[-1, self._num_channels])
pool = paddle.squeeze(pool, axis=[2, 3])
squeeze = self.squeeze(pool)
squeeze = self.relu(squeeze)
excitation = self.excitation(squeeze)
excitation = self.sigmoid(excitation)
excitation = paddle.reshape(
excitation, shape=[-1, self._num_channels, 1, 1])
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
out = input * excitation
return out
......
......@@ -90,7 +90,11 @@ def main(args):
predictor.run()
output = output_tensor.copy_to_cpu()
return utils.postprocess(output, args)
classes, scores = utils.postprocess(output, args)
print("Current image file: {}".format(args.image_file))
print("\ttop-1 class: {0}".format(classes[0]))
print("\ttop-1 score: {0}".format(scores[0]))
else:
for i in range(0, test_num + 10):
inputs = np.random.rand(args.batch_size, 3, 224,
......@@ -115,7 +119,4 @@ def main(args):
if __name__ == "__main__":
args = utils.parse_args()
classes, scores = main(args)
print("Current image file: {}".format(args.image_file))
print("\ttop-1 class: {0}".format(classes[0]))
print("\ttop-1 score: {0}".format(scores[0]))
main(args)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册