[fix] fix a little bug of Bit model exporting (#64)

own
kongdebug 3 years ago committed by GitHub
parent fc91d3d94a
commit 88a27ef3d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      deploy/export/README.md
  2. 8
      paddlers/custom_models/cd/bit.py

@ -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`的属性,若为负数则报错。

@ -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)

Loading…
Cancel
Save