Spaces:
Running
Running
Commit
·
070cde2
1
Parent(s):
4e10fb1
Update utils.py
Browse files
utils.py
CHANGED
@@ -35,22 +35,11 @@ base_model = tf.keras.applications.ResNet50V2(include_top=False, input_shape=inp
|
|
35 |
base_model.trainable = True
|
36 |
|
37 |
def preprocess(img_path):
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# Convert the image to a TensorFlow tensor
|
44 |
-
img_tensor = tf.keras.preprocessing.image.img_to_array(img)
|
45 |
-
img_tensor = tf.expand_dims(img_tensor, axis=0) # Create a batch-like shape
|
46 |
-
|
47 |
-
# Apply rescaling (aligning with the training rescaling)
|
48 |
-
img_tensor = tf.keras.applications.resnet.preprocess_input(img_tensor)
|
49 |
-
|
50 |
-
return img_tensor
|
51 |
-
except Exception as e:
|
52 |
-
print(f"Error preprocessing image: {e}")
|
53 |
-
return None
|
54 |
|
55 |
def model_arc():
|
56 |
model = tf.keras.Sequential([
|
|
|
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([
|