VishnuEcoClim commited on
Commit
7b908dc
·
1 Parent(s): 413ef10

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +6 -35
utils.py CHANGED
@@ -34,41 +34,12 @@ 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(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
- elif isinstance(image_or_path, np.ndarray): # Check if the input is a numpy array
41
- # Convert the numpy array to a PIL Image
42
- img = Image.fromarray((image_or_path * 255).astype(np.uint8))
43
- else:
44
- raise ValueError("Unsupported input type. Expected string path or numpy array.")
45
-
46
- # Print image dimensions for debugging
47
- print(f"Original image dimensions: {img.size}")
48
-
49
- # Check image mode
50
- if img.mode != "RGB":
51
- img = img.convert("RGB")
52
- print("Converted image mode to RGB.")
53
-
54
- try:
55
- # Resize the image
56
- resized_img = img.resize((256, 256), Image.LANCZOS)
57
-
58
- # Convert the image to a numpy array
59
- img_array = np.array(resized_img)
60
-
61
- # Normalize if necessary
62
- img_array = img_array / 255.0
63
-
64
- # Add a batch dimension
65
- img_array = np.expand_dims(img_array, axis=0)
66
-
67
- return img_array
68
-
69
- except Exception as e:
70
- print(f"Error encountered: {e}")
71
- return None
72
 
73
  def model_arc():
74
  model = tf.keras.Sequential([
 
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)
39
+ img = img.resize((256, 256))
40
+ img_array = np.array(img)
41
+ img_array = np.expand_dims(img_array, axis=0)
42
+ return img_array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  def model_arc():
45
  model = tf.keras.Sequential([