tensorflow打印模型结构
时间: 2023-09-18 22:12:30 浏览: 38
我们可以使用 `model.summary()` 函数打印模型结构,其中 `model` 是已经定义好的 TensorFlow 模型。
例如:
```python
import tensorflow as tf
# 定义一个简单的全连接神经网络模型
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu', input_shape=(784,)),
tf.keras.layers.Dense(10, activation='softmax')
])
# 打印模型结构
model.summary()
```
输出结果如下:
```
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
dense (Dense) (None, 64) 50240
_________________________________________________________________
dense_1 (Dense) (None, 10) 650
=================================================================
Total params: 50,890
Trainable params: 50,890
Non-trainable params: 0
_________________________________________________________________
```
其中,每一层都会显示该层的类型、输出形状、参数数量等信息。