classes = ["chien", "chat", "oiseau"]
img_width, img_height = 1600, 1200
DATA_DIR = [""] * len(classes)
SAVE_DIR = [""] * len(classes)
for i in range(len(classes)):
    DATA_DIR[i] = 'input/' + classes[i]
SAVE_DIR [i] = os.path.join ('output /', classes [i]) # Répertoire dans lequel l'image générée est enregistrée if not os.path.exists(SAVE_DIR[i]): os.makedirs(SAVE_DIR[i])
#Load image (image au format PIL) # img = load_img(IMAGE_FILE)
# plt.imshow(img)
# plt.show()
#Shear: cisaillement de -5 degrés à 5 degrés
datagen = ImageDataGenerator(
    rotation_range=15,
    height_shift_range=0.2,
    width_shift_range=0.2,
    shear_range=5,
    zoom_range=0.2,
   channel_shift_range=5,
   brightness_range=[0.3, 1.0]
)
for i in range(len(classes)):
    for picture in list_pictures(DATA_DIR[i]):
        img = img_to_array(load_img(picture, target_size=(img_height, img_width)))
Convertir en # tableau numpy x = img_to_array(img)
        # x = np.expand_dims(x, axis=0)
        x = x.reshape((1,) + x.shape)
        # print(x.shape)
        g = datagen.flow(x, batch_size=1, save_to_dir=SAVE_DIR[i], save_prefix='out', save_format='jpg')
        for j in range(3):
            batches = g.next()
            # print(batches.shape)
#Pour afficher sous forme d'image, passez des données 4D aux données 3D et passez d'un tableau à une image. gen_img = array_to_img(batches[0])
            # plt.subplot(8, 8, i + 1)
            # plt.imshow(gen_img)
            # plt.axis('off')
        Recommended Posts