lordfoogthe2st
commited on
Commit
•
d4da8ae
1
Parent(s):
e8663a5
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def complete_model_pipeline(image):
|
2 |
+
"""
|
3 |
+
Complete model pipeline for deploying the model using Gradio.
|
4 |
+
|
5 |
+
This function takes an image as input, saves it temporarily to a file,
|
6 |
+
loads the image as a test sample, performs prediction using the model,
|
7 |
+
and then removes the temporarily saved image. The function returns the
|
8 |
+
predicted dog breed label.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
image (np.ndarray): The NumPy array representing the input image.
|
12 |
+
|
13 |
+
Returns:
|
14 |
+
str: The predicted dog breed label.
|
15 |
+
|
16 |
+
Parameters:
|
17 |
+
- image: A NumPy array representing the input image.
|
18 |
+
|
19 |
+
Note: This function is designed to be used with Gradio to deploy the model
|
20 |
+
and obtain predictions interactively.
|
21 |
+
|
22 |
+
"""
|
23 |
+
|
24 |
+
# Define the file path to temporarily save the image
|
25 |
+
image_file_path = '/content/drive/MyDrive/Colab Notebooks/dog-vision-project/custom_images/myImage.jpg'
|
26 |
+
|
27 |
+
# Convert the input NumPy array to a Pillow image object and save it as a file
|
28 |
+
image = Image.fromarray(image)
|
29 |
+
image.save(image_file_path)
|
30 |
+
|
31 |
+
# Prepare test data for the model using the saved image file
|
32 |
+
test_data = get_data_batches(X=[image_file_path], test_data=True, batch_size=1, deployment = True)
|
33 |
+
|
34 |
+
# Perform prediction using the model
|
35 |
+
predictions = model.predict(test_data, verbose = 0)
|
36 |
+
|
37 |
+
# Get the index of the highest predicted value and obtain the corresponding breed label
|
38 |
+
predicted_label_index = np.argmax(predictions[0])
|
39 |
+
predicted_breed_label = unique_breeds[predicted_label_index]
|
40 |
+
|
41 |
+
# Remove the temporarily saved image file
|
42 |
+
os.remove(image_file_path)
|
43 |
+
|
44 |
+
return format_underscores(predicted_breed_label)
|