You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
921 B
33 lines
921 B
import cv2
|
|
import numpy as np
|
|
from tensorflow.keras.models import load_model
|
|
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
|
from tensorflow.keras.losses import MeanSquaredError
|
|
from tensorflow.keras.utils import get_custom_objects
|
|
|
|
def mse(y_true, y_pred):
|
|
return MeanSquaredError()(y_true, y_pred)
|
|
|
|
get_custom_objects().update({"mse": mse})
|
|
|
|
def predict_age(model, image_path):
|
|
img = load_img(image_path, target_size=(128, 128))
|
|
img_array = img_to_array(img) / 255.0
|
|
|
|
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
predicted_age = model.predict(img_array)
|
|
|
|
return predicted_age[0][0]
|
|
|
|
def main():
|
|
model_path = "face_aging_model.h5"
|
|
image_path = "visage.jpg"
|
|
|
|
model = load_model(model_path, custom_objects={"mse": mse})
|
|
|
|
age = predict_age(model, image_path)
|
|
print(f"L'âge prédit est: {age}")
|
|
|
|
if __name__ == "__main__":
|
|
main() |