lordfoogthe2st's picture
create app.py
d4da8ae
def complete_model_pipeline(image):
"""
Complete model pipeline for deploying the model using Gradio.
This function takes an image as input, saves it temporarily to a file,
loads the image as a test sample, performs prediction using the model,
and then removes the temporarily saved image. The function returns the
predicted dog breed label.
Args:
image (np.ndarray): The NumPy array representing the input image.
Returns:
str: The predicted dog breed label.
Parameters:
- image: A NumPy array representing the input image.
Note: This function is designed to be used with Gradio to deploy the model
and obtain predictions interactively.
"""
# Define the file path to temporarily save the image
image_file_path = '/content/drive/MyDrive/Colab Notebooks/dog-vision-project/custom_images/myImage.jpg'
# Convert the input NumPy array to a Pillow image object and save it as a file
image = Image.fromarray(image)
image.save(image_file_path)
# Prepare test data for the model using the saved image file
test_data = get_data_batches(X=[image_file_path], test_data=True, batch_size=1, deployment = True)
# Perform prediction using the model
predictions = model.predict(test_data, verbose = 0)
# Get the index of the highest predicted value and obtain the corresponding breed label
predicted_label_index = np.argmax(predictions[0])
predicted_breed_label = unique_breeds[predicted_label_index]
# Remove the temporarily saved image file
os.remove(image_file_path)
return format_underscores(predicted_breed_label)