1

I'm trying to create a model in keras. I read a paper and I want to create a model from this paper. Here What I want: ArchitectureInPaper

I tried create a model like this, but I dunno How to concatenate two Model in Keras. And How to create a model like this architecture in this paper.

input1 = Input(shape=(96,96,3))
x1 = Conv2D(64, 
(5,5),input_shape=input_shape,padding='same',activation='relu',strides= 
(2,2))(input1)
x1 = MaxPooling2D(pool_size=(2,2))(x1)
x1 = Conv2D(128, 
(5,5),input_shape=input_shape,padding='same',activation='relu',strides= 
(2,2))(input1)
x1 = MaxPooling2D(pool_size=(2,2))(x1)
x1 = Conv2D(256, 
(5,5),input_shape=input_shape,padding='same',activation='relu',strides= 
(2,2))(input1)
x1 = MaxPooling2D(pool_size=(2,2))(x1)

input2 = Input(shape=(96,96,3))
x2 = Dense(4032,activation='relu')(input2)

input3 = Input(shape=(96,96,3))
x3 = Dense(300,activation='relu')(input3)

input4 = Input(shape=(96,96,3))
x4 = Dense(7,activation='softmax')(input4)


x = concatenate([input2,input4])

x = Dense(4039,activation='relu')(x)
x = Dense(1000,activation='relu')(x)
x = Dense(500,activation='relu')(x)
main_output = Dense(15, activation='sigmoid', name='main_output')(x)

model = Model(inputs=[input2,input4],outputs =[main_output])
Cevdet
  • 69
  • 9

2 Answers2

0

You can use concatenate layer. See the doc https://www.tensorflow.org/api_docs/python/tf/keras/layers/concatenate

x = keras.layers.concatenate([fc4032, emo8])

x here will have output shape 4040 as shown in the paper.

Ha Bom
  • 2,787
  • 3
  • 15
  • 29
  • Yeah I know but. I have a 7 class for first model. So I have output shape 4039. Now I should solve this error. Thanks for help. ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. – Cevdet Jun 18 '19 at 12:42
0

It isn't clear which of the model architectures you are planning to implement, fig3 or 4? For the architecture represented in figure 3, you don't need to concatenate any two layers or models. For the architecture in figure 4, you can preferably try the functional API in keras, which allows concatenation of layers, using keras.backend.concatenate().

It will be helpful to go through this answer on stackoverflow itself. How to concatenate two layers in keras?

neha tamore
  • 181
  • 1
  • 1
  • 8