【发布时间】:2021-07-01 10:54:42
【问题描述】:
我为边缘检测任务制作了一个 CNN 模型。它工作得很好,我可以通过特征图看到很好的结果。问题是我在每个卷积层中使用 4 个过滤器,因此输出将是具有 4 个通道的图像,但我需要将图像保存为 3 个通道以便稍后使用,这里是代码示例我用过:
#Feed image to model:
output = model(img) #input size (1, 3, 224, 224)
#convert output tensor to numpy
fimg = output.detach().cpu().numpy()
#get rid of the single batch dimension
f2img = fimg.squeeze(0)
#swap axes to (13, 13, 4)
f2img = fimg.transpose(1, 2, 0)
它会被保存为 (13,13,4) 但我需要它作为 (13, 13, 3)。如果有人可以提供帮助,将不胜感激。
【问题讨论】:
-
对这个任务使用自动编码器或者改变模型输出3个通道或者这个分割成
(13, 13, 1)的4个图像。 -
您可以将其保存为具有 4 个通道的
RGBA图像。
标签: image-processing pytorch tensor