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.
 
 
 

25 lines
917 B

  1. import requests
  2. from PIL import Image
  3. import os
  4. import json
  5. import tensorflow as tf
  6. import numpy as np
  7. from tensorflow.keras.preprocessing.image import ImageDataGenerator
  8. from tensorflow.keras.applications.vgg16 import preprocess_input
  9. if not os.path.isdir("data/vgg-16"):
  10. os.makedirs("data/vgg-16")
  11. species = os.listdir("data/cropped")
  12. for specie in species:
  13. if not os.path.isdir("data/vgg-16/"+specie):
  14. os.makedirs("data/vgg-16/"+specie)
  15. fichiers = os.listdir("data/cropped/"+specie)
  16. for fichier in fichiers:
  17. if not os.path.isfile("data/vgg-16/"+specie+"/"+fichier):
  18. image = Image.open("data/cropped/"+specie+"/"+fichier)
  19. zone_recadrage = (0, 0, 224, 224)
  20. image_recadree = image.crop(zone_recadrage)
  21. image_normalisee = preprocess_input(np.array(image_recadree))
  22. image_normalisee.save("data/vgg-16/"+specie+"/"+fichier)