-
Notifications
You must be signed in to change notification settings - Fork 11
/
DataAugmentation.txt
55 lines (41 loc) · 1.28 KB
/
DataAugmentation.txt
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
import os
import numpy as np
import cv2
from keras.preprocessing.image import ImageDataGenerator, load_img, image, img_to_array
DG_folder='DG_data'
images_increased = 5
try:
os.mkdir(DG_folder)
except:
print("")
train_datagen = ImageDataGenerator(
rotation_range=20,
zoom_range=0.2,
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=True,
vertical_flip=False)
data_path = "D:/Video Tutoriales/ImageClassification/dataset/train/AFRICAN FIREFINCH"
data_dir_list = os.listdir(data_path)
width_shape, height_shape = 224, 244
i=0
num_images=0
for image_file in data_dir_list:
img_list=os.listdir(data_path)
img_path = data_path + '/'+ image_file
imge=load_img(img_path)
imge=cv2.resize(image.img_to_array(imge), (width_shape, height_shape), interpolation = cv2.INTER_AREA)
x= imge/255
x=np.expand_dims(x,axis=0)
t=1
for output_batch in train_datagen.flow(x,batch_size=1):
a=image.img_to_array(output_batch[0])
imagen=output_batch[0,:,:]*255
imgfinal = cv2.cvtColor(imagen, cv2.COLOR_BGR2RGB)
cv2.imwrite(DG_folder+"/%i%i.jpg"%(i,t), imgfinal)
t+=1
num_images+=1
if t>images_increased:
break
i+=1
print("images generated",num_images)