【问题标题】:Error for 'int' object has no attribute 'size'“int”对象的错误没有属性“size”
【发布时间】:2022-07-22 18:22:21
【问题描述】:

一个函数接收一个5D张量,如下:

class PatchEmbed(nn.Module):
""" Image to Patch Embedding
"""
def __init__(self, img_size=224, patch_size=16, in_chans=3, embed_dim=768):
    super().__init__()
    img_size = to_2tuple(img_size)
    patch_size = to_2tuple(patch_size)
    num_patches = (img_size[1] // patch_size[1]) * (img_size[0] // patch_size[0])
    self.img_size = img_size
    self.patch_size = patch_size
    self.num_patches = num_patches

    self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)

def forward(self, x):
    B, C, T, H, W = x.shape
    x = rearrange(x, 'b c t h w -> (b t) c h w')
    x = self.proj(x)
    W = x.size(-1)
    x = x.flatten(2).transpose(1, 2)
    return x, T, W

def forward_features(self, x):
    B = x.shape[0]
    x, T, W = self.patch_embed(x)  # self.patch_embed is an object created based on PatchEmbed

当我在另一个转发函数中调用上述类时,我遇到以下错误:

'int' 对象没有属性 'size'

如何消除此错误?

【问题讨论】:

    标签: python error-handling pytorch integer


    【解决方案1】:

    我认为您为此函数提供了错误的输入

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-20
      • 2014-03-30
      • 2020-05-25
      • 2016-07-31
      • 2019-11-18
      • 2018-12-02
      • 2023-03-19
      相关资源
      最近更新 更多