0

I'm using two differents neural networks sequential models in my python program.

One RNN model defined like this:

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, CuDNNLSTM

ModelRNN = Sequential()

ModelRNN.add(CuDNNLSTM(150, return_sequences=True, batch_size=None, input_shape=(None,10)))
ModelRNN.add(CuDNNLSTM(150, return_sequences=True))
ModelRNN.add(Dense(100, activation='relu'))
ModelRNN.add(Dense(10, activation='relu'))
optimizer = tf.keras.optimizers.Adam(lr=0.001)

ModelRNN.compile(loss='mean_squared_error', optimizer=optimizer, metrics=['accuracy'])

One Dense model defined like this :

ModelDense = Sequential()

ModelDense.add(Dense(380, batch_size=None, input_shape=(1,380), activation='elu'))
ModelDense.add(Dense(380, activation='elu'))
ModelDense.add(Dense(380, activation='elu'))
ModelDense.add(Dense(380, activation='elu'))
optimizer = tf.keras.optimizers.Adam(lr=0.00025)

ModelDense.compile(loss='mean_squared_error', optimizer=optimizer, metrics=['accuracy'])

So my problem is that the two networks will work together so i have to run both of them in the same tensorflow session BUT, i want to save them in two differents folders. I don't really know if it's possible because i never really interested myself in how is working the tensorflow graphs at all and i only know that when i use my tensorflow saver, i only give as parameter my session and a path.

So my question is how can i separate the storage of my models in two folders ?

I want to do that because i want to be able to easily change my RNN without having to retrain both of my networks or without having to overwrite my trained RNN

If i'am not clear please ask me for more details

Xeyes
  • 583
  • 5
  • 25

1 Answers1

2

So my question is how can i separate the storage of my models in two folders ?

The save method of Keras model accepts a file path, so different folders can be given for the individual models.

ModelRNN.save('folder1/<filename.h5>')
ModelDense.save('folder2/<filename.h5>')

https://www.tensorflow.org/tutorials/keras/save_and_restore_models#save_the_entire_model

Manoj Mohan
  • 5,654
  • 1
  • 17
  • 21
  • oh really ! there is such a function ! thank a lot i didn't find anything about this i'll check it so thank a lot – Xeyes Jul 04 '19 at 21:03
  • So I tested it, the save function seems to work well but when i restore the model for retrain it the accuracy start with as bad values as if i create a new network.. – Xeyes Jul 05 '19 at 15:08
  • This has to be a separate question. You can check if you compiled the model after loading, which is not required. https://stackoverflow.com/questions/56851288/why-is-adam-iterations-always-set-to-0-in-keras/ – Manoj Mohan Jul 06 '19 at 11:33