1
私は、私を混乱させるPyTorchの例がいくつかありますが、それをクリアしたいと考えています。PyTorchブロードキャストに失敗しました。 "Rules"に続きました
最初に、PyTorchページごとに、私はこれらの例がnumpy同等物、すなわちtheseと同じように動作することを期待しています。最初の例は非常に直感的です。これらは、放送用互換性があります。
torch.Tensor([[1,2,3]])/torch.Tensor([1,2,3])
Out[5]:
1 1 1
[torch.FloatTensor of size 1x3]
torch.Tensor([[1,2,3]])/torch.Tensor([1,2,3])
Out[6]:
1 1 1
[torch.FloatTensor of size 1x3]
torch.Tensor([[[1,2,3]]])/torch.Tensor([1,2,3])
Out[7]:
(0 ,.,.) =
1 1 1
[torch.FloatTensor of size 1x1x3]
はしかし、これはnumpyの例の結果である:
torch.randn(256,256,3)/torch.Tensor([1,2,3])
Traceback (most recent call last):
File "<ipython-input-12-4c328d453e24>", line 1, in <module>
torch.randn(256,256,3)/torch.Tensor([1,2,3])
File "/home/nick/anaconda3/lib/python3.6/site-packages/torch/tensor.py", line 313, in __div__
return self.div(other)
RuntimeError: inconsistent tensor size at /opt/conda/conda-bld/pytorch_1501971235237/work/pytorch-0.1.12/torch/lib/TH/generic/THTensorMath.c:873
Here is an excerpt which says this ought to work:
Image (3d array): 256 x 256 x 3 Scale (1d array): 3 Result (3d array): 256 x 256 x 3
は、例えばこれらを取ります2つのテンソルは「broadca
- 各テンソルには少なくとも1つの次元があります。
- ディメンションサイズを反復するとき、後続ディメンションから開始して、ディメンションサイズはと等しくなければならず、そのうちの1つは1であるか、その1つは存在しません。
テンソルをnumpyに変換すると、算術演算は期待通りに機能します。
どうなりますか?私はドキュメントを誤解しましたか?そうであれば、同じ結果になる構文は何ですか?