diff --git a/__pycache__/read_cifar.cpython-311.pyc b/__pycache__/read_cifar.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3c4534351e5e03b53d76e9087a1ffc193f08cd06 Binary files /dev/null and b/__pycache__/read_cifar.cpython-311.pyc differ diff --git a/read_cifar.py b/read_cifar.py index c8cedb06042955a3dd45553a657c7b859909e020..ffd06f32fece9d1ecec27b069ae333295cacb69e 100644 --- a/read_cifar.py +++ b/read_cifar.py @@ -1,4 +1,8 @@ import numpy as np +import pickle +from sklearn.model_selection import train_test_split +import pandas as pd + import pickle @@ -12,4 +16,37 @@ def read_cifar_batch(batch_path): return data, labels -print(read_cifar_batch('Data/cifar-10-batches-py/data_batch_2')) \ No newline at end of file + +def read_cifar(path): + data = [] + labels = [] + + #Add the 5 batches + for i in range(1,6): + data_temp, labels_temp = read_cifar_batch(f'{path}/data_batch_{i}') + data.append(data_temp) + labels.append(labels_temp) + + #Add the test batches + data_temp, labels_temp = read_cifar_batch(f'{path}/test_batch') + data.append(data_temp) + labels.append(labels_temp) + + #Concatenate all the batches to create a big one + data = np.concatenate(data, axis = 0) + labels = np.concatenate(labels, axis = 0) + + return(data, labels) + +def split_dataset(data, labels, split): + X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=(1 - split), random_state=0) + + return(X_train, X_test, y_train, y_test) + + +if __name__== '__main__': + + data, labels = read_cifar_batch('Data/cifar-10-batches-py/data_batch_1') + data, labels = read_cifar('/Users/milancart/Documents/GitHub/image-classification/Data/cifar-10-batches-py') + X_train, X_test, y_train, y_test = split_dataset(data, labels, 0.8) + print(X_train, X_test, y_train, y_test) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000000000000000000000000000000000000..c6e72d1c3a89c46895dd871416778e1371edb0cd --- /dev/null +++ b/test.py @@ -0,0 +1,2 @@ +import read_cifar +