def get_valid_ratio(self, mask):
        """Get the valid radios of feature maps of all level."""
        _, H, W = mask.shape
        valid_H = paddle.sum(mask[:, :, 0].astype('float'), 1)
        valid_W = paddle.sum(mask[:, 0, :].astype('float'), 1)
        valid_ratio_h = valid_H.astype('float') / H
        valid_ratio_w = valid_W.astype('float') / W
        valid_ratio = paddle.stack([valid_ratio_w, valid_ratio_h], -1)
        return valid_ratio
Get the valid radios of feature maps of all level.
ppdet/modeling/transformers/petr_transformer.py