0 votes
1 view
in AI and Deep Learning by (120 points)

Hi. I have a code which is concatenating two models. The code used the old version of Keras. I am using Keras 2.2.4. I am trying to concatenate both the models but I am getting an error while training. And if I use the pre-train model and try to execute the test file I get the following error:

ValueError: You are trying to load a weight file containing 6 layers into a model with 0 layers.

Because of this error, I am assuming that I am not concatenating the models correctly. Here is my code snippet. How do I concatenate my model using Keras 2.2.4 on line 

"model.add(Merge([image_model, lang_model], mode='concat'))"      .... Below is the complete model code snippet. 

def create_model(self, ret_model = False):

        image_model = Sequential()

        image_model.add(Dense(EMBEDDING_DIM, input_dim = 4096, activation='relu'))


        lang_model = Sequential()

        lang_model.add(Embedding(self.vocab_size, 256, input_length=self.max_length))



        model = Sequential()

        model.add(Merge([image_model, lang_model], mode='concat'))




        print ("Model created!")


            return model

      model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])

      return model

Here is my code snippet in pic: How do I concatenate my model using Keras 2.2.4 on line 103.

This is my model code snippet pic. Please help me out with it.

1 Answer

0 votes
by (43k points)
Just remove the InputLayer as it seems that it is not serialized to HDF5 correctly.

And also Merge(mode='concat') is now concatenate(axis=-1).

You want to merge models not layers, this will not work in your situation. Just use the functional model as this behavior has no longer stayed with the basic Sequential model type.
by (120 points)
https://dpaste.de/dWSy  (this is my train.py file)   and     https://dpaste.de/7MNH   (this is my file where I create the model. the file name is "SceneDesc.py").

I can't seem to remove the error.
by (43k points)
Instead of using InputLayer you can use input shape like the follows:
model = Sequentional()
model.add(Conv2D(filters=20,..., input_shape=(36, 120, 1)))
and for concatenating two models you can refer the following syntax:
concatenated = concatenate([model1_out, model2_out])
out = Dense(1, activation='softmax', name='output_layer')(concatenated)
by (120 points)
Ashely can you please properly write it for me the code.. I mean the model. I am getting a bit confused. As i am a beginner to all this.
Welcome to Intellipaat Community. Get your technical queries answered by top developers !