在TensorFlow中,可以使用model.summary()方法来查看模型的参数。这个方法会打印出模型的结构以及每一层的参数数量。示例如下:
import tensorflow as tf# 创建模型model = tf.keras.Sequential([ tf.keras.layers.Dense(64, activation='relu', input_shape=(784,)), tf.keras.layers.Dense(64, activation='relu'), 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, 64) 4160 _________________________________________________________________dense_2 (Dense) (None, 10) 650 =================================================================Total params: 55,050Trainable params: 55,050Non-trainable params: 0_________________________________________________________________在上述输出中,每一层的参数数量都会显示在Param #这一列中。

