model.summary() in Tensorflow like Keras

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

 

来源: https://stackoverflow.com/questions/46560313/is-there-an-easy-way-to-get-something-like-keras-model-summary-in-tensorflow

 

相关文章:

  • 2021-07-02
  • 2021-09-29
  • 2021-11-14
  • 2022-01-07
  • 2021-11-11
  • 2021-08-10
  • 2021-08-10
  • 2021-07-19
猜你喜欢
  • 2021-09-12
  • 2021-05-30
  • 2021-07-27
  • 2021-07-22
  • 2021-11-11
  • 2021-04-21
  • 2021-10-25
相关资源
相似解决方案