|
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. |
|
|
|
""" |
|
|
|
|
|
image_file_path = '/content/drive/MyDrive/Colab Notebooks/dog-vision-project/custom_images/myImage.jpg' |
|
|
|
|
|
image = Image.fromarray(image) |
|
image.save(image_file_path) |
|
|
|
|
|
test_data = get_data_batches(X=[image_file_path], test_data=True, batch_size=1, deployment = True) |
|
|
|
|
|
predictions = model.predict(test_data, verbose = 0) |
|
|
|
|
|
predicted_label_index = np.argmax(predictions[0]) |
|
predicted_breed_label = unique_breeds[predicted_label_index] |
|
|
|
|
|
os.remove(image_file_path) |
|
|
|
return format_underscores(predicted_breed_label) |