Пример #1
0
    def run(self):
        """
        Function: Run
        -------------
        This function will evaluate your solution! You do not need to
        write any code in this file, however you SHOULD understand this
        function!
        """
        print "Running the full pipeline!"
        K=25
        trainImages = util.loadTrainImages()[:1000]
        testImages = util.loadTestImages()

        classifier = Classifier()

        print 'Training..........'
        classifier.train(trainImages, K)

        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'Testing...........'
        testPredictions = classifier.test(testImages)
        testAccuracy = self.evaluate(testPredictions, testImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')
        self.reportAccuracy(testAccuracy, 'Test Accuracy')
def run(grad,view,pixels,maxIter,numTrain):
    k = 25
    maxIter_kMeans = 20

    trainUImages = util.loadTrainImages()[:numTrain]
    trainSImages = trainUImages[:500]
    testImages = util.loadTestImages()

    if pixels is False:
        # Compile all patches into one big 2-D array (patchSize x numPatches)
        patches = np.hstack([np.array(image.getPatches()).transpose() for image in trainUImages])
        print("Training K-means using %d images..." % numTrain)
        centroids = submission.runKMeans(k,patches,maxIter_kMeans)
        print("Finished running K-means")
        if view:
            util.viewPatches(centroids)
        trainX,trainY = util.kMeansFeatures(trainSImages,centroids,submission.extractFeatures)
        testX, testY = util.kMeansFeatures(testImages,centroids,submission.extractFeatures)
    else:
        maxIter = 100
        trainX,trainY = util.pixelFeatures(trainSImages)
        testX,testY = util.pixelFeatures(testImages)

    clf = util.Classifier(maxIter=maxIter,alpha=5e-5,gradient=grad)
    print("Training supervised classifier with %d images..."%len(trainSImages))
    clf.train(trainX,trainY)

    predictions = clf.test(trainX)
    acc = np.sum(trainY==predictions)/float(trainY.size)
    print("Train accuracy is %f"%acc)

    predictions = clf.test(testX)
    acc = np.sum(testY==predictions)/float(testY.size)
    print("Test accuracy is %f"%acc)
Пример #3
0
    def run(self):
        """
        Function: Run
        -------------
        This function will evaluate your solution! You do not need to
        write any code in this file, however you SHOULD understand this
        function!
        """
        print "Running the full pipeline!"
        K = 25
        trainImages = util.loadTrainImages()[:1000]
        testImages = util.loadTestImages()

        classifier = Classifier()

        print 'Training..........'
        classifier.train(trainImages, K)

        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'Testing...........'
        testPredictions = classifier.test(testImages)
        testAccuracy = self.evaluate(testPredictions, testImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')
        self.reportAccuracy(testAccuracy, 'Test Accuracy')
Пример #4
0
def run(grad,view,pixels,maxIter,numTrain):
    k = 25
    maxIter_kMeans = 20

    trainUImages = util.loadTrainImages()[:numTrain]
    trainSImages = trainUImages[:500]
    testImages = util.loadTestImages()

    if pixels is False:
        # Compile all patches into one big 2-D array (patchSize x numPatches)
        patches = np.hstack([np.array(image.getPatches()).transpose() for image in trainUImages])
        print "Training K-means using %d images"%numTrain
        centroids = submission.runKMeans(k,patches,maxIter_kMeans)
        trainX,trainY = util.kMeansFeatures(trainSImages,centroids,submission.extractFeatures)
        testX, testY = util.kMeansFeatures(testImages,centroids,submission.extractFeatures)
        if view:
            util.viewPatches(centroids)
    else:
        maxIter = 100
        trainX,trainY = util.pixelFeatures(trainSImages)
        testX,testY = util.pixelFeatures(testImages)

    clf = util.Classifier(maxIter=maxIter,alpha=5e-5,gradient=grad)
    clf.train(trainX,trainY)

    predictions = clf.test(trainX)
    acc = np.sum(trainY==predictions)/float(trainY.size)
    print "Train accuracy is %f"%acc

    predictions = clf.test(testX)
    acc = np.sum(testY==predictions)/float(testY.size)
    print "Test accuracy is %f"%acc
Пример #5
0
    def runDev(self):
        print "Running in development mode"

        K=5
        trainImages = util.loadTrainImages()[:100]
        testImages = util.loadTestImages()[:100]
        
        classifier = Classifier()
        
        print 'Training..........'
        classifier.train(trainImages, K)
        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')
Пример #6
0
    def run(self):
        print "Running the full pipeline!"
        K=25
        trainImages = util.loadTrainImages()[:1000]
        testImages = util.loadTestImages()

        classifier = Classifier()

        print 'Training..........'
        classifier.train(trainImages, K)

        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'Testing...........'
        testPredictions = classifier.test(testImages)
        testAccuracy = self.evaluate(testPredictions, testImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')
        self.reportAccuracy(testAccuracy, 'Test Accuracy')
Пример #7
0
    def runDev(self):
        """
        Function: runDev
        -------------
        This function will run the full pipeline in development mode.
        I.e. it will use only 10 centroids and 100 images.
        """
        print "Running in development mode"

        K=5
        trainImages = util.loadTrainImages()[:100]
        testImages = util.loadTestImages()[:100]
        
        classifier = Classifier()
        
        print 'Training..........'
        classifier.train(trainImages, K)
        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')
Пример #8
0
    def runDev(self):
        """
        Function: runDev
        -------------
        This function will run the full pipeline in development mode.
        I.e. it will use only 10 centroids and 100 images.
        """
        print "Running in development mode"

        K = 5
        trainImages = util.loadTrainImages()[:100]
        testImages = util.loadTestImages()[:100]

        classifier = Classifier()

        print 'Training..........'
        classifier.train(trainImages, K)
        trainPredictions = classifier.test(trainImages)
        trainAccuracy = self.evaluate(trainPredictions, trainImages)

        print 'All done. Here is your summary:'
        self.reportAccuracy(trainAccuracy, 'Train Accuracy')