使用keras2 0 將Merge層改為函式式

2022-10-04 14:24:29 字數 2016 閱讀 5884

不能再向以前一樣使用

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="channewww.cppcns.comls_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), activat'relu',

# init='he_normal', borde程式設計客棧r_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 zjvbks= 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層改為函式式

本文位址:

Keras使用使用動態LSTM RNN

padding def generate mtp 100,batch 50 最長時間步,詞向量長度為200,batch size 50 origin input np.random.random sample batch,np.random.randint mtp 2,mtp 200 時間長隨機從m...

Keras學習 1 使用keras建立序列模型

keras學習 1 使用keras建立序列模型 sequential model就是一些列layers的簡單堆疊。首先,我們建立乙個簡單的前向全連線網路。輸入維度784 from keras.models import sequential from keras.layers import dens...

使用 Keras 搭建 DNN

from keras.datasets import mnist import numpy as np x train,y train x test,y test mnist.load data print np.shape x train np.shape x test 60000,28,28 1...