首页 > 解决方案 > 如何更改图像的通道尺寸?

问题描述

假设我有带有shape = [x,y,z,21]where的火炬张量x = batch_size, y = image_width, z= image_height。上面的张量表示具有 21 个通道的一批图像。我应该如何将其转换为size = [ x,y,z,3 ]

标签: pytorch

解决方案


[x,y,z,21] -> [x,y,z,1] -> [x,y,z,3]

对于大小为 [x,y,z,21]的分割结果预测

大小为 [x,y,z,1] 的分段类索引结果

# for pytorch, the right format for image is [batch, channels, height, width]
# however your image format [batch, height, width, channels]
result=predicts.argmax(-1)

索引结合颜色图将帮助您!查看voc 颜色图以获取详细信息


推荐阅读