VishnuEcoClim commited on
Commit
22d0d15
·
1 Parent(s): be1ea43

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +22 -9
utils.py CHANGED
@@ -40,19 +40,32 @@ def preprocess(image_or_path):
40
  else: # Assume the input is a PIL Image object
41
  img = image_or_path
42
 
43
- # Resize the image
44
- resized_img = img.resize((256, 256), Image.LANCZOS)
45
 
46
- # Convert the image to a numpy array
47
- img_array = np.array(resized_img)
 
 
48
 
49
- # Normalize if necessary
50
- img_array = img_array / 255.0
 
51
 
52
- # Add a batch dimension
53
- img_array = np.expand_dims(img_array, axis=0)
54
 
55
- return img_array
 
 
 
 
 
 
 
 
 
 
56
 
57
  def model_arc():
58
  model = tf.keras.Sequential([
 
40
  else: # Assume the input is a PIL Image object
41
  img = image_or_path
42
 
43
+ # Print image dimensions for debugging
44
+ print(f"Original image dimensions: {img.size}")
45
 
46
+ # Check image mode
47
+ if img.mode != "RGB":
48
+ img = img.convert("RGB")
49
+ print("Converted image mode to RGB.")
50
 
51
+ try:
52
+ # Resize the image
53
+ resized_img = img.resize((256, 256), Image.LANCZOS)
54
 
55
+ # Convert the image to a numpy array
56
+ img_array = np.array(resized_img)
57
 
58
+ # Normalize if necessary
59
+ img_array = img_array / 255.0
60
+
61
+ # Add a batch dimension
62
+ img_array = np.expand_dims(img_array, axis=0)
63
+
64
+ return img_array
65
+
66
+ except Exception as e:
67
+ print(f"Error encountered: {e}")
68
+ return None
69
 
70
  def model_arc():
71
  model = tf.keras.Sequential([