コーヒー買ってきて☕
*メモ:
Un flatten() は、以下に示すように、0 個以上の要素の 1D または複数の D テンソルに 0 個以上の次元を追加し、0 個以上の要素の 1D またはそれ以上の D テンソルを取得できます。
*メモ:
import torch from torch import nn unflatten = nn.Unflatten() unflatten # Unflatten(dim=0, unflattened_size=(6,)) unflatten.dim # 0 unflatten.unflattened_size # (6,) my_tensor = torch.tensor([7, 1, -8, 3, -6, 0]) unflatten = nn.Unflatten(dim=0, unflattened_size=(6,)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1,)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(6,)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1,)) unflatten(input=my_tensor) # tensor([7, 1, -8, 3, -6, 0]) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 6)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1, 6)) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 6)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1, 6)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, -1)) unflatten(input=my_tensor) # tensor([[7, 1, -8, 3, -6, 0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2, 3)) unflatten = nn.Unflatten(dim=0, unflattened_size=(2, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(2, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(2, -1)) unflatten(input=my_tensor) # tensor([[7, 1, -8], [3, -6, 0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(3, 2)) unflatten = nn.Unflatten(dim=0, unflattened_size=(3, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(3, 2)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(3, -1)) unflatten(input=my_tensor) # tensor([[7, 1], [-8, 3], [-6, 0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(6, 1)) unflatten = nn.Unflatten(dim=0, unflattened_size=(6, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(6, 1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(6, -1)) unflatten(input=my_tensor) # tensor([[7], [1], [-8], [3], [-6], [0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 2, 3)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1, 2, 3)) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, -1, 3)) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 2, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 2, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1, 2, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, -1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 2, -1)) unflatten(input=my_tensor) # tensor([[[7, 1, -8], [3, -6, 0]]]) etc my_tensor = torch.tensor([[7, 1, -8], [3, -6, 0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2,)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1,)) unflatten = nn.Unflatten(dim=1, unflattened_size=(3,)) unflatten = nn.Unflatten(dim=1, unflattened_size=(-1,)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(3,)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1,)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(2,)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(-1,)) unflatten(input=my_tensor) # tensor([[7, 1, -8], [3, -6, 0]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 2)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1, 2)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(1, 2)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(-1, 2)) unflatten(input=my_tensor) # tensor([[[7, 1, -8], [3, -6, 0]]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2, 1)) unflatten = nn.Unflatten(dim=0, unflattened_size=(2, -1)) unflatten = nn.Unflatten(dim=1, unflattened_size=(1, 3)) unflatten = nn.Unflatten(dim=1, unflattened_size=(-1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1, 3)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(2, 1)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(2, -1)) unflatten(input=my_tensor) # tensor([[[7, 1, -8]], [[3, -6, 0]]]) unflatten = nn.Unflatten(dim=1, unflattened_size=(3, 1)) unflatten = nn.Unflatten(dim=1, unflattened_size=(3, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(3, 1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(3, -1)) unflatten(input=my_tensor) # tensor([[[7], [1], [-8]], [[3], [-6], [0]]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 1, 2)) unflatten = nn.Unflatten(dim=0, unflattened_size=(-1, 1, 2)) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, -1, 2)) unflatten = nn.Unflatten(dim=0, unflattened_size=(1, 1, -1)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(1, 1, 2)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(-1, 1, 2)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(1, -1, 2)) unflatten = nn.Unflatten(dim=-2, unflattened_size=(1, 1, -1)) unflatten(input=my_tensor) # tensor([[[[7, 1, -8], [3, -6, 0]]]]) unflatten = nn.Unflatten(dim=1, unflattened_size=(1, 1, 3)) unflatten = nn.Unflatten(dim=1, unflattened_size=(-1, 1, 3)) unflatten = nn.Unflatten(dim=1, unflattened_size=(1, -1, 3)) unflatten = nn.Unflatten(dim=1, unflattened_size=(1, 1, -1)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(-1, 1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, -1, 3)) unflatten = nn.Unflatten(dim=-1, unflattened_size=(1, 1, -1)) unflatten(input=my_tensor) # tensor([[[[7, 1, -8]]], [[[3, -6, 0]]]]) my_tensor = torch.tensor([[7., 1., -8.], [3., -6., 0.]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2,)) unflatten(input=my_tensor) # tensor([[7., 1., -8.], [3., -6., 0.]]) my_tensor = torch.tensor([[7.+0.j, 1.+0.j, -8.+0.j], [3.+0.j, -6.+0.j, 0.+0.j]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2,)) unflatten(input=my_tensor) # tensor([[7.+0.j, 1.+0.j, -8.+0.j], # [3.+0.j, -6.+0.j, 0.+0.j]]) my_tensor = torch.tensor([[True, False, True], [False, True, False]]) unflatten = nn.Unflatten(dim=0, unflattened_size=(2,)) unflatten(input=my_tensor) # tensor([[True, False, True], [False, True, False]])
以上がPyTorch で非平坦化の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。