I am using tensorflow==1.15.5.
And I load my model like this
modelBlstm = tf.keras.models.load_model(modelPath,
                                            custom_objects={
                                                'elmo': hub.Module("https://tfhub.dev/google/elmo/2", trainable=False),
                                                'tf': tf
                                            })

My model needs elmo variable to be declared, so I passed the elmo  variable in custom objects, but with this it does not predict correctly, now I declare the elmo as different variable
and just use
modelBlstm = tf.keras.models.load_model(modelPath)
it works well with the same user query.
But this works only if i am running the same code in single file.
But now if integrate the same code in my project it shows elmo variable is undefined.
Tried declaring elmo outside the class, creating elmo variable inside the class but it does not work, even with in the project, i removed the class and just cerated the functions like this…
dirName = os.path.dirname(__file__)

modelPath = os.path.join(dirName, "models/elmo-strat-bilstm-dense-2.h5")

modelBlstm = tf.keras.models.load_model(modelPath)

labelModelPath = os.path.join(dirName, "..\config\labels_mapping.pkl")

modelLabel = joblib.load(labelModelPath)

stopwords = ['i',  'am', 'a',

             'to', 'is', 'do', 'in', 'of']

elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainable=False)

print("************elmo",elmo)

with tf.Session() as session:

    K.set_session(session)

    session.run(tf.global_variables_initializer())

    session.run(tf.tables_initializer())

    modelBlstm = tf.keras.models.load_model(modelPath, )

def process(query: str) -> Intent:

    Logger.log("Processing query : " + query)

    query = __textPreprocess(query)

    print("query", query)

    intent = __predict(query)

    print(query)

    return intent

but even this does not work,
all other details i have mentioned in this SO question.
Any help?

  

      stackoverflow.com
  

  
      
    
  


  model is not predicting correct results keras tensorflow python



  python, tensorflow, keras, data-science



  asked by
  
  
    Sunil Garg
  
  on 10:09AM - 09 Jul 21 UTC