Ejemplo n.º 1
0
    def _new_epoch(self):
        start_time = time.time()
        np.random.shuffle(self.indexs)
        self.data = []
        self.scores = []
        total_correct = 0.0
        for i in xrange(self.opt.training_images):
            curi = self.indexs[i]
            rgb = cv2.imread(
                path.join(self.opt.dataset_dir, self.rgb_paths[curi]))
            pose = getInfo(
                path.join(self.opt.dataset_dir, self.pose_paths[curi]))
            sampling, patches = stochasticSubSample(rgb, self.opt.obj_size,
                                                    self.opt.input_size)
            estObj = getCoordImg(patches, self.sess, self.ol, self.opt)
            estObj = estObj.reshape(-1, 3)

            for h in xrange(self.opt.training_hyps):
                diffMap, score, correct = createScore(pose, estObj, sampling)
                self.data.append(diffMap.reshape(40, 40, 1))
                self.scores.append(score.reshape(1))
                total_correct += correct

        self.step = 0
        if self.opt.time_info:
            print "Generated {} patches ({:2f}% correct) in {}s".format(
                len(self.data), total_correct / len(self.data) * 100.0,
                time.time() - start_time)
    def loadInfo(self, csvInput):

        getInfo = utils.getInfo(csvInput)

        try:
            studentID = next(getInfo)
            questionsID = next(getInfo)
            correct = next(getInfo)
        except:
            # print ('Execption occurs in function--loadInfo')
            return None

#       print ('-------------loadInfo begin-----------')
        n = int(studentID[0])
        #       print ('studentID[0] is',n)
        #       print ('-------------------------------------')

        newID = [
        ]  # to replace questionSet by simplifying each questions serial number

        # use replacement to shorten one hot list length
        for i in range(len(questionsID)):
            if not questionsID[i] in self.questions:
                self.questions.update({questionsID[i]: self.n_questions})
                self.n_questions += 1
            newID.append(self.questions[questionsID[i]])


#        print ('questionSet is ',questionSet)
#        print ('-------------------------------------')
#        print ('newQuestionSet is',newQuestionSet)
#        print ('-------------------------------------')

        stu = student(n, newID, correct)
        return stu
Ejemplo n.º 3
0
def update():
    information = utils.getInfo()
    print information
    return json.dumps(information)
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
"""
    main
"""

import time
import utils
import config

while True:
    try:
        time.sleep(config.REFRESH)
        print(50 * "\n")
        url = config.URL
        samples = utils.parserHtml(utils.getInfo(url))
        for tram in samples:
            print(utils.clean(tram.text))
        print(1 * "\n")
    except ConnectionError:
        print(50 * "\n")
        print("Tram doesn´t exist anymore!")
        print(1 * "\n")
Ejemplo n.º 5
0
def main():
    """ Driver.py """
    upperCaseLettersInfoFile = 'info_1.csv'
    greekLettersInfoFile = 'info_2.csv'

    trainingData1File = 'train_1.csv'
    trainingData2File = 'train_2.csv'

    val1File = 'val_1.csv'
    val2File = 'val_2.csv'

    testWithLabel1File = 'test_with_label_1.csv'
    testWithLabel2File = 'test_with_label_2.csv'

    baseDTFile1 = 'Base-DT-DS1.csv'
    baseDTFile2 = 'Base-DT-DS2.csv'

    bestDTFile1 = 'Best-DT-DS1.csv'
    bestDTFile2 = 'Best-DT-DS2.csv'


    upperCaseLettersDict = utils.getInfo(upperCaseLettersInfoFile)
    greekLettersDict = utils.getInfo(greekLettersInfoFile)

    #Get data uses Pandas library. Returns 2d array with column headers in first row
    trainingData1 = utils.getData(trainingData1File)
    trainingData2 = utils.getData(trainingData2File)
    #Generating our ML Models
    baseDTUpperCase = decisionTree.generateBaseDT(trainingData1)
    baseDTGreek = decisionTree.generateBaseDT(trainingData2)
    bestDTUpperCase = decisionTree.generateBestDT(trainingData1)
    bestDTGreek = decisionTree.generateBestDT(trainingData2)
    
    val1Data = utils.getData(val1File)
    val2Data = utils.getData(val2File)
    testWithLabel1 = utils.getData(testWithLabel1File)
    testWithLabel2 = utils.getData(testWithLabel2File)

    utils.plotInstances(trainingData1, upperCaseLettersDict, 'Uppercase Letters', 'Training', 'trainingUppercase')
    utils.plotInstances(trainingData2, greekLettersDict, 'Greek Letters', 'Training', 'trainingGreek')
    utils.plotInstances(val1Data, upperCaseLettersDict, 'Uppercase Letters', 'Validation', 'validationUppercase')
    utils.plotInstances(val2Data, greekLettersDict, 'Greek Letters', 'Validation', 'validationGreek')
    utils.plotInstances(testWithLabel1, upperCaseLettersDict, 'Uppercase Letters', 'Test', 'testUppercase')
    utils.plotInstances(testWithLabel2, greekLettersDict, 'Greek Letters', 'Test', 'testGreek')

    print('Running Validation for Base DT - Upper Case Letters...')
    utils.testModel(baseDTUpperCase, val1Data)
    print('Running Validation for Best DT - Upper Case Letters...')
    utils.testModel(bestDTUpperCase, val1Data)

    print('\nRunning Tests for Base DT - Upper Case Letters...')
    baseDTRes1 = utils.testModel(baseDTUpperCase, testWithLabel1)
    utils.writeMLResults(baseDTRes1, baseDTFile1)
    print('Running Tests for Best DT - Upper Case Letters...')
    bestDTRes1 = utils.testModel(bestDTUpperCase, testWithLabel1)
    utils.writeMLResults(bestDTRes1, bestDTFile1)
    
    print('\nRunning Validation for Base DT - Greek Letters...')
    utils.testModel(baseDTGreek, val2Data)
    print('Running Validation for Best DT - Greek Letters...')
    utils.testModel(bestDTGreek, val2Data)
    
    print('\nRunning Tests for Base DT - Greek Letters...')
    baseDTRes2 = utils.testModel(baseDTGreek, testWithLabel2)
    utils.writeMLResults(baseDTRes2, baseDTFile2)
    print('Running Tests for Best DT - Greek Letters...')
    bestDTRes2 = utils.testModel(bestDTGreek, testWithLabel2)
    utils.writeMLResults(bestDTRes2, bestDTFile2)

    utils.plotConfusionMatrix(baseDTUpperCase, testWithLabel1, upperCaseLettersDict, 'Base DT Uppercase Letters' ,'Base-DT-DS1-CM')
    utils.plotConfusionMatrix(baseDTGreek, testWithLabel2, greekLettersDict, 'Base DT Greek Letters' ,'Base-DT-DS2-CM')
    utils.plotConfusionMatrix(bestDTUpperCase, testWithLabel1, upperCaseLettersDict, 'Best DT Uppercase Letters' ,'Best-DT-DS1-CM')
    utils.plotConfusionMatrix(bestDTGreek, testWithLabel2, greekLettersDict, 'Best DT Greek Letters' ,'Best-DT-DS2-CM')

    utils.getClassificationReport(baseDTUpperCase, testWithLabel1, upperCaseLettersDict, 'Base DT Uppercase Letters' ,'Base-DT-DS1-Report')
    utils.getClassificationReport(baseDTGreek, testWithLabel2, greekLettersDict, 'Base DT Greek Letters' ,'Base-DT-DS2-Report')
    utils.getClassificationReport(bestDTUpperCase, testWithLabel1, upperCaseLettersDict, 'Base DT Uppercase Letters' ,'Best-DT-DS1-Report')
    utils.getClassificationReport(bestDTGreek, testWithLabel2, greekLettersDict, 'Base DT Greek Letters' ,'Best-DT-DS2-Report')
Ejemplo n.º 6
0
def update():
    information = utils.getInfo()
    print information
    return json.dumps(information)
Ejemplo n.º 7
0
    raw_input(
        "1:\tPrivate Key\n2:\tWallet Import Format Private Key\n3:\tPublic Key\n\n[ ] Enter selection: "
    ))

print

if q == 1:
    priv_key = raw_input("[ ] Enter Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(priv_key))
    print
    print "Address: " + address
    print "Private Key: " + priv_key
    print "Wallet Import Format Private Key: " + utils.privateKeyToWif(
        priv_key)
    print "Public Key: " + utils.privateKeyToPublicKey(priv_key)
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 2:
    wif_priv_key = raw_input("[ ] Enter Wallet Import Format Private Key: ")
    address = utils.pubKeyToAddr(
        utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key)))
    print
    print "Address: " + address
    print "Private key: " + utils.wifToPrivateKey(wif_priv_key)
    print "Wallet Import Format Private Key: " + wif_priv_key
    print "Public Key: " + utils.privateKeyToPublicKey(
        utils.wifToPrivateKey(wif_priv_key))
    info = utils.getInfo(address)
    if info.balance() > 0:
Ejemplo n.º 8
0
print

q = int(raw_input("1:\tPrivate Key\n2:\tWallet Import Format Private Key\n3:\tPublic Key\n\n[ ] Enter selection: "))

print 

if q == 1:
    priv_key = raw_input("[ ] Enter Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(priv_key))
    print
    print "Address: " + address
    print "Private Key: " + priv_key
    print "Wallet Import Format Private Key: " + utils.privateKeyToWif(priv_key)
    print "Public Key: " + utils.privateKeyToPublicKey(priv_key)
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()

elif q == 2:
    wif_priv_key = raw_input("[ ] Enter Wallet Import Format Private Key: ")
    address = utils.pubKeyToAddr(utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key)))
    print
    print "Address: " + address
    print "Private key: " + utils.wifToPrivateKey(wif_priv_key)
    print "Wallet Import Format Private Key: " + wif_priv_key
    print "Public Key: " + utils.privateKeyToPublicKey(utils.wifToPrivateKey(wif_priv_key))
    info = utils.getInfo(address)
    if info.balance() > 0:
        info.display()