ImanAmran commited on
Commit
d464172
1 Parent(s): a426aff

Update 101234444_aml_assignment_1.py

Browse files
Files changed (1) hide show
  1. 101234444_aml_assignment_1.py +3 -1
101234444_aml_assignment_1.py CHANGED
@@ -32,6 +32,8 @@ model = tf.keras.models.load_model("final_model.h5")
32
  index_to_class = {v: k for k, v in class_indices.items()}
33
 
34
  def classify_image(image: PIL.Image.Image):
 
 
35
  try:
36
  # Ensure the input is a PIL Image, resize it, and then convert it to a NumPy array
37
  if not isinstance(image, PIL.Image.Image):
@@ -48,7 +50,7 @@ def classify_image(image: PIL.Image.Image):
48
  predicted_class_idx = np.argmax(predictions) # Get the predicted class index
49
 
50
  # Map index to label using index_to_class
51
- predicted_class_label = index_to_class[predicted_class_idx]
52
  return predicted_class_label
53
 
54
  except Exception as e:
 
32
  index_to_class = {v: k for k, v in class_indices.items()}
33
 
34
  def classify_image(image: PIL.Image.Image):
35
+ if image is None:
36
+ return "Invalid or empty image provided."
37
  try:
38
  # Ensure the input is a PIL Image, resize it, and then convert it to a NumPy array
39
  if not isinstance(image, PIL.Image.Image):
 
50
  predicted_class_idx = np.argmax(predictions) # Get the predicted class index
51
 
52
  # Map index to label using index_to_class
53
+ predicted_class_label = index_to_class[predicted_class_idx].replace('_', ' ')
54
  return predicted_class_label
55
 
56
  except Exception as e: