Spaces:
Sleeping
Sleeping
Delete src/data_preperation.py
Browse files- src/data_preperation.py +0 -57
src/data_preperation.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
from src import utils
|
| 2 |
-
import numpy as np
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def main(in_dir: str, out_dir: str, size: tuple, stride: tuple, classes: list):
|
| 7 |
-
# Read all files in the in_dir
|
| 8 |
-
files = os.listdir(in_dir)
|
| 9 |
-
|
| 10 |
-
# Create the out_dir if it does not exist
|
| 11 |
-
if not os.path.exists(out_dir):
|
| 12 |
-
os.makedirs(out_dir)
|
| 13 |
-
|
| 14 |
-
dataset = []
|
| 15 |
-
# Loop through all files in the in_dir
|
| 16 |
-
for file in files:
|
| 17 |
-
# apply the sliding window method to each file
|
| 18 |
-
imgs = os.listdir(in_dir + file)
|
| 19 |
-
for img in imgs:
|
| 20 |
-
path = in_dir + file + "/" + img
|
| 21 |
-
data, _ = utils.sliding_window(path, window_size=size, stride=stride)
|
| 22 |
-
|
| 23 |
-
for x in data:
|
| 24 |
-
dataset.append((np.array(x[0]), classes.index(file)))
|
| 25 |
-
|
| 26 |
-
# Split the dataset into training, validation, and test sets
|
| 27 |
-
train, val, test = utils.split_data(dataset, 0.7, 0.1, 0.2)
|
| 28 |
-
utils.plot_distribution(
|
| 29 |
-
train, val, test, classes, title="Data Distribution Before Balancing"
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# Balance the dataset
|
| 33 |
-
train, excess_data = utils.balance_data(train)
|
| 34 |
-
test += excess_data
|
| 35 |
-
utils.plot_distribution(
|
| 36 |
-
train, val, test, classes, title="Data Distribution After Balancing"
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
# Shuffle the data
|
| 40 |
-
train = utils.shuffle_data(train)
|
| 41 |
-
val = utils.shuffle_data(val)
|
| 42 |
-
test = utils.shuffle_data(test)
|
| 43 |
-
|
| 44 |
-
# Pickle the data
|
| 45 |
-
utils.save_to_pickle(train, out_dir + "/train.pkl")
|
| 46 |
-
utils.save_to_pickle(val, out_dir + "/val.pkl")
|
| 47 |
-
utils.save_to_pickle(test, out_dir + "/test.pkl")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
if __name__ == "__main__":
|
| 51 |
-
main(
|
| 52 |
-
in_dir="raw_data/high_res/",
|
| 53 |
-
out_dir="data/high_res/",
|
| 54 |
-
size=(224, 224),
|
| 55 |
-
stride=(224, 224),
|
| 56 |
-
classes=["formal", "informal"],
|
| 57 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|