Spaces:
Running
Running
Commit
·
2e1dcb0
1
Parent(s):
cefb660
Update utils.py
Browse files
utils.py
CHANGED
@@ -34,8 +34,14 @@ 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(
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
img = img.resize((256, 256))
|
40 |
img_array = np.array(img)
|
41 |
img_array = np.expand_dims(img_array, axis=0)
|
|
|
34 |
#Making the layers of the model trainable
|
35 |
base_model.trainable = True
|
36 |
|
37 |
+
def preprocess(img_path_or_img):
|
38 |
+
if isinstance(img_path_or_img, str): # Check if input is a path
|
39 |
+
img = Image.open(img_path_or_img)
|
40 |
+
elif isinstance(img_path_or_img, Image.Image): # Check if input is already an Image object
|
41 |
+
img = img_path_or_img
|
42 |
+
else:
|
43 |
+
raise ValueError("Input must be a string path or a PIL Image object.")
|
44 |
+
|
45 |
img = img.resize((256, 256))
|
46 |
img_array = np.array(img)
|
47 |
img_array = np.expand_dims(img_array, axis=0)
|