1. import tensorflow as tf
  2. from tensorflow.keras.preprocessing import image
  3. import matplotlib.pyplot as plt
  4. # Charger un modèle pré-entraîné pour la reconnaissance d'image
  5. model = tf.keras.applications.VGG16(weights='imagenet', include_top=True)
  6. # Fonction pour charger et prétraiter l'image
  7. def load_and_preprocess_image(img_path):
  8. img = image.load_img(img_path, target_size=(224, 224))
  9. img_array = image.img_to_array(img)
  10. img_array = tf.expand_dims(img_array, 0)
  11. return tf.keras.applications.vgg16.preprocess_input(img_array)
  12. # Fonction pour prédire les composants de l'image
  13. def predict_components(img_path):
  14. img = load_and_preprocess_image(img_path)
  15. predictions = model.predict(img)
  16. return tf.keras.applications.vgg16.decode_predictions(predictions, top=5)[0]
  17. # Fonction pour générer un schéma (simplifié)
  18. def generate_schema(predictions):
  19. plt.figure(figsize=(10, 6))
  20. plt.title("Generated Schema")
  21. for pred in predictions:
  22. plt.text(0.5, 0.5, pred[1], fontsize=12)
  23. plt.show()
  24. # Exemple d'utilisation
  25. img_path = 'path_to_your_image.png'
  26. predictions = predict_components(img_path)
  27. generate_schema
 
 

88

Pasted Text #34289

-

PasteBin

Lines
32
Words
99
Size
1.2 KB
Created
Type
text/plain
Creative Commons Attribution Share-Alike 4.0 (CC-BY-SA 4.0)
Please log in to leave a comment!