从张量列表从3个通道转换为1个通道Pytorch张量
说我有一个list
张量,卷
,我可以迭代:
for volume in range(len(volumes)):
print (volume.shape)
torch.Size([3, 512, 512, 222])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 185])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 271])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 261])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 215])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 284])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 191])
<class 'torch.Tensor'>
如何将频道从3更改为所有卷?
谢谢
Say I have a list
of tensors, volumes
, which I can iterate over:
for volume in range(len(volumes)):
print (volume.shape)
torch.Size([3, 512, 512, 222])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 185])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 271])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 261])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 215])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 284])
<class 'torch.Tensor'>
torch.Size([3, 512, 512, 191])
<class 'torch.Tensor'>
How can I change the channel from 3 to 1, for all volumes?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要删除前两个频道,则只能保留最后一个
dim = -1
iedim = 2
:如果您想在此过程中挤压单例尺寸,然后做:
If you are looking to remove the first two channels, then you should only keep the last one
dim=-1
i.e.dim=2
:If you want to squeeze the singleton dimensions in the process then do:
如果您只想保留每个卷的第一个频道,则可以创建一个这样的新列表:
If you like just to keep the first channel for each volume, you can create a new list like that: