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