0
Model description:
cnn1=Sequential()
cnn1.add(Conv2D(128,(2,300), activation = 'relu',input_shape = (maxLenofSent,300,1)))

cnn1.add(MaxPooling2D(1,3))

cnn1.add(Flatten())
cnn1.add(Dense(100, activation = 'relu'))

cnn2=Sequential()
cnn2.add(Conv2D(128,(2,300), activation = 'relu',input_shape = (maxLenofSent,300,1)))
cnn2.add(MaxPooling2D(1,3))
cnn2.add(Flatten())
cnn2.add(Dense(100, activation = 'relu'))


classifier2=Sequential()
classifier2.add(Merge([cnn1,cnn2], mode='concat'))
classifier2.add(Dense(70,activation='sigmoid'))
classifier2.add(Dropout(0.2))
classifier2.add(Dense(2,activation='tanh'))
sgd = SGD(lr = 0.01, momentum = 0.9, decay=1e-2, nesterov = False)
classifier2.compile(loss = 'categorical_crossentropy', optimizer = sgd, metrics = ['accuracy'])

How to save full model so that it can be used later for testing. Output of two cnn goes to ann and classify.

  • What have you tried? A quick search revealed https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model which should already answer your problem. – Sebastian Höffner Nov 19 '17 at 14:28
  • 3
    Possible duplicate of [Keras: How to save model and continue training?](https://stackoverflow.com/questions/45393429/keras-how-to-save-model-and-continue-training) – Sebastian Höffner Nov 19 '17 at 14:30

2 Answers2

0

Here how to save the model:

model_json = model.to_json()
with open("<path.json>", "w") as json_file:
    json_file.write(model_json)
model.save_weights("<path.hdf5>", overwrite=True)

If you want to save the model and weights at every epoch, try searching for callbacks.

MazeRunner09
  • 334
  • 2
  • 8
0

before saving the model, you need to train it using classifier2.fit()

https://keras.io/models/sequential/#fit

to save the model use classifier2.save('filename.hdf5')

Ophir Yoktan
  • 8,149
  • 7
  • 58
  • 106