Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "inputList",  #nargs="?" , 
        help=("Training sample list."),
        #default=config.defaultTrainSampleList
    )
    parser.add_argument("outputDir",
                        nargs="?",
                        help="Music output directory",
                        default=config.defaultOutputDir)
    #parser.add_argument("modelName", nargs="?" ,
    #                    help="model filename",
    #                    default=config.defaultModelFilename
    #                    )
    args = parser.parse_args()

    trainSampList = sampleLoader.parseFileList(args.inputList)

    trainFeatsList = []
    for trainSampFilename in trainSampList:
        trainSamp = sampleLoader.loadTrainSample(trainSampFilename)
        trainFeat = featureManager.extractTrainFeat(trainSamp)
        trainFeatsList.append(trainFeat)

    trainFeatFilename = config.getTrainInFeatFilename(args)
    featureManager.saveJson(trainFeatsList, trainFeatFilename)

    m = model.getModelObj()
    #modelName = config.getModelFilename(args)
    m.train(args)
Ejemplo n.º 2
0
def main():
   parser = argparse.ArgumentParser()
   parser.add_argument("inputList", #nargs="?" , 
                       help=("Training sample list."),
                       #default=config.defaultTrainSampleList
                      )
   parser.add_argument("outputDir", nargs="?" , 
                       help="Music output directory",
                       default = config.defaultOutputDir
                      )
   #parser.add_argument("modelName", nargs="?" , 
   #                    help="model filename",
   #                    default=config.defaultModelFilename
   #                    )
   args = parser.parse_args()


   trainSampList = sampleLoader.parseFileList(args.inputList)

   trainFeatsList = []
   for trainSampFilename in trainSampList:
      trainSamp = sampleLoader.loadTrainSample(trainSampFilename)
      trainFeat = featureManager.extractTrainFeat(trainSamp)
      trainFeatsList.append(trainFeat)

   trainFeatFilename = config.getTrainInFeatFilename(args)
   featureManager.saveJson(trainFeatsList, trainFeatFilename);

   m = model.getModelObj();
   #modelName = config.getModelFilename(args)
   m.train(args); #load features from config.getTrainInFeatFilename(args)
Ejemplo n.º 3
0
    def train(self, args):
        #ex filenames:
        # trainFeat.json -> [quantizer] -> <perfFeatName>.train.dat
        #                       |                                 |
        #                       +->  <perfFeatName>.quant         |
        # +-------------------------------------------------------+
        # +-> [svm^hmm] -> <perfFeatName>.model.bin

        trainFeats = featureManager.loadJson(
            config.getTrainInFeatFilename(args))
        perfFeats = collectPerfFeats(trainFeats)
        #logging.printDebug(perfFeats)
        #for each perfFeature, a svmFeatFilename (quantized feat for svm^hmm)
        #and singleModelFilename (model file for svm^hmm) will be saved
        #scoreFeatLines = self.formatLine(scoreFeats)
        scoreFeatLines = self.formatLineDirect(trainFeats)
        for pkey, pval in perfFeats.items():
            allLines = [("# " + pkey)]
            #TODO:quantize pval
            q = quantizer.getQuantizerObj(self.getQuantizeFilename(args, pkey))
            quantizedVal = q.quantize(pval)
            lines = zip(map(str, quantizedVal), scoreFeatLines)
            #logging.printDebug(lines)
            allLines = map(lambda l: " ".join(l), lines)
            #logging.printDebug(allLines)

            svmFeatFilename = self.getTrainInputFilename(args, pkey)
            with open(svmFeatFilename, 'w') as f:
                f.writelines(map(lambda x: x + "\n", allLines))

            cmd = [self.trainBinPath]
            if (config.svmhmm_c != None):
                cmd.append("-c " + str(config.svmhmm_c))
            else:
                cmd.append("-c 0.01")
            cmd.append(svmFeatFilename)
            singleModelFilename = self.getSingleModelFilename(args, pkey)
            cmd.append(singleModelFilename)

            #logging.printDebug(" ".join(cmd))
            subprocess.call(" ".join(cmd), shell=True)
Ejemplo n.º 4
0
   def train(self, args):
      #ex filenames:
      # trainFeat.json -> [quantizer] -> <perfFeatName>.train.dat 
      #                       |                                 |
      #                       +->  <perfFeatName>.quant         |
      # +-------------------------------------------------------+
      # +-> [svm^hmm] -> <perfFeatName>.model.bin

      trainFeats = featureManager.loadJson(config.getTrainInFeatFilename(args))
      perfFeats = collectPerfFeats(trainFeats)
      #logging.printDebug(perfFeats)
      #for each perfFeature, a svmFeatFilename (quantized feat for svm^hmm)
      #and singleModelFilename (model file for svm^hmm) will be saved
      #scoreFeatLines = self.formatLine(scoreFeats) 
      scoreFeatLines = self.formatLineDirect(trainFeats) 
      for pkey, pval in perfFeats.items():
         allLines = [("# " + pkey)]
         #TODO:quantize pval
         q = quantizer.getQuantizerObj(self.getQuantizeFilename(args, pkey))
         quantizedVal = q.quantize(pval)
         lines = zip(map(str, quantizedVal), scoreFeatLines) 
         #logging.printDebug(lines)
         allLines = map(lambda l:" ".join(l), lines)
         #logging.printDebug(allLines)

         svmFeatFilename = self.getTrainInputFilename(args, pkey)
         with open(svmFeatFilename, 'w') as f:
            f.writelines(map(lambda x:x+"\n", allLines))

         cmd = [self.trainBinPath]
         if (config.svmhmm_c != None):
             cmd.append("-c " + str(config.svmhmm_c))
         else:
             cmd.append("-c 0.01")
         cmd.append(svmFeatFilename)
         singleModelFilename = self.getSingleModelFilename(args,pkey)
         cmd.append(singleModelFilename)

         #logging.printDebug(" ".join(cmd))
         subprocess.call(" ".join(cmd), shell=True)