tensorflow2.0——多层全连接模板

import tensorflow as tf

x = tf.random.normal((2,3))                 #   模拟样本数据

model = tf.keras.Sequential([               #   定义全连接层结构
    tf.keras.layers.Dense(4,activation='relu'),                 #   第一层输出为4
    tf.keras.layers.Dense(3,activation='relu'),
    tf.keras.layers.Dense(2)                                    #   输出层不需要激活函数
])
out = model(x)                                                  #   前向预测值
print('out:',out)
print(model.summary())                                          #   网络结构打印
print()
for i in model.trainable_variables:                              #   打印训练参数
    print(i.name,i.shape)
   

原文地址:https://www.cnblogs.com/cxhzy/p/13509624.html