Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import os
- from tqdm import tqdm
- from sklearn.model_selection import train_test_split
- import scipy.misc
- from keras.layers import Dense, Flatten, Input, Conv2D, Conv2DTranspose, MaxPooling2D, UpSampling2D
- from keras.models import Model
- from PIL import Image
- from keras.utils import to_categorical
- from sklearn.utils import shuffle
- from keras.preprocessing.image import ImageDataGenerator
- from keras.preprocessing.image import array_to_img, img_to_array, load_img
- gen = ImageDataGenerator(
- rotation_range=20,
- width_shift_range=0.2,
- height_shift_range=0.2,
- horizontal_flip=True
- )
- APPLE_DIRECTORY = "./apple/"
- apple_images = []
- for apple_dir in tqdm(os.listdir(APPLE_DIRECTORY)):
- for apple in os.listdir(APPLE_DIRECTORY + '/' + apple_dir):
- if apple.endswith('_crop.png'):
- img = cv2.imread(APPLE_DIRECTORY + '/' + apple_dir + '/' + apple)
- img = cv2.resize(img, (92,92), interpolation = cv2.INTER_AREA)
- #img = img_to_array(load_img(APPLE_DIRECTORY + '/' + apple_dir + '/' + apple))
- img = img_to_array(img)
- img = img.reshape((1,) + img.shape)
- apple_images.append(img)
- #image= apple_images.reshape((1,)+ apple_images.shape)
- output_path = './apple_aug/apple_random{}.png'
- count =10
- # let's create infinite flow of images
- images_flow = gen.flow(img, batch_size=100)
- for i, new_images in enumerate(images_flow):
- # we access only first image because of batch_size=1
- new_image = array_to_img(new_images[0], scale=True)
- new_image.save(output_path.format(i + 1))
- if i >= count:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement