Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open source #106

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions model_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.preprocessing.image import img_to_array, load_img


def load_optimized_model():
model = MobileNetV2(
weights="imagenet", include_top=False, input_shape=(224, 224, 3)
)
print("Loaded MobileNetV2 model for optimized face detection.")
return model


def preprocess_image(image_path):
image = load_img(image_path, target_size=(224, 224))
image = img_to_array(image)
image = image / 255.0 # Normalize image
image = np.expand_dims(image, axis=0)
return image


# Example usage
if __name__ == "__main__":
model = load_optimized_model()
preprocessed_image = preprocess_image("path/to/sample_image.jpg")
features = model.predict(preprocessed_image)
print("Extracted features:", features)
55 changes: 55 additions & 0 deletions test_face_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import unittest

from face_recognition_module import \
detect_faces # Replace with the actual module name


class TestFaceDetection(unittest.TestCase):
def test_invalid_image_path(self):
"""Test case for an invalid image path."""
invalid_path = "non_existent_directory/non_existent_image.jpg"
with self.assertRaises(FileNotFoundError):
detect_faces(invalid_path)

def test_corrupted_image_file(self):
"""Test case for a corrupted image file."""
# Create a corrupted image file for testing
corrupted_image_path = "test_images/corrupted_image.jpg"
with open(corrupted_image_path, "w") as f:
f.write("This is not a valid image content")

with self.assertRaises(ValueError):
detect_faces(corrupted_image_path)

# Clean up the corrupted image file after testing
os.remove(corrupted_image_path)

def test_unsupported_image_format(self):
"""Test case for an unsupported image format."""
unsupported_image_path = "test_images/sample.txt"
# Create a text file to simulate an unsupported image format
with open(unsupported_image_path, "w") as f:
f.write("This is a text file, not an image.")

with self.assertRaises(ValueError):
detect_faces(unsupported_image_path)

# Clean up the text file after testing
os.remove(unsupported_image_path)

def test_empty_image_file(self):
"""Test case for an empty image file."""
empty_image_path = "test_images/empty_image.jpg"
# Create an empty file
open(empty_image_path, "w").close()

with self.assertRaises(ValueError):
detect_faces(empty_image_path)

# Clean up the empty image file after testing
os.remove(empty_image_path)


if __name__ == "__main__":
unittest.main()
27 changes: 27 additions & 0 deletions test_face_recognition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from face_recognition_module import detect_faces, generate_embeddings


class TestFaceRecognition(unittest.TestCase):
def test_detect_faces(self):
# Test with a sample image
image_path = "test_images/sample.jpg"
faces = detect_faces(image_path)
self.assertGreater(
len(faces), 0, "No faces detected in the sample image.")

def test_generate_embeddings(self):
# Test with a dummy face data
face_data = "sample_face_data"
embedding = generate_embeddings(face_data)
self.assertIsNotNone(
embedding, "Embedding generation failed for the given face data."
)
self.assertEqual(
len(embedding), 128, "Embedding length should be 128 dimensions."
) # Example dimension


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