-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_Augmentation.py
More file actions
79 lines (51 loc) · 2.07 KB
/
image_Augmentation.py
File metadata and controls
79 lines (51 loc) · 2.07 KB
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
70
71
72
73
74
75
76
import pickle
from keras.utils import np_utils
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
import csv
from keras.preprocessing.image import ImageDataGenerator
import scipy.misc
file = open('/Users/thomasbekman/Documents/Homework/Deep_Learning/Final_Project/ForestFireClassification/data.pkl','rb')
data = pickle.load(file)
xTrain = data["image"]
yTrain = data["label"]
new_y =[]
# tokenize the labels
for i in yTrain:
if(i == '-Fire-Smoke'):
new_y.append(0)
elif (i == '-Fire+Smoke'):
new_y.append(1)
elif (i == '+Fire+Smoke'):
new_y.append(2)
y_train_f = np_utils.to_categorical(new_y, 3)
datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=15,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
fill_mode='wrap')
with open('aug_labels.csv', 'w', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
with open('labels1.csv', newline='') as f:
reader = csv.reader(f)
for j in range(1,688):
img = load_img(
'/Users/thomasbekman/Documents/Homework/Deep_Learning/Final_Project/ForestFireClassification/images/' +str(j) + '.jpg')
x = img_to_array(img) # creating a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape) # converting to a Numpy array with shape (1, 3, 150, 150)
row1 = next(reader)
label = row1[1]
print("We are on image: "+str(j))
print("The associated label in the original CSV is: "+str(row1[0]))
print("The label is: "+ label)
i = 0
for batch in datagen.flow(x,save_to_dir='preview', save_prefix=str(j)+"___", save_format='jpeg'):
rowToWrite = []
rowToWrite.append(str(j))
rowToWrite.append(label)
spamwriter.writerow(rowToWrite)
i += 1
if i > 19:
break