您好,登錄后才能下訂單哦!
這篇文章主要講解了keras2.0如何將Merge層改為函數式,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。
不能再向以前一樣使用
model.add(Merge([Model1,Model2]))
必須使用函數式
out = Concatenate()([model1.output, model2.output])
補充知識:keras 新版接口修改
1.
# b = MaxPooling2D((3, 3), strides=(1, 1), border_mode='valid', dim_ordering='tf')(x)
b = MaxPooling2D((3, 3), strides=(1, 1), padding='valid', data_format="channels_last")(x)
2.
from keras.layers.merge import concatenate # x = merge([a, b], mode='concat', concat_axis=-1) x = concatenate([a, b], axis=-1)
3.
from keras.engine import merge m = merge([init, x], mode='sum') Equivalent Keras 2.0.2 code: from keras.layers import add m = add([init, x])
4.
# x = Convolution2D(32 // nb_filters_reduction_factor, 3, 3, subsample=(1, 1), activation='relu', # init='he_normal', border_mode='valid', dim_ordering='tf')(x) x = Conv2D(32 // nb_filters_reduction_factor, (3, 3), activation="relu", strides=(1, 1), padding="valid", data_format="channels_last", kernel_initializer="he_normal")(x)
1.
# b = MaxPooling2D((3, 3), strides=(1, 1), border_mode='valid', dim_ordering='tf')(x) b = MaxPooling2D((3, 3), strides=(1, 1), padding='valid', data_format="channels_last")(x)
2.
from keras.layers.merge import concatenate # x = merge([a, b], mode='concat', concat_axis=-1) x = concatenate([a, b], axis=-1)
3.
from keras.engine import merge m = merge([init, x], mode='sum') Equivalent Keras 2.0.2 code: from keras.layers import add m = add([init, x])
4.
# x = Convolution2D(32 // nb_filters_reduction_factor, 3, 3, subsample=(1, 1), activation='relu', # init='he_normal', border_mode='valid', dim_ordering='tf')(x) x = Conv2D(32 // nb_filters_reduction_factor, (3, 3), activation="relu", strides=(1, 1), padding="valid", data_format="channels_last", kernel_initializer="he_normal")(x)
看完上述內容,是不是對keras2.0如何將Merge層改為函數式有進一步的了解,如果還想學習更多內容,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。