import tensorflow as tf
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
# Charger un modèle pré-entraîné pour la reconnaissance d'image
model = tf.keras.applications.VGG16(weights='imagenet', include_top=True)
# Fonction pour charger et prétraiter l'image
def load_and_preprocess_image(img_path):
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = tf.expand_dims(img_array, 0)
return tf.keras.applications.vgg16.preprocess_input(img_array)
# Fonction pour prédire les composants de l'image
def predict_components(img_path):
img = load_and_preprocess_image(img_path)
predictions = model.predict(img)
return tf.keras.applications.vgg16.decode_predictions(predictions, top=5)[0]
# Fonction pour générer un schéma (simplifié)
def generate_schema(predictions):
plt.figure(figsize=(10, 6))
plt.title("Generated Schema")
for pred in predictions:
plt.text(0.5, 0.5, pred[1], fontsize=12)
plt.show()
# Exemple d'utilisation
img_path = 'path_to_your_image.png'
predictions = predict_components(img_path)
generate_schema
-
Please log in to leave a comment!