Пример #1
0
from PIL import Image
import torchvision.transforms as transforms
import torch 

kOutputDirectory = "C:\\temp\\visualize\\torch"

import MachineLearningCourse.MLUtilities.Visualizations.Charting as Charting

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

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

featurizer = BlinkFeaturize.BlinkFeaturize()

sampleStride = 2
featurizer.CreateFeatureSet(xTrainRaw, yTrain, includeEdgeFeatures=False, includeIntensities=True, intensitiesSampleStride=sampleStride)

xTrain_pretorch    = featurizer.Featurize(xTrainRaw)
xValidate_pretorch = featurizer.Featurize(xValidateRaw)
xTest_pretorch     = featurizer.Featurize(xTestRaw)

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

# xTrainImages = [ Image.open(path) for path in xTrainRaw ]
Пример #2
0
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

import MachineLearningCourse.MLUtilities.Learners.BoostedTree as BoostedTree
import MachineLearningCourse.MLUtilities.Evaluations.ErrorBounds as ErrorBounds
import MachineLearningCourse.MLUtilities.Evaluations.EvaluateBinaryClassification as EvaluateBinaryClassification
import MachineLearningCourse.MLUtilities.Visualizations.Charting as Charting

tuneRounds = False
if tuneRounds:

    featurizer = BlinkFeaturize.BlinkFeaturize()

    #featurizer.CreateFeatureSet(xTrainRaw, yTrain, includeEdgeFeatures=True)
    #filename = "1-BlinkBoostedTreeEdgeFilterFeaturesOnly-Rounds" 
    featurizer.CreateFeatureSet(xTrainRaw, yTrain, includeEdgeFeatures=True, includeEdgeFeaturesMax=True)
    filename = "1-BlinkBoostedTreeEdgeFilterMaxAndAvg-Rounds"

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

    bestModelBT = None
    kValues = [1, 10, 50, 100, 150]
    maxDepth = 1
    validationAccuracies = []
    validationAccuracyErrorBounds = []