Is there an easy way to get something like Keras model.summary in Tensorflow?

前端 未结 4 764
一向
一向 2020-12-13 13:51

I have been working with Keras and really liked the model.summary() It gives a good overview of the size of the different layers and especially an overview of t

相关标签:
4条回答
  • 2020-12-13 14:07

    You can use keras with the tensorflow backend to get the best features of either keras or tensorflow.

    0 讨论(0)
  • 2020-12-13 14:12

    Looks like you can use Slim

    Example:

    import numpy as np
    
    from tensorflow.python.layers import base
    import tensorflow as tf
    import tensorflow.contrib.slim as slim
    
    x = np.zeros((1,4,4,3))
    x_tf = tf.convert_to_tensor(x, np.float32)
    z_tf = tf.layers.conv2d(x_tf, filters=32, kernel_size=(3,3))
    
    def model_summary():
        model_vars = tf.trainable_variables()
        slim.model_analyzer.analyze_vars(model_vars, print_info=True)
    
    model_summary()
    

    Output:

    ---------
    Variables: name (type shape) [size]
    ---------
    conv2d/kernel:0 (float32_ref 3x3x3x32) [864, bytes: 3456]
    conv2d/bias:0 (float32_ref 32) [32, bytes: 128]
    Total size of variables: 896
    Total bytes of variables: 3584
    

    Also here is an example of custom function to print model summary: https://github.com/NVlabs/stylegan/blob/f3a044621e2ab802d40940c16cc86042ae87e100/dnnlib/tflib/network.py#L507

    If you already have .pb tensorflow model you can use: inspect_pb.py to print model info or use tensorflow summarize_graph tool with --print_structure flag, also it's nice that it can detect input and output names.

    0 讨论(0)
  • 2020-12-13 14:15

    I haven't seen anything like model.summary() for the tensorflow... However, I don't think you need it. There is a TensorBoard, where you can easily check the architecture of the NN.

    https://www.tensorflow.org/get_started/graph_viz

    0 讨论(0)
  • 2020-12-13 14:31

    For those who land here in the post era of Tensorflow 1.x...

    With Tensorflow 2.0 all models recommended to use Keras Model class, so:

    • You can print the Keras model sumary with model.summary() (or)
    • You can plot the model by following the doc @ https://www.tensorflow.org/api_docs/python/tf/keras/utils/plot_model?version=stable
    0 讨论(0)
提交回复
热议问题