Unable to load and use multiple keras models

I am trying to load three different models into the same process. Only the first one works as expected, the rest return as random results. Basically the order is as follows:

  • identify and compile the first model
  • load trained weights to
  • rename layers
  • the same process for the second model
  • the same process for the third model

So something like:

model1 = Model(inputs=Input(shape=input_size_im) , outputs=layers_firstmodel)
model1.compile(optimizer='sgd', loss='mse')
model1.load_weights(weights_first, by_name=True)
# rename layers but didn't work

model2 = Model(inputs=Input(shape=input_size_im) , outputs=layers_secondmodel)
model2.compile(optimizer='sgd', loss='mse')
model2.load_weights(weights_second, by_name=True)
# rename layers but didn't work

model3 = Model(inputs=Input(shape=input_size_im) , outputs=layers_thirdmodel)
model3.compile(optimizer='sgd', loss='mse')
model3.load_weights(weights_third, by_name=True)
# rename layers but didn't work

for im in list_images:
    results_firstmodel = model1.predict(im) 
    results_secondmodel = model2.predict(im) 
    results_thirdmodel = model2.predict(im) 

I would like to draw some conclusions because of the heap of images. For this, the idea is to loop the images and perform the output with these three algorithms and return the results.

, . , . , ( , - , sess.run(tf.global_variables_initializer()) ). , , " tensorflow (/device: GPU: 0)".

Tensorflow 1.4.0-rc0, Keras 2.1.1 โ€‹โ€‹Ubuntu 16.04 4.14.

+4
2

Keras docs load_weights:

HDF5 (, save_weights). , . ( ), by_name = True .

, , by_name=True False ( ). , , , , - .


, , - HDF5 . ( save_weights, ), , .

, HDF5 , keras.models.load_model ( , ). , .

Callbacks, , ModelCheckpoint EarlyStopping if , . ( ), , load_model , .

, SO, ( ) Keras.

+2

. script . . script, , , . - .

EDIT: model.load_weight , , , . , - , load_weight script, . , , , .

0

Source: https://habr.com/ru/post/1689573/


All Articles