-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtf-processingData.py
42 lines (31 loc) · 1.03 KB
/
tf-processingData.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
import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
DATA_DIR = "C:/Users/benca/africananmials" # Change this to your own personal directory containing data
CATEGORIES = ['buffalo', 'elephant', 'rhino', 'zebra']
dataset = []
IMG_SIZE = 100
def createDataset():
for animal in CATEGORIES:
path = os.path.join(DATA_DIR, animal)
class_num = CATEGORIES.index(animal)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path, img))
img_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
dataset.append([img_array, class_num])
except:
pass
createDataset()
import random as rand
rand.shuffle(dataset)
X = []
y = []
for features, labels in dataset:
X.append(features)
y.append(labels)
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 3)
# Save dataset
np.save('AfricanAnimalFeatures.npy',X)
np.save('AfricanAnimalLabels.npy',y)