Spaces:
Sleeping
Sleeping
fixing ensure img greyscaled
Browse files- app.py +1 -0
- modelbuilder.py +8 -5
app.py
CHANGED
|
@@ -43,6 +43,7 @@ for example in dataset:
|
|
| 43 |
# 3️⃣ Define preprocessing and inference function
|
| 44 |
# ------------------------------------------------------------
|
| 45 |
def preprocess_image(img: Image.Image):
|
|
|
|
| 46 |
img = img.resize(TARGET_SIZE, Image.BILINEAR) # resize image to (target_height, target_width)
|
| 47 |
img_array = img_to_array(img) / 255.0 # convert image to float32 NumPy array and normalize pixel values to [0, 1]
|
| 48 |
img_array = np.expand_dims(img_array, axis=0) # add batch dimension -> shape becomes (1, height, width, channels)
|
|
|
|
| 43 |
# 3️⃣ Define preprocessing and inference function
|
| 44 |
# ------------------------------------------------------------
|
| 45 |
def preprocess_image(img: Image.Image):
|
| 46 |
+
img = img.convert("L") # Ensure grayscale (1 channel): "L" = 8-bit grayscale
|
| 47 |
img = img.resize(TARGET_SIZE, Image.BILINEAR) # resize image to (target_height, target_width)
|
| 48 |
img_array = img_to_array(img) / 255.0 # convert image to float32 NumPy array and normalize pixel values to [0, 1]
|
| 49 |
img_array = np.expand_dims(img_array, axis=0) # add batch dimension -> shape becomes (1, height, width, channels)
|
modelbuilder.py
CHANGED
|
@@ -61,7 +61,7 @@ class ModelBuilder:
|
|
| 61 |
)
|
| 62 |
|
| 63 |
def get_augmentation_pipe(self):
|
| 64 |
-
# Random
|
| 65 |
# disabled during inference/evaluation
|
| 66 |
return Sequential(
|
| 67 |
[
|
|
@@ -78,12 +78,15 @@ class ModelBuilder:
|
|
| 78 |
|
| 79 |
# Define input layer
|
| 80 |
inputs = Input(shape=self.input_shape, name="inputs")
|
| 81 |
-
|
| 82 |
-
|
| 83 |
x_aug = self.get_augmentation_pipe()(
|
| 84 |
inputs
|
| 85 |
-
)
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# Model selector
|
| 89 |
match self.model_type:
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
def get_augmentation_pipe(self):
|
| 64 |
+
# Random/Augmentation layers are stochastic only when training=True
|
| 65 |
# disabled during inference/evaluation
|
| 66 |
return Sequential(
|
| 67 |
[
|
|
|
|
| 78 |
|
| 79 |
# Define input layer
|
| 80 |
inputs = Input(shape=self.input_shape, name="inputs")
|
| 81 |
+
|
| 82 |
+
# --- Random/Augmentation layers are stochastic only when training=True
|
| 83 |
x_aug = self.get_augmentation_pipe()(
|
| 84 |
inputs
|
| 85 |
+
)
|
| 86 |
+
# ----- end augmentation -----
|
| 87 |
+
|
| 88 |
+
# --- common preprocessing layer: rescaling to [0,1]
|
| 89 |
+
x = Rescaling(1.0 / 255)(x_aug)
|
| 90 |
|
| 91 |
# Model selector
|
| 92 |
match self.model_type:
|