Spaces:
Running
Running
Commit
·
22d0d15
1
Parent(s):
be1ea43
Update utils.py
Browse files
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 |
-
#
|
44 |
-
|
45 |
|
46 |
-
#
|
47 |
-
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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([
|