我有一个具有9个波段的多光谱数据集。由于数据非常大,我将每个波段划分为256 x 256个样本。所以我对每个波段有16个这样的样本,并将它们保存在不同的文件夹中。现在,我如何连接9个波段的每个样本?
例如,我想将来自第一个频带数据的第一个样本与第二个频带的第一个样本连接起来,与第三个频带的第一个样本连接起来,以此类推,直到第九个频带。然后是第一个,第二个……第九个波段的第二个样本。因此,一直到第16个样本。
发布于 2021-02-24 19:34:43
您可以使用(torch.stack)https://pytorch.org/docs/stable/generated/torch.stack.html或(torch.cat)https://pytorch.org/docs/stable/generated/torch.cat.html来完成此操作
例如,让我们生成一些随机的256x256矩阵:
import torch
a = torch.FloatTensor(256,256).uniform_(0,1)
b = torch.FloatTensor(256,256).uniform_(0,1)c = torch.stack((a,b),axis=2) 的第二种方式:或torch.cat
c = torch.cat((a.reshape(256,256,-1),b.reshape(256,256,-1)),axis=2)主要区别在于,当torch.stack沿着新的轴连接时,torch.cat只能在现有轴上连接(这就是为什么需要使用reshape命令)。
https://stackoverflow.com/questions/66349285
复制相似问题