Skip to content

Commit

Permalink
Create model_optimization.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsimran-Dalal authored Oct 28, 2024
1 parent b87a9ca commit d0884e1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions model_optimization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.preprocessing.image import img_to_array, load_img
import numpy as np

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)

0 comments on commit d0884e1

Please sign in to comment.