bs = 4
kernel_dim=3
for i in range(all_prototypes.size(0)):
prototypes = all_prototypes[i, ...].permute(1, 0, 2).reshape(
bs, num_objects, kernel_dim, kernel_dim, -1
).permute(0, 1, 4, 2, 3).flatten(0, 2)[:, None, ...]
'''
in(type shape):
all_prototypes size: torch.Size([3, 27, 4, 256])
deal(function meaning):
all_prototypes[i, ...] [27, 4, 256] 选择 all_prototypes 的第 i 个元素
.permute(1, 0, 2) → [4, 27, 256] 重新排列维度,将第 1 维和第 0 维交换
.reshape → [4, 3, 3, 3, 256]
.permute(0, 1, 4, 2, 3) → [4, 3, 256, 3, 3]
.flatten(0, 2) → [3072, 3, 3] 第 0 维到第 2 维
[:, None, ...] → [3072, 1,3, 3] 在第 1 维插入一个新的维度
out(type shape):
prototypes.shape = torch.Size([3072, 1, 3, 3])
'''
print(prototypes.shape)
permute
reshape
flatten