Use Slim to overview model in Tensorflow like model.summary() in Keras

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://*.com/questions/46560313/is-there-an-easy-way-to-get-something-like-keras-model-summary-in-tensorflow

 

上一篇:tensorboard 使用summary报Fetch argument None has invalid type class NoneType


下一篇:SummaryWriter报错,改为tf summary FileWriter