Spaces:
Sleeping
Sleeping
sowbaranika13
commited on
Commit
•
6d7868d
1
Parent(s):
2ce8b47
Update app.py
Browse files
app.py
CHANGED
@@ -15,19 +15,26 @@ labels = {
|
|
15 |
'amphibia': ['American Bullfrog', 'American Toad', 'Green Frog', 'Northern Leopard Frog']
|
16 |
}
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
model = load_model(r"inceptionv3_classs.h5")
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
# results = {}
|
32 |
# image_array = load_and_preprocess_image(image)
|
33 |
# print(image_array)
|
|
|
15 |
'amphibia': ['American Bullfrog', 'American Toad', 'Green Frog', 'Northern Leopard Frog']
|
16 |
}
|
17 |
|
18 |
+
def preprocess_image(img_path):
|
19 |
+
img = image.resize((224, 224)) # MobileNet requires 224x224 input size
|
20 |
+
img_array = image.img_to_array(img)
|
21 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
22 |
+
img_array = preprocess_input(img_array) # Preprocess the image
|
23 |
|
24 |
+
return img_array
|
25 |
+
|
26 |
+
# Function to perform inference
|
27 |
+
def predict(model, img_path):
|
28 |
+
img = preprocess_image(img_path)
|
29 |
model = load_model(r"inceptionv3_classs.h5")
|
30 |
+
preds = model.predict(img) # Get the model predictions
|
31 |
+
decoded_preds = np.argmax(preds)
|
32 |
+
print(decoded_preds, labels['class'][decoded_preds])
|
33 |
+
return decoded_preds
|
34 |
+
|
35 |
+
|
36 |
|
37 |
+
|
38 |
# results = {}
|
39 |
# image_array = load_and_preprocess_image(image)
|
40 |
# print(image_array)
|