Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
|
| 7 |
-
model_path = "
|
| 8 |
model = tf.keras.models.load_model(model_path)
|
| 9 |
|
| 10 |
# Define the core prediction function
|
|
@@ -12,7 +12,7 @@ def predict_bmwX(image):
|
|
| 12 |
# Preprocess image
|
| 13 |
print(type(image))
|
| 14 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
| 15 |
-
image = image.resize((
|
| 16 |
image = np.array(image)
|
| 17 |
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
| 18 |
|
|
@@ -23,10 +23,15 @@ def predict_bmwX(image):
|
|
| 23 |
prediction = tf.nn.softmax(prediction)
|
| 24 |
|
| 25 |
# Define class names
|
| 26 |
-
class_names = ['Afghan', 'African Wild Dog', '
|
| 27 |
-
'
|
| 28 |
-
'
|
| 29 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Create a dictionary with the probabilities for each dog breed
|
| 32 |
prediction_dict = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
|
| 7 |
+
model_path = "DogClassifier2.1.keras"
|
| 8 |
model = tf.keras.models.load_model(model_path)
|
| 9 |
|
| 10 |
# Define the core prediction function
|
|
|
|
| 12 |
# Preprocess image
|
| 13 |
print(type(image))
|
| 14 |
image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image
|
| 15 |
+
image = image.resize((150, 150)) #resize the image to 150x150
|
| 16 |
image = np.array(image)
|
| 17 |
image = np.expand_dims(image, axis=0) # same as image[None, ...]
|
| 18 |
|
|
|
|
| 23 |
prediction = tf.nn.softmax(prediction)
|
| 24 |
|
| 25 |
# Define class names
|
| 26 |
+
class_names = ['Afghan', 'African Wild Dog', 'Airedale', 'American Hairless', 'American Spaniel', 'Basenji', 'Basset', 'Beagle',
|
| 27 |
+
'Bearded Collie', 'Bermaise', 'Bichon Frise', 'Blenheim', 'Bloodhound', 'Bluetick', 'Border Collie', 'Borzoi',
|
| 28 |
+
'Boston Terrier', 'Boxer', 'Bull Mastiff', 'Bull Terrier', 'Bulldog', 'Cairn', 'Chihuahua', 'Chinese Crested',
|
| 29 |
+
'Chow', 'Clumber','Cockapoo', 'Cocker', 'Collie', 'Corgi', 'Coyote', 'Dalmation', 'Dhole', 'Dingo', 'Doberman',
|
| 30 |
+
'Elk Hound', 'French Bulldog', 'German Sheperd', 'Golden Retriever', 'Great Dane', 'Great Perenees', 'Greyhound',
|
| 31 |
+
'Groenendael', 'Irish Spaniel', 'Irish Wolfhound', 'Japanese Spaniel', 'Komondor', 'Labradoodle', 'Labrador',
|
| 32 |
+
'Lhasa', 'Malinois', 'Maltese', 'Maltese', 'Mex Hairless', 'Newfoundland', 'Pekinese', 'Pit Bull', 'Pomeranian',
|
| 33 |
+
'Poodle', 'Pug', 'Rhodesian', 'Rottweiler', 'Saint Bernard', 'Schnauzer', 'Scotch Terrier', 'Shar_Pei',
|
| 34 |
+
'Shiba Inu', 'Shih-Tzu', 'Siberian Husky', 'Vizsla', 'Yorkie']
|
| 35 |
|
| 36 |
# Create a dictionary with the probabilities for each dog breed
|
| 37 |
prediction_dict = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
|