这篇文章主要讲解了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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。