# -*- coding: utf-8 -*-
"""
Created on Thu Aug 10 20:11:42 2017

@author: ksxl806
"""

def load_data(data_dir):
    # Get all subdirectories of data_dir. Each represents a label.
    directories = [d for d in os.listdir(data_dir) 
                   if os.path.isdir(os.path.join(data_dir, d))]
    # Loop through the label directories and collect the data in
    # two lists, labels and images.
    labels = []
    images = []
    for d in directories:
        label_dir = os.path.join(data_dir, d)
        file_names = [os.path.join(label_dir, f) 
                      for f in os.listdir(label_dir) 
                      if f.endswith(".ppm")]
        for f in file_names:
            images.append(data.imread(f))
            labels.append(int(d))
    return images, labels

ROOT_PATH = "C:/Users/ksxl806/Documents/PythonScripts/Datasets/BelgiumTSC/"

train_data_dir = os.path.join(ROOT_PATH, "BelgiumTSC_Testing/Testing")
test_data_dir = os.path.join(ROOT_PATH, "BelgiumTSC_Training/Training")

images, labels = load_data(train_data_dir)

images_array = np.array(images)
labels_array = np.array(labels)

# Print the `images` dimensions
print(images_array.ndim)

# Print the number of `images`'s elements
print(images_array.size)

# Print the first instance of `images`
images_array[0]

# Print the `labels` dimensions
print(labels_array.ndim)

# Print the number of `labels`'s elements
print(labels_array.size)

# Count the number of labels
print(len(set(labels_array)))