请考虑以下模型
def create_model():
x_1=tf.Variable(24)
bias_initializer = tf.keras.initializers.HeNormal()
model = Sequential()
model.add(Conv2D(64, (5, 5), input_shape=(28,28,1),activation="relu", name='conv2d_1', use_bias=True,bias_initializer=bias_initializer))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (5, 5), activation="relu",name='conv2d_2', use_bias=True,bias_initializer=bias_initializer))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(120, name='dense_1',activation="relu", use_bias=True,bias_initializer=bias_initializer),)
model.add(Dense(10, name='dense_2', activation="softmax", use_bias=True,bias_initializer=bias_initializer),)
我可以提取模型示例的摘要,但是否有任何方法可以给予/计算层数(带有可训练参数)?例如,上面发布的模型有4个带有可训练参数的层。
1条答案
按热度按时间ki0zmccv1#
model.trainable_weights
给出了所有可训练权重的列表。权重和偏差是独立考虑的,因此您需要对权重总数进行唯一计数