sowbaranika13 commited on
Commit
6d7868d
1 Parent(s): 2ce8b47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -15,19 +15,26 @@ labels = {
15
  'amphibia': ['American Bullfrog', 'American Toad', 'Green Frog', 'Northern Leopard Frog']
16
  }
17
 
18
-
19
- def predict(image):
 
 
 
20
 
21
- img = image.resize((224, 224))
22
- img_array = tf.keras.utils.img_to_array(img)
23
- img_array = tf.expand_dims(img_array, 0) # Create a batch
 
 
24
  model = load_model(r"inceptionv3_classs.h5")
25
- predictions = model.predict(img_array)
26
- score = np.argmax(predictions)
27
- class_label = labels['class'][score]
28
- print(score, class_label )
 
 
29
 
30
- return class_label
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)