使用PlotNeuralNet绘制ResNet50模型
一、下载所需软件
1、下载MikTex
作用:将.tex文件转换为PDF文件
下载官网链接:Getting MiKTeX
2、下载Git
作用:将PlotNeuralNet库从GitHub上下载下来,在cmd使用命令行:
git clone https://github.com/SamuraiBUPT/PlotNeuralNet-Windows.git
就可以将PlotNeuralNet库克隆到当前文件夹中
下载官网链接:Git - Downloads
二、使用PlotNeuralNet绘制ResNet50模型
1、模型代码
import sys
sys.path.append('../')
from PlotNeuralNet.pycore.tikzeng import *
from PlotNeuralNet.pycore.blocks import *
#------------------------------------------------------------------------------
# 1) 定义一个函数,将真实 (H, C) 映射为 PlotNeuralNet 的 (height, depth, width)
#------------------------------------------------------------------------------
def dims(H, C):
# 让 height、depth 随着 H 变化,但不少于 4
h = 25 + H * 0.3
d = 25 + H * 0.3
w = 2 + C * 0.005
return (h, d, w)
# conve1
h1, d1, w1 = dims(112,64)
# maxpool1
h2, d2, w2 = dims(56, 64)
# conve2_x
h3, d3, w3 = dims(56, 64)
h4, d4, w4 = dims(56, 64)
h5, d5, w5 = dims(56, 256)
# conve3_x
h6, d6, w6 = dims(56, 128)
h7, d7, w7 = dims(28, 128)
h8, d8, w8 = dims(28, 512)
# conve4_x
h9, d9, w9 = dims(28, 256)
h10, d10, w10 = dims(14, 256)
h11, d11, w11 = dims(14, 1024)
# conve5_x
h12, d12, w12 = dims(14, 512)
h13, d13, w13 = dims(7, 512)
h14, d14, w14 = dims(7, 2048)
# avgpool
h15, d15, w15 = dims(1, 2048)
#--------------------------------------------------------------------------------------------
# 2) 构建 ResNet-50 的网络结构 (arch),并为每个阶段指