【问题标题】:tensor division in pytorch. Assertion errorpytorch 中的张量分割。断言错误
【发布时间】:2017-06-13 20:08:58
【问题描述】:

这是一个 pytorch 初学者问题。在 pytorch 中,我试图用两个大小为 [5,5,3] 的张量进行元素除法。在 numpy 中,使用 np.divide() 可以正常工作,但不知何故我在这里遇到错误。我正在为 Python 3.5 使用 PyTorch 版本 0.1.12。

c = [torch.DoubleTensor 大小为 5x5x3]

input_patch = [torch.FloatTensor 大小为 5x5x3]

input_patch 是一个 torch.autograd 变量的切片,c 是通过 c = torch.from_numpy(self.patch_filt[:, :, :, 0]).float() 生成的

做的时候:

torch.div(input_patch, c)

我收到了这个我不明白的错误。

line 317, in div
assert not torch.is_tensor(other)
AssertionError

这是否意味着变量 c 不应该是 torch_tensor?在将 c 转换为 FloatTensor 之后仍然会给出相同的错误。

谢谢!

【问题讨论】:

  • 嗨!我不能像那样重现你的错误。你使用的是什么版本的 Pytorch,你是如何生成 input_patch 和 c 的?确保 c 和 input_patch 具有相同的 dtype 并且都是 torch.autograd.Variable 或两者都是公共张量。我怀疑您可能已将一个变量设为变量,而另一个则没有?据我所知,您的错误中的那一行只是区分提供了一个张量作为除数还是一个常数。两者皆有可能。

标签: division torch pytorch


【解决方案1】:

input_patch是一个torch.autograd变量的切片,c是做的

c = torch.from_numpy(self.patch_filt[:, :, :, 0]).float() 

无论如何,mexmex,感谢您的评论,我通过将 c 定义为

解决了这个问题
Variable(torch.from_numpy(self.patch_filt[:, :, :, 0])).float()

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    • 2020-01-21
    • 2021-10-11
    • 2021-12-16
    相关资源
    最近更新 更多