日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Keras共享某个层

發布時間:2024/7/5 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Keras共享某个层 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對一個層的多次調用,就是在共享這個層。

input1 = Input(shape=[28,28]) input2 = Input(shape=[28,28]) x1 = Flatten()(input1) x1 = Dense(60,activation="relu")(x1) x2 = Flatten()(input2) x2 = Dense(60,activation="relu")(x2)d = Dense(10, activation='softmax')output1 = d(x1) output2 = d(x2) model1 = Model(input=[input1], output=[output1]) model2 = Model(input=[input1], output=[output1]) print(model1.summary()) print(model2.summary())

結果:

____________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ==================================================================================================== input_1 (InputLayer) (None, 28, 28) 0 ____________________________________________________________________________________________________ flatten_1 (Flatten) (None, 784) 0 input_1[0][0] ____________________________________________________________________________________________________ dense_1 (Dense) (None, 60) 47100 flatten_1[0][0] ____________________________________________________________________________________________________ dense_3 (Dense) (None, 10) 610 dense_1[0][0] ==================================================================================================== Total params: 47710 ____________________________________________________________________________________________________ None ____________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ==================================================================================================== input_1 (InputLayer) (None, 28, 28) 0 ____________________________________________________________________________________________________ flatten_1 (Flatten) (None, 784) 0 input_1[0][0] ____________________________________________________________________________________________________ dense_1 (Dense) (None, 60) 47100 flatten_1[0][0] ____________________________________________________________________________________________________ dense_3 (Dense) (None, 10) 610 dense_1[0][0] ==================================================================================================== Total params: 47710 ____________________________________________________________________________________________________ None

如果修改x2:

x2 = Dense(70,activation="relu")(x2)

就會報錯:

Exception: Input 0 is incompatible with layer dense_3: expected shape=(None, 60), found shape=(None, 70)

就是因為第一次使用Dense層的時候,他的參數w的大小已經定了是(28*28,60),共享層的目的不就是為了共享參數的嗎,所以,我講明白了吧!

總結

以上是生活随笔為你收集整理的Keras共享某个层的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。