From 88a27ef3d515dd311f604d0292bed6be1f77f1d8 Mon Sep 17 00:00:00 2001 From: kongdebug <52785738+kongdebug@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:10:11 +0800 Subject: [PATCH] [fix] fix a little bug of Bit model exporting (#64) --- deploy/export/README.md | 1 + paddlers/custom_models/cd/bit.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/deploy/export/README.md b/deploy/export/README.md index 6cf86df..ae8e7d3 100644 --- a/deploy/export/README.md +++ b/deploy/export/README.md @@ -60,3 +60,4 @@ python deploy/export_model.py --model_dir=./output/deeplabv3p/best_model/ --save - 对于检测模型中的YOLO/PPYOLO系列模型,请保证输入影像的`w`和`h`有相同取值、且均为32的倍数;指定`--fixed_input_shape`时,R-CNN模型的`w`和`h`也均需为32的倍数。 - 指定`[w,h]`时,请使用半角逗号(`,`)分隔`w`和`h`,二者之间不允许存在空格等其它字符。 - 将`w`和`h`设得越大,则模型在推理过程中的耗时和内存/显存占用越高。不过,如果`w`和`h`过小,则可能对模型的精度存在较大负面影响。 +- 对于变化检测模型BIT,请保证指定`--fixed_input_shape`,并且数值不包含负数,因为BIT用到空间注意力,需要从tensor中获取`b,c,h,w`的属性,若为负数则报错。 diff --git a/paddlers/custom_models/cd/bit.py b/paddlers/custom_models/cd/bit.py index 133fd76..af9f2f9 100644 --- a/paddlers/custom_models/cd/bit.py +++ b/paddlers/custom_models/cd/bit.py @@ -129,7 +129,7 @@ class BIT(nn.Layer): Conv3x3(EBD_DIM, num_classes)) def _get_semantic_tokens(self, x): - b, c = paddle.shape(x)[:2] + b, c = x.shape[:2] att_map = self.conv_att(x) att_map = att_map.reshape((b, self.token_len, 1, -1)) att_map = F.softmax(att_map, axis=-1) @@ -154,7 +154,7 @@ class BIT(nn.Layer): return x def decode(self, x, m): - b, c, h, w = paddle.shape(x) + b, c, h, w = x.shape x = x.transpose((0, 2, 3, 1)).flatten(1, 2) x = self.decoder(x, m) x = x.transpose((0, 2, 1)).reshape((b, c, h, w)) @@ -172,7 +172,7 @@ class BIT(nn.Layer): else: token1 = self._get_reshaped_tokens(x1) token2 = self._get_reshaped_tokens(x2) - + # Transformer encoder forward token = paddle.concat([token1, token2], axis=1) token = self.encode(token) @@ -265,7 +265,7 @@ class CrossAttention(nn.Layer): nn.Linear(inner_dim, dim), nn.Dropout(dropout_rate)) def forward(self, x, ref): - b, n = paddle.shape(x)[:2] + b, n = x.shape[:2] h = self.n_heads q = self.fc_q(x)