yolov5里AttributeError: 'Namespace' object has no attribute 'plots'

AttributeError: 'Namespace' object has no attribute 'plots'

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/7805818
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:YOLOv3保存检测视频:AttributeError: 'NoneType' object has no attribute '__array_interface__'
  • 除此之外, 这篇博客: 【YOLOV5-5.x 源码解读】plots.py中的 10、feature_visualization 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    \qquad这个函数是用来可视化feature map的,而且可以实现可视化网络中任意一层的feature map。

    函数代码:

    def feature_visualization(x, module_type, stage, n=64):
        """用在yolo.py的Model类中的forward_once函数中 自行选择任意层进行可视化该层feature map
        可视化feature map(模型任意层都可以用)
        :params x: Features map   [bs, channels, height, width]
        :params module_type: Module type
        :params stage: Module stage within model
        :params n: Maximum number of feature maps to plot
        """
        batch, channels, height, width = x.shape  # batch, channels, height, width
        if height > 1 and width > 1:
            project, name = 'runs/features', 'exp'
            save_dir = increment_path(Path(project) / name)  # increment run
            save_dir.mkdir(parents=True, exist_ok=True)  # make save dir
    
            plt.figure(tight_layout=True)
            # torch.chunk: 与torch.cat()原理相反 将tensor x按dim(行或列)分割成channels个tensor块, 返回的是一个元组
            # 将第2个维度(channels)将x分成channels份  每张图有三个block batch张图  blocks=len(blocks)=3*batch
            blocks = torch.chunk(x, channels, dim=1)
            n = min(n, len(blocks))  # 总共可视化的feature map数量
            for i in range(n):
                feature = transforms.ToPILImage()(blocks[i].squeeze())  # tensor -> PIL Image
                ax = plt.subplot(int(math.sqrt(n)), int(math.sqrt(n)), i + 1)  # 根号n行根号n列  当前属于第i+1张子图
                ax.axis('off')
                plt.imshow(feature)  # cmap='gray' 可视化当前feature map
    
            f = f"stage_{stage}_{module_type.split('.')[-1]}_features.png"
            print(f'Saving {save_dir / f}...')
            plt.savefig(save_dir / f, dpi=300)
    

    通常这个函数是把他放在yolo.py的Model类中的forward_once函数中:
    在这里插入图片描述
    自己可以在if中选择要查看的任意一层feature map。

    原图:
    在这里插入图片描述
    执行效果:
    在这里插入图片描述


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

你好,请问这个问题你已经解决了吗?能请问下是怎么解决的吗?