tensorflow 2.0使用plot_model函数画网络结构图

1、函数的定义及其形参

tf.keras.utils.plot_model(
    model,
    to_file='model.png',
    show_shapes=False,
    show_layer_names=True,
    rankdir='TB',
    expand_nested=False,
    dpi=96
)

Arguments:

  • model: A Keras model instance
  • to_file: File name of the plot image.
  • show_shapes: whether to display shape information.
  • show_layer_names: whether to display layer names.
  • rankdirrankdir argument passed to PyDot, a string specifying the format of the plot: 'TB' creates a vertical plot; 'LR' creates a horizontal plot.
  • expand_nested: Whether to expand nested models into clusters.
  • dpi: Dots per inch.

2、使用实例

    model = keras.Sequential([
        layers.LSTM(32, input_shape=[5, 20], return_sequences=True, kernel_regularizer=keras.regularizers.l2(0.01)),
        layers.LSTM(32, return_sequences=False),
        layers.Dense(3, activation='softmax'),
    ])

    tf.keras.utils.plot_model(model, to_file='model3.png', show_shapes=True, show_layer_names=True,rankdir='TB', dpi=900, expand_nested=True)

3、可能碰到的问题

我在使用过程中,碰到错误如下:

raise ImportError('Failed to import pydot. You must install pydot'
ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

按照提示安装pydot和graphviz即可,我是用conda进行安装

 

https://blog.csdn.net/yz19930510/article/details/82345181 

https://tensorflow.google.cn/api_docs/python/tf/keras/utils/plot_model

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值