Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 the number of parameters the model has.

Is there a similar function in Tensorflow? I could find nothing on Stackoverflow or the Tensorflow API documentation.

like image 353
Carsten Avatar asked Oct 04 '17 08:10

Carsten


People also ask

How do I get a model summary in TensorFlow?

Model summaryCall model. summary() to print a useful summary of the model, which includes: Name and type of all layers in the model. Output shape for each layer.

What is Model Summary ()?

Model summary. The model summary table reports the strength of the relationship between the model and the dependent variable. R, the multiple correlation coefficient, is the linear correlation between the observed and model-predicted values of the dependent variable.

What is model summary keras?

Summarize ModelKeras provides a way to summarize a model. The summary is textual and includes information about: The layers and their order in the model. The output shape of each layer. The number of parameters (weights) in each layer.


1 Answers

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.

like image 160
mrgloom Avatar answered Oct 02 '22 15:10

mrgloom