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)
   

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM