import MachineLearningCourse.MLProjectSupport.Blink.BlinkDataset as BlinkDataset

(xRaw, yRaw) = BlinkDataset.LoadRawData()

import MachineLearningCourse.MLUtilities.Data.Sample as Sample

(xTrainRaw, yTrain, xValidateRaw, yValidate, xTestRaw,
 yTest) = Sample.TrainValidateTestSplit(xRaw, yRaw)

print("Train is %d samples, %.4f percent opened." %
      (len(yTrain), 100.0 * sum(yTrain) / len(yTrain)))
print("Validate is %d samples, %.4f percent opened." %
      (len(yValidate), 100.0 * sum(yValidate) / len(yValidate)))
print("Test is %d samples %.4f percent opened" %
      (len(yTest), 100.0 * sum(yTest) / len(yTest)))

from PIL import Image
import torchvision.transforms as transforms
import torch

##
# Load the images, normalize and convert them into tensors
##

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize(mean=[0.], std=[0.5])])

xTrainImages = [Image.open(path) for path in xTrainRaw]
xTrain = torch.stack([transform(image) for image in xTrainImages])
kOutputDirectory = "C:\\temp\\visualize"

import MachineLearningCourse.MLProjectSupport.Blink.BlinkDataset as BlinkDataset

### UPDATE this path for your environment
kDataPath = "MachineLearningCourse\\MLProjectSupport\\Blink\\dataset\\"

(xRaw, yRaw) = BlinkDataset.LoadRawData(kDataPath)

import MachineLearningCourse.MLUtilities.Data.Sample as Sample

(xTrainRaw, yTrain, xValidateRaw, yValidate, xTestRaw,
 yTest) = Sample.TrainValidateTestSplit(xRaw, yRaw)

print("Train is %d samples, %.4f percent opened." %
      (len(yTrain), 100.0 * sum(yTrain) / len(yTrain)))
print("Validate is %d samples, %.4f percent opened." %
      (len(yValidate), 100.0 * sum(yValidate) / len(yValidate)))
print("Test is %d samples %.4f percent opened" %
      (len(yTest), 100.0 * sum(yTest) / len(yTest)))

import MachineLearningCourse.Assignments.Module03.SupportCode.BlinkFeaturize as BlinkFeaturize

featurizer = BlinkFeaturize.BlinkFeaturize()

featurizer.CreateFeatureSet(xTrainRaw, yTrain, includeEdgeFeatures=True)

xTrain = featurizer.Featurize(xTrainRaw)
xValidate = featurizer.Featurize(xValidateRaw)
xTest = featurizer.Featurize(xTestRaw)