当我运行AdaIN代码
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)相匹配。目标大小:[100、128、7、7]。张量大小:[100,128]
答案 0 :(得分:0)
在解释问题时,您应该更加准确和更具描述性。您不能期望别人能读懂您的想法或熟悉您的确切问题。那么首先,预期的输出应该是什么,哪条线出现故障?我想从expand
呼叫中您想启用广播。不幸的是,正如您可以从official documentation中读取的内容一样,expand
的工作原理与通常的广播相同,并且在开头而不是结尾处添加了所需的额外尺寸。
因此,您应该使用reshape(size[:2] + (1, 1))
代替expand(size)
。