-1

I have two different CNN network as below:

class CNN_1(object):
def __init__(self, max_input_right, max_input_left,list_ans,filter_sizes, embeddings,embedding_size):
    self.max_input_right = max_input_right
    self.max_input_left = max_input_left
    self.list_ans = list_ans
    self.filter_sizes = filter_sizes
    self.embeddings = embeddings
    self.total_embedding_dim = embedding_size

def create_placeholder(self):
    print('Create placeholders')
    self.question = tf.placeholder(tf.int32,[None,self.max_input_left],name = 'input_question')
    self.sample_set_1 = tf.placeholder(tf.int32, [None,self.max_input_right])
    self.sample_set_2 = tf.placeholder(tf.int32, [None,self.max_input_right])

The second CNN layer also looks similar and they are further more functions in it to build the network. Now I want to build a third network which merges these 2 existing network.

Can anyone suggest how to build this third network using tensorflow?

Purbasha
  • 43
  • 9
  • What does merging means? Stacking? Averaging? Are these CNN pre-trained? – Patwie Aug 12 '18 at 04:57
  • @Patwie Merging means concating them together. Yes, these CNN are pre-trained. – Purbasha Aug 12 '18 at 06:06
  • Then it is duplicate. Stacking is done by output of one network is input of other instead of placeholders. And loading is described [here](https://stackoverflow.com/a/51018846/7443104) – Patwie Aug 12 '18 at 06:10

1 Answers1

1

You can use Keras Functional API to merge them into one network . Here's code for that:

merged = Concatenate()([model_1, model_2])    
model_final = Model(inputs=[model_1_input_shape, model_2_input_shape], outputs=[output])
model_final.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

If you want to Visualize final Model :

from keras.utils import plot_model
plot_model(model_final, to_file='Summary.png')

In your own work , you can use any optimizer or Loss.Hope it helped you.

AEM
  • 1,354
  • 8
  • 20
  • 30