如何用 matplotlib 画论文中的CNN结构图

主要介绍两种用matplotlib画CNN结构图的方法代码,下一篇介绍用pydot画CNN结构图。

1.如果你需要这样的结构图,如下图:

 

代码资源可以在GitHub上找到,具体连接有很多,很容易找到,比如:https://github.com/gwding/draw_convnet,这里主要分析一下代码的原理和结构

原理:采用的是以列表的形式保存各类层的数据

如卷积层的数据表示,这种画图方式需要你计算经过每次卷积计算之后特征图大小,目前看到的代码似乎只能展示卷积层和池化层,一些其他的结构展示需要自己开发了

另外很重的一点就是,matplotlib的版本一定要在2以上3以下,2以下不能运行,3以上可以运行但是结果展示出现问题,如下图实在3.0.0版本下运行结果:

  • 6
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于使用PyQt5和Matplotlib绘制条形图,你可以按照以下步骤: 1. 安装必要的库,如pyqt5和matplotlib:可以使用pip install pyqt5和pip install matplotlib来安装。 2. 在PyQt5创建应用程序窗口,例如: ``` import sys from PyQt5.QtWidgets import QApplication, QMainWindow app = QApplication(sys.argv) window = QMainWindow() window.show() sys.exit(app.exec_()) ``` 3. 在窗口添加一个matplotlib布,例如: ``` import matplotlib.pyplot as plt from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas class MyMainWindow(QMainWindow): def __init__(self): super().__init__() ... # Create the matplotlib figure and canvas widgets self.fig = plt.Figure() self.canvas = FigureCanvas(self.fig) self.setCentralWidget(self.canvas) ... ``` 4. 绘制条形图: ``` class MyMainWindow(QMainWindow): def __init__(self): super().__init__() ... # Define data for the bar chart labels = ['Apples', 'Oranges', 'Bananas'] values = [5, 3, 4] # Create the matplotlib figure and canvas widgets self.fig = plt.Figure() self.canvas = FigureCanvas(self.fig) self.setCentralWidget(self.canvas) # Add the bar chart to the Figure ax = self.fig.add_subplot(111) ax.bar(labels, values) ... ``` 5. 最后,记得在窗口调整和显示matplotlib布: ``` class MyMainWindow(QMainWindow): def __init__(self): super().__init__() ... # Create the matplotlib figure and canvas widgets self.fig = plt.Figure() self.canvas = FigureCanvas(self.fig) self.setCentralWidget(self.canvas) # Add the bar chart to the Figure ax = self.fig.add_subplot(111) ax.bar(labels, values) # Adjust the matplotlib figure layout self.fig.tight_layout() # Show the window self.show() ``` 希望这能帮助你完成任务!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值