0

i saved my model like this :

ktrain.get_predictor(learner.model,preproc=trans).save('model')

i want to load my model and use it and to do something like :

predictor = ktrain.load(folder)
x = "hello wold"
prediction = predictor(x) 

now, i have a folder "model" which contains 5 files : vocab.txt , tokenizer_config.json, tf_model.preproc , special_tokens_map.json and config.json thank you please help me to load and use my predictor

2 Answers2

0
predictor = ktrain.load_predictor('<Path>')
model = ktrain.get_predictor(predictor.model, predictor.preproc)
predictions = model.predict('<anything you want to predict')

There's also a method model.predict_filename() to predict from images.

Yash Vishe
  • 61
  • 8
  • 1
    i have this error , Exception: Failed to load .preproc file in either the post v0.16.x loction (IAAA/model/tf_model.preproc) or pre v0.16.x location (IAAA/model.preproc) – Omayma HARBAOUI Jun 28 '21 at 18:38
  • I got this error once when the path specified in load_predictor was incorrect. Make sure to write the entire path up until the folder that has tf_model.h5 and tf_model.preproc files. If you used google collab to save the model the path should be somewhat like "foldername/content/modelname" – Yash Vishe Jun 29 '21 at 11:51
  • @OmaymaHARBAOUI The predictor needs to be saved properly before loading. `predictor = ktrain.get_predictor(learner.model, preproc=preproc)` -> `predictor.save(path)`. You'll see a folder with `tf_model.h5` and `tf_model.preproc`. – Woden Nov 25 '21 at 07:28
0

You need to explicitly use predictor.model.predict function to make a prediction. Therefore, the processes:

predictor = ktrain.get_predictor(learner.model,preproc=trans).save('model')
predictor.save('model')

predictor = ktrain.load_predictor('model')
x = "Hello World"
prediction = predictor.model.predict(x)
print(prediction)
Woden
  • 1,054
  • 2
  • 13
  • 26