三维自动编码器的MSE损耗低,但重建图像却很吵

问题描述

我正在重建3维尺寸的时空长方体,宽度和高度等于32,深度等于20。我在自动编码器体系结构中使用了Conv3d层。

所以我的输入形状是32x32x20,我将其缩小为2048,然后将其重构回32x32x20。

即使重建只是噪声,模型的MSE损失仍具有很好的收敛性。

我的编码器体系结构:

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv3d-1       [-1,64,20,32,32]           5,248
         AvgPool3d-2       [-1,10,16,16]               0
            Conv3d-3      [-1,128,16]         221,312
         AvgPool3d-4         [-1,5,8,8]               0
            Conv3d-5         [-1,256,8]         884,992
         AvgPool3d-6         [-1,2,4,4]               0
            Conv3d-7         [-1,512,4]       3,539,456
         AvgPool3d-8         [-1,1,2]               0

我的解码器体系结构:

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
       Interpolate-1         [-1,4]               0
            Conv3d-2         [-1,200
       Interpolate-3         [-1,8]               0
            Conv3d-4        [-1,864
       Interpolate-5      [-1,16]               0
            Conv3d-6       [-1,248
       Interpolate-7       [-1,40,32]               0
            Conv3d-8        [-1,3,187
            Conv3d-9        [-1,32]             246

我的重建代码:

from mpl_toolkits.axes_grid1 import ImageGrid
# recon_batch is the last batch of the autoencoder output.
# recon_batch has shape (batch_size,32)
recon_batch = recon_batch.permute(0,1) # new shape = (batch_size,3)
recon_batch = recon_batch.detach().cpu()
recon_batch_numpy = recon_batch.detach().cpu().numpy()
for k in range(3):  # K=3 because I want to display 3 frames
    fig = plt.figure(figsize=(4.,4.))
    grid = ImageGrid(fig,111,nrows_ncols=(4,4),axes_pad=0.1,)
    images = [recon_batch_numpy[i][k] for i in range(16)]  # 16 because Original Image is of size (128x128),when I make 32x32 patches,16 sub frames are formed
    for ax,im in zip(grid,images):
        ax.imshow((rgb2gray(im) * 255).astype(np.uint8),cmap='gray',vmin=0,vmax=255)
    name = str(num_epochs) + 'th_figure_' + str(k)
    plt.savefig(name)

原始输入图像(实际长方体尺寸为32x32x20,通过对每个此类长方体的深度0取第一帧来重建图像)

original input image

重建的输出图像:

reconstructed image

如果需要,我还可以添加一个损失图,损失开始于10,000左右,收敛于200左右。

解决方法

我不确定您的损失期限或培训过程是什么样子,但是您可能需要考虑以下几点:

  1. 因为200可能是一个相对较大的MSE,所以需要训练更多的时间(您可能会陷入局部最小值,在这种情况下,较高的梯度或不同的优化器/优化器超参数可能会有所帮助)

  2. 通过使用其他损失或在损失中增加其他条款来更改您的损失期限;例如KL散度

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...