Esempio n. 1
0
    def validate(self, classify_path = None):        
        total_score = 0.0
        K = 3

        if classify_path is None:
            for filename in [f for f in os.listdir(self.validation_path) if os.path.isfile(self.validation_path + f)]:
                logger.log("classifying %s" % filename)
                scores = audio.classify(self.train_set, self.validation_path + filename)
                label = filename.replace('_', ' ').replace('.mp3', '').title()
                
                top_pick = scores[0]
                second = scores[1]
                third = scores[2]
                fourth = scores[3]
                
                if top_pick[1] == label:
                    confidence_1 = (float(second[0]) - float(top_pick[0])) / float(second[0])
                    confidence_2 = (float(third[0]) - float(top_pick[0])) / float(third[0])
                    confidence_3 = (float(fourth[0]) - float(top_pick[0])) / float(fourth[0])
                    
                    total_score += (confidence_1 + confidence_2 + confidence_3) / float(K)
                    print "classify correct, confidence: ", (confidence_1 + confidence_2 + confidence_3) / float(K)
                else:
                    print "incorrect classify %s %s" % (top_pick[1], label)
                
                print " first  > ", top_pick
                print " second > ", second 
                    
        else:
            logger.log(audio.classify(self.train_set, self.validation_path + classify_path))   
    
        self.train_set.default_validation_score = total_score
        self.train_set.save()
           
        return total_score
Esempio n. 2
0
 def POST(self, name):
     destination_path = "uploads/test_track.mp3"
     data = web.input()
            
     fout = open(destination_path, 'w')
     fout.write(data['uploadedfile'])
     fout.close()
     
     result = audio.classify(destination_path)
     web.debug(result)
     return result[0][1].split('_')[0]