VishnuEcoClim commited on
Commit
aac970e
·
1 Parent(s): 9fc025f

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +18 -5
utils.py CHANGED
@@ -34,11 +34,24 @@ base_model = tf.keras.applications.ResNet50V2(include_top=False, input_shape=inp
34
  #Making the layers of the model trainable
35
  base_model.trainable = True
36
 
37
- def preprocess(img_path):
38
- img = Image.open(img_path).resize((256, 256), Image.LANCZOS)
39
- img_array = np.array(img)
40
- img_array = img_array / 255.0 # Normalize if necessary
41
- img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  return img_array
43
 
44
  def model_arc():
 
34
  #Making the layers of the model trainable
35
  base_model.trainable = True
36
 
37
+ def preprocess(image_or_path):
38
+ if isinstance(image_or_path, str): # Check if the input is a string (image path)
39
+ img = Image.open(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():