-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcracks.py
58 lines (44 loc) · 1.69 KB
/
cracks.py
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
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Dense, Flatten, BatchNormalization, Conv2D, MaxPool2D
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from sklearn.metrics import confusion_matrix
import itertools
import shutil
import random
import glob
import matplotlib.pyplot as plt
import os
import pandas as pd
import cv2
import pickle
######################################################################################################################
DIRECTORY = "C:\\Users\\Steven_Verkest\\Documents\\INF_STUDY\\BECODE\\PROJECT_SKYEBASE\\DATASET_KAGGLE"
CATEGORIES = ['Negative','Positive']
IMG_SIZE = 100 #in order for CNN to be trained properly image size have to been similar across al the photos, play around with pixel size
data = []
for category in CATEGORIES:
folder = os.path.join(DIRECTORY,category)
label = CATEGORIES.index(category) #give label to
for img in os.listdir(folder):
img_path = os.path.join(folder,img)
img_arr = cv2.imread(img_path)
img_arr = cv2.resize(img_arr,(IMG_SIZE,IMG_SIZE)) #resize pixels so all image are same pixel_size
data.append([img_arr, label])
print(len(data))
random.shuffle(data)
#print(data[0])
X = []
y = []
for features,labels in data:
X.append(features)
y.append(labels)
X = np.array(X)
y = np.array(y)
#print(len(X))
pickle.dump(X,open('X_cracks.pkl','wb'))
pickle.dump(y,open('y_cracks.pkl','wb'))