1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| from keras.preprocessing.image import ImageDataGenerator from keras.preprocessing.image import img_to_array from keras.preprocessing.image import load_img import numpy as np import argparse
from keras_util import *
ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="path to the input image") ap.add_argument("-o", "--output", required=True, help="path to output directory to store augmentation examples") ap.add_argument("-p", "--prefix", type=str, default="image", help="output filename prefix") args = vars(ap.parse_args())
print("[INFO] loading example image...") target_size = None
image = load_img(args["image"], target_size=target_size) image = img_to_array(image) image = np.expand_dims(image, axis=0)
aug = ImageDataGenerator(preprocessing_function=resnet.preprocess_input, rotation_range=30, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode="nearest") total = 0
print("[INFO] generating images...") imageGen = aug.flow(image, batch_size=1, save_to_dir=args["output"], save_prefix=args["prefix"], save_format="png")
next_image = next(imageGen) print(next_image.shape) print(next_image[0, :5,:5,0])
for image in imageGen: total += 1
if total == 10: break
|