Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 28, 2024
1 parent 1d192bb commit 74846d9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test_preprocess_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from model_optimization import \
preprocess_image # Replace with actual module name
import unittest
import numpy as np
from tensorflow.keras.preprocessing.image import img_to_array, load_img


def preprocess_image(image_path):
"""Preprocess the image for model prediction."""
try:
Expand All @@ -12,13 +16,14 @@ def preprocess_image(image_path):

image = img_to_array(image)
if image.shape != (224, 224, 3):
raise ValueError(f"Image shape is invalid. Expected (224, 224, 3), got {image.shape}.")
raise ValueError(
f"Image shape is invalid. Expected (224, 224, 3), got {image.shape}."
)

image = image / 255.0 # Normalize
image = np.expand_dims(image, axis=0)
return image
import unittest
from model_optimization import preprocess_image # Replace with actual module name


class TestPreprocessImage(unittest.TestCase):
def test_nonexistent_image_path(self):
Expand All @@ -37,5 +42,6 @@ def test_invalid_image_shape(self):
with self.assertRaises(ValueError):
preprocess_image("test_images/grayscale_image.jpg")


if __name__ == "__main__":
unittest.main()

0 comments on commit 74846d9

Please sign in to comment.