mirror of
https://github.com/PaddlePaddle/PaddleClas.git
synced 2025-06-03 21:55:06 +08:00
fix pred (#450)
* fix pred * fix resnest * fix hrnet se * fix se for export
This commit is contained in:
parent
0df5ba63df
commit
1ecf8334ff
@ -83,13 +83,12 @@ class SEBlock(nn.Layer):
|
|||||||
|
|
||||||
def forward(self, inputs):
|
def forward(self, inputs):
|
||||||
pool = self.pool2d_gap(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 = self.squeeze(pool)
|
||||||
squeeze = F.relu(squeeze)
|
squeeze = F.relu(squeeze)
|
||||||
excitation = self.excitation(squeeze)
|
excitation = self.excitation(squeeze)
|
||||||
excitation = paddle.clip(x=excitation, min=0, max=1)
|
excitation = paddle.clip(x=excitation, min=0, max=1)
|
||||||
excitation = paddle.reshape(
|
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
|
||||||
excitation, shape=[-1, self._num_channels, 1, 1])
|
|
||||||
out = inputs * excitation
|
out = inputs * excitation
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -322,8 +322,7 @@ class SELayer(nn.Layer):
|
|||||||
self.squeeze = Linear(
|
self.squeeze = Linear(
|
||||||
num_channels,
|
num_channels,
|
||||||
med_ch,
|
med_ch,
|
||||||
act="relu",
|
weight_attr=ParamAttr(
|
||||||
param_attr=ParamAttr(
|
|
||||||
initializer=Uniform(-stdv, stdv), name=name + "_sqz_weights"),
|
initializer=Uniform(-stdv, stdv), name=name + "_sqz_weights"),
|
||||||
bias_attr=ParamAttr(name=name + '_sqz_offset'))
|
bias_attr=ParamAttr(name=name + '_sqz_offset'))
|
||||||
|
|
||||||
@ -331,18 +330,18 @@ class SELayer(nn.Layer):
|
|||||||
self.excitation = Linear(
|
self.excitation = Linear(
|
||||||
med_ch,
|
med_ch,
|
||||||
num_filters,
|
num_filters,
|
||||||
act="sigmoid",
|
weight_attr=ParamAttr(
|
||||||
param_attr=ParamAttr(
|
|
||||||
initializer=Uniform(-stdv, stdv), name=name + "_exc_weights"),
|
initializer=Uniform(-stdv, stdv), name=name + "_exc_weights"),
|
||||||
bias_attr=ParamAttr(name=name + '_exc_offset'))
|
bias_attr=ParamAttr(name=name + '_exc_offset'))
|
||||||
|
|
||||||
def forward(self, input):
|
def forward(self, input):
|
||||||
pool = self.pool2d_gap(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.squeeze(pool)
|
||||||
|
squeeze = F.relu(squeeze)
|
||||||
excitation = self.excitation(squeeze)
|
excitation = self.excitation(squeeze)
|
||||||
excitation = paddle.reshape(
|
excitation = F.sigmoid(excitation)
|
||||||
excitation, shape=[-1, self._num_channels, 1, 1])
|
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
|
||||||
out = input * excitation
|
out = input * excitation
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -85,7 +85,8 @@ class rSoftmax(nn.Layer):
|
|||||||
x = paddle.reshape(
|
x = paddle.reshape(
|
||||||
x=x,
|
x=x,
|
||||||
shape=[
|
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 = paddle.transpose(x=x, perm=[0, 2, 1, 3])
|
||||||
x = nn.functional.softmax(x, axis=1)
|
x = nn.functional.softmax(x, axis=1)
|
||||||
@ -164,7 +165,7 @@ class SplatConv(nn.Layer):
|
|||||||
|
|
||||||
atten = self.conv3(gap)
|
atten = self.conv3(gap)
|
||||||
atten = self.rsoftmax(atten)
|
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:
|
if self.radix > 1:
|
||||||
attens = paddle.split(atten, num_or_sections=self.radix, axis=1)
|
attens = paddle.split(atten, num_or_sections=self.radix, axis=1)
|
||||||
|
@ -223,13 +223,12 @@ class SELayer(nn.Layer):
|
|||||||
|
|
||||||
def forward(self, input):
|
def forward(self, input):
|
||||||
pool = self.pool2d_gap(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.squeeze(pool)
|
||||||
squeeze = F.relu(squeeze)
|
squeeze = F.relu(squeeze)
|
||||||
excitation = self.excitation(squeeze)
|
excitation = self.excitation(squeeze)
|
||||||
excitation = F.sigmoid(excitation)
|
excitation = F.sigmoid(excitation)
|
||||||
excitation = paddle.reshape(
|
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
|
||||||
excitation, shape=[-1, self._num_channels, 1, 1])
|
|
||||||
out = input * excitation
|
out = input * excitation
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -157,13 +157,12 @@ class SELayer(nn.Layer):
|
|||||||
|
|
||||||
def forward(self, input):
|
def forward(self, input):
|
||||||
pool = self.pool2d_gap(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.squeeze(pool)
|
||||||
squeeze = self.relu(squeeze)
|
squeeze = self.relu(squeeze)
|
||||||
excitation = self.excitation(squeeze)
|
excitation = self.excitation(squeeze)
|
||||||
excitation = self.sigmoid(excitation)
|
excitation = self.sigmoid(excitation)
|
||||||
excitation = paddle.reshape(
|
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
|
||||||
excitation, shape=[-1, self._num_channels, 1, 1])
|
|
||||||
out = input * excitation
|
out = input * excitation
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -164,13 +164,12 @@ class SELayer(nn.Layer):
|
|||||||
|
|
||||||
def forward(self, input):
|
def forward(self, input):
|
||||||
pool = self.pool2d_gap(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.squeeze(pool)
|
||||||
squeeze = self.relu(squeeze)
|
squeeze = self.relu(squeeze)
|
||||||
excitation = self.excitation(squeeze)
|
excitation = self.excitation(squeeze)
|
||||||
excitation = self.sigmoid(excitation)
|
excitation = self.sigmoid(excitation)
|
||||||
excitation = paddle.reshape(
|
excitation = paddle.unsqueeze(excitation, axis=[2, 3])
|
||||||
excitation, shape=[-1, self._num_channels, 1, 1])
|
|
||||||
out = input * excitation
|
out = input * excitation
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -90,7 +90,11 @@ def main(args):
|
|||||||
predictor.run()
|
predictor.run()
|
||||||
|
|
||||||
output = output_tensor.copy_to_cpu()
|
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:
|
else:
|
||||||
for i in range(0, test_num + 10):
|
for i in range(0, test_num + 10):
|
||||||
inputs = np.random.rand(args.batch_size, 3, 224,
|
inputs = np.random.rand(args.batch_size, 3, 224,
|
||||||
@ -115,7 +119,4 @@ def main(args):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = utils.parse_args()
|
args = utils.parse_args()
|
||||||
classes, scores = main(args)
|
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]))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user