-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_csv.py
42 lines (32 loc) · 1019 Bytes
/
create_csv.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 pandas as pd
import numpy as np
import cv2
import os
IMG_WIDTH = 30
IMG_HEIGHT = 30
def load_data(data_dir="DATASET/TRAIN"):
X = []
y = []
os.chdir(data_dir)
parent_path = os.getcwd()
print(os.getcwd())
for category in os.listdir("."):
path = os.path.join(parent_path, category)
os.chdir(path)
print(f"Loading data for {path}")
for filename in os.listdir("."):
try:
image = cv2.imread(filename)
dimensions = (IMG_WIDTH, IMG_HEIGHT)
image = cv2.resize(image, dimensions, interpolation = cv2.INTER_AREA)
X.append(image)
y.append(str(category))
except:
print(filename)
return (X, y)
if __name__ == "__main__":
X, y = load_data()
X = [i[:, :, 0].reshape(900) for i in X]
df = pd.DataFrame(np.array(X))
df["y"] = y
df.to_csv(r"C:\Users\Manan Jhaveri\Desktop\yogyata\DATASET\data.csv", index=False)