Pytorch RuntimeError:张量(7)的扩展大小必须与非单态维度3的现有大小(128)匹配

Pytorch RuntimeError:张量(7)的扩展大小必须与非单态维度3的现有大小(128)匹配,pytorch,Pytorch,当我在代码中运行ADA时 def adaptive_instance_normalization(content_feat, style_mean, style_std): size = content_feat.size() content_mean, content_std = calc_mean_std(content_feat) normalized_feat = (content_feat - content_mean.expand( size

当我在代码中运行ADA时

def adaptive_instance_normalization(content_feat, style_mean, style_std):
    size = content_feat.size()
    content_mean, content_std = calc_mean_std(content_feat)

    normalized_feat = (content_feat - content_mean.expand(
        size)) / content_std.expand(size)
    return normalized_feat * style_std.expand(size) + style_mean.expand(size)
我犯了以下错误


RuntimeError:张量(7)的扩展大小必须与非单态维度3的现有大小(128)匹配。目标尺寸:[100128,7,7]。张量大小:[100128]

在解释问题时,你应该更精确、更具描述性。你不能指望别人能读懂你的心思,或者对你的问题了如指掌。那么首先,预期的输出应该是什么?哪一行出现故障?我猜从
展开
调用中,您希望启用广播。不幸的是,正如您从中所读到的,
expand
的工作原理与通常的广播相同,并在开头而不是结尾添加所需的额外维度

因此,您应该使用
重塑(大小[:2]+(1,1))
代替
扩展(大小)