pytorch使用tensorboardX做可视化(三)卷积核可视化 + 总结

卷积核可视化意思核feature map可视化是一样的

把卷积核的权重变成图像输出来

#卷积核可视化
def show_kernal(model):
    # 可视化卷积核
    for name, param in model.named_parameters():
        if 'conv' in name and 'weight' in name:
            in_channels = param.size()[1]
            out_channels = param.size()[0]  # 输出通道,表示卷积核的个数

            k_w, k_h = param.size()[3], param.size()[2]  # 卷积核的尺寸
            kernel_all = param.view(-1, 1, k_w, k_h)  # 每个通道的卷积核
            kernel_grid = vutils.make_grid(kernel_all, normalize=True, scale_each=True, nrow=in_channels)
            writer.add_image(f'{name}_all', kernel_grid, global_step=0)

结果为:

pytorch使用tensorboardX做可视化(三)卷积核可视化 + 总结_第1张图片

pytorch使用tensorboardX做可视化(三)卷积核可视化 + 总结_第2张图片

总结:

from tensorboardX import SummaryWriter 导入
writer = SummaryWriter('./Result')   # 数据存放
writer.add_histogram(name, param, 0) # 直方图
writer.add_scalar('loss', loss[i], i)  # loss
writer.add_image(f'{name}_all', kernel_grid, global_step=0) #加图

 

 

你可能感兴趣的:(pytorch,可视化,学习,可视化,pytorch,tensorboard)