|
from tensorflow.keras.models import load_model |
|
from scripts.utilities import ( |
|
greedy_generator, |
|
beam_search_generator, |
|
extract_image_features, |
|
inception_v3_model, |
|
) |
|
|
|
loaded_caption_model = load_model('models/caption_model.keras') |
|
|
|
|
|
def predict_caption(image_path): |
|
""" |
|
Predicts a caption for a given image. |
|
|
|
Args: |
|
image_path (str): The path to the image file. |
|
|
|
Returns: |
|
str: The generated caption. |
|
""" |
|
|
|
image_features = extract_image_features(inception_v3_model,image_path) |
|
|
|
|
|
greedy_caption = greedy_generator(image_features) |
|
beam_caption = beam_search_generator(image_features) |
|
|
|
|
|
return greedy_caption,beam_caption |
|
|
|
|
|
if __name__ == "__main__": |
|
image_path_to_predict = 'examples\ElleVet_Peny_92-1024x717.jpg' |
|
generated_caption = predict_caption(image_path_to_predict) |
|
print("Predicted Caption:", generated_caption) |
|
|
|
|
|
|
|
|
|
|