HanyangZhong / FENet

MIT License
4 stars 0 forks source link

SwinTransformer F.pad op export #3

Open adherent-ls opened 3 weeks ago

adherent-ls commented 3 weeks ago

SwinTransformer 作为backbone , , H, W = x.shape if W % self.patch_size[1] != 0: x = F.pad(x, [0, self.patch_size[1] - W % self.patch_size[1], 0, 0])


        if H % self.patch_size[0] != 0:
            x = F.pad(x, [0, 0, 0, self.patch_size[0] - H % self.patch_size[0]])
Invoked with: <paddle.fluid.libpaddle.OpDesc object at 0x7f3f980379b0>, 'paddings', [0, var tmp_6 : LOD_TENSOR.shape(1,).dtype(int32).stop_gradient(False), 0, 0, 0, 0]
![image](https://github.com/HanyangZhong/FENet/assets/96528773/b88d0880-e3a7-4591-b11e-88a2a0d8533d)

以及
        # calculate attention mask for SW-MSA
        Hp = int(np.ceil(H / self.window_size)) * self.window_size
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        Wp = int(np.ceil(W / self.window_size)) * self.window_size
        img_mask = paddle.zeros((1, Hp, Wp, 1))  # 1 Hp Wp 1

    TypeError: must be real number, not Variable
![image](https://github.com/HanyangZhong/FENet/assets/96528773/12462add-d552-4515-96b1-107aa5203600)

paddle版本:paddlepaddle-gpu==2.5.2.post120
HanyangZhong commented 3 weeks ago

Although Swin transformer is not used in the code, there are some suggestions that may be worth trying. The errors you're encountering seem to be related to data types being incompatible with the expected input types for certain PaddlePaddle functions.

  1. Error with calculating the attention mask for SW-MSA Diagnosis: This error indicates that one of the variables (H or self.window_size) is a PaddlePaddle Variable, and np.ceil() cannot handle PaddlePaddle Variable types. You need to extract the numerical value from the Variable. Solution: Convert the PaddlePaddle Variable to a numpy array and then to an integer
  2. Error with SwinTransformer padding Diagnosis: The F.pad function in PaddlePaddle expects the padding dimensions as a list of integers. If any of these values are PaddlePaddle Variables, this error will occur. Solution: Ensure all padding values are integers