Exemplo n.º 1
0
    def __init__(self):
        #  classes = [0,1,2,3,4,5]  #  detail classes
        nc1 = nc.noteClass()
        self.classes = nc1.segmentClasses.values()
        self.featureNamesDict = nc1.featureNamesDict

        self.resetFeatureDictAll()
Exemplo n.º 2
0
    def __init__(self):
        self.nc1 = nc.noteClass()
        self.ptSeg1 = ptSeg.pitchtrackSegByNotes()
        self.evalu1 = evalu.Evaluation()
        self.evaluationMetrics = []

        self.resetRepresentation()
Exemplo n.º 3
0
    def constructJson4DetailFeature(self, featureVecFolderPath,
                                    targetFolderPath, recordingNames,
                                    groundtruthCSVPath):

        #  detail level classification groundtruth json

        nc1 = nc.noteClass()
        segmentClasses = nc1.segmentClasses

        for rn in recordingNames:
            featureFilename = featureVecFolderPath + rn + '.json'
            targetFilename = targetFolderPath + rn + '.json'

            CSVFile = ''.join([str(groundtruthCSVPath), '/', rn, '.csv'])

            with open(featureFilename) as data_file:
                featureDict = json.load(data_file)

            # read classification groundtruth csv file
            with open(CSVFile) as groundtruthFile:
                targetDict = {}
                for line in groundtruthFile.readlines():
                    splitLine = line.split(',')
                    for iic in range(len(splitLine)):
                        c = splitLine[iic].rstrip('\n')
                        if c != '':  #  empty string is False
                            cInt = int(c)
                            targetDict[cInt] = iic

            with open(targetFilename, 'w') as outfile:
                json.dump(targetDict, outfile)
    def __init__(self):
        self.nc1 = nc.noteClass()
        self.ptSeg1 = ptSeg.pitchtrackSegByNotes()
        self.evalu1 = evalu.Evaluation()
        self.evaluationMetrics = []

        self.resetRepresentation()
Exemplo n.º 5
0
    def __init__(self):
        #  classes = [0,1,2,3,4,5]  #  detail classes
        nc1 = nc.noteClass()
        self.classes = nc1.segmentClasses.values()
        self.featureNamesDict = nc1.featureNamesDict

        self.resetFeatureDictAll()
    def constructJson4NoteFeature(self,featureVecFolderPath,targetFolderPath,recordingNames,groundtruthNoteLevel):

        #  note level classification groundtruth json

        nc1 = nc.noteClass()
        allNoteClasses = list(nc1.basicNoteClasses.keys()) + nc1.unClassifiedNoteClasses

        for rn in recordingNames:
            featureFilename = featureVecFolderPath+rn+'.json'
            targetFilename = targetFolderPath+rn+'.json'
            with open(featureFilename) as data_file:
                featureDict = json.load(data_file)

            targetDict = {}
            for ii in range(1, len(featureDict)+1):
                for noteClass in allNoteClasses:
                    noteClassRecordingFoldername = os.path.join(groundtruthNoteLevel, noteClass, rn+'midinote')
                    if os.path.isdir(noteClassRecordingFoldername):
                        onlypngs = [ f for f in os.listdir(noteClassRecordingFoldername) if f.endswith('.png') ]
                        for png in onlypngs:
                            pngNum = os.path.splitext(png)[0]
                            if str(ii) == pngNum:
                                if noteClass in nc1.basicNoteClasses:
                                    #  targetDict[ii] = nc1.basicNoteClasses[noteClass]  #  detail classes
                                    targetDict[ii] = 0  # 5 basic classes
                                else:
                                    #  targetDict[ii] = 5  #  detail classes
                                    targetDict[ii] = 1  # non classified classes

            with open(targetFilename, 'w') as outfile:
                json.dump(targetDict, outfile)
    def constructJson4DetailFeature(self, featureVecFolderPath,targetFolderPath,recordingNames,groundtruthCSVPath):

        #  detail level classification groundtruth json

        nc1 = nc.noteClass()
        segmentClasses = nc1.segmentClasses

        for rn in recordingNames:
            featureFilename = featureVecFolderPath+rn+'.json'
            targetFilename = targetFolderPath+rn+'.json'

            CSVFile = ''.join([str(groundtruthCSVPath),'/',rn,'.csv'])

            with open(featureFilename) as data_file:
                featureDict = json.load(data_file)

            # read classification groundtruth csv file
            with open(CSVFile) as groundtruthFile:
                targetDict = {}
                for line in groundtruthFile.readlines():
                    splitLine = line.split(',')
                    for iic in range(len(splitLine)):
                        c = splitLine[iic].rstrip('\n')
                        if c != '':  #  empty string is False
                            cInt = int(c)
                            targetDict[cInt] = iic

            with open(targetFilename, 'w') as outfile:
                json.dump(targetDict, outfile)
Exemplo n.º 8
0
    def constructJson4NoteFeature(self, featureVecFolderPath, targetFolderPath,
                                  recordingNames, groundtruthNoteLevel):

        #  note level classification groundtruth json

        nc1 = nc.noteClass()
        allNoteClasses = list(
            nc1.basicNoteClasses.keys()) + nc1.unClassifiedNoteClasses

        for rn in recordingNames:
            featureFilename = featureVecFolderPath + rn + '.json'
            targetFilename = targetFolderPath + rn + '.json'
            with open(featureFilename) as data_file:
                featureDict = json.load(data_file)

            targetDict = {}
            for ii in range(1, len(featureDict) + 1):
                for noteClass in allNoteClasses:
                    noteClassRecordingFoldername = os.path.join(
                        groundtruthNoteLevel, noteClass, rn + 'midinote')
                    if os.path.isdir(noteClassRecordingFoldername):
                        onlypngs = [
                            f for f in os.listdir(noteClassRecordingFoldername)
                            if f.endswith('.png')
                        ]
                        for png in onlypngs:
                            pngNum = os.path.splitext(png)[0]
                            if str(ii) == pngNum:
                                if noteClass in nc1.basicNoteClasses:
                                    #  targetDict[ii] = nc1.basicNoteClasses[noteClass]  #  detail classes
                                    targetDict[ii] = 0  # 5 basic classes
                                else:
                                    #  targetDict[ii] = 5  #  detail classes
                                    targetDict[
                                        ii] = 1  # non classified classes

            with open(targetFilename, 'w') as outfile:
                json.dump(targetDict, outfile)
Exemplo n.º 9
0
 def __init__(self):
     self.nc1 = nc.noteClass()
Exemplo n.º 10
0
def jingjuElementSegmentation():

    start_time = time.time()  # starting time
    '''
    ######################################### pYIN pitchtrack and notes ################################################
    filename_amateur = '/Users/gong/Documents/MTG document/Jingju arias/jingjuElementMaterials/laosheng/test/weiguojia_section_amateur.wav'
    filename_pro = '/Users/gong/Documents/MTG document/Jingju arias/jingjuElementMaterials/laosheng/test/weiguojia_section_pro.wav'
    pYINPtNote(filename_amateur)
    #filename1 = pYinPath + '/testAudioLong.wav'
    '''

    ############################################## initialsation #######################################################
    pitchtrackNoteTrainFolderPath = os.path.join(dir, 'pYinOut/laosheng/train/')

    # classification training ground truth
    # groundtruthNoteLevelPath = '/Users/gong/Documents/pycharmProjects/jingjuSegPic/laosheng/train/pyinNoteCurvefit/classified'
    # groundtruthNoteDetailPath = '/Users/gong/Documents/pycharmProjects/jingjuSegPic/laosheng/train/refinedSegmentCurvefit/classified'

    # classification model path
    pitchContourClassificationModelName = os.path.join(dir,'pYinOut/laosheng/train/model/pitchContourClassificationModel.pkl')

    # feature, target folders train
    # featureVecTrainFolderPath = os.path.join(dir,'pYinOut/laosheng/train/featureVec/')
    # targetTrainFolderPath = os.path.join(dir,'pYinOut/laosheng/train/target/')

    # predict folders
    pitchtrackNotePredictFolderPath = os.path.join(dir,'../../data/updateFiles/')
    #pitchtrackNotePredictFolderPath = os.path.join(dir,'pYinOut/laosheng/predict/)
    featureVecPredictFolderPath = os.path.join(dir,'pYinOut/laosheng/predict/featureVec/')
    targetPredictFolderPath = os.path.join(dir,'pYinOut/laosheng/predict/target/')


    # recordingNamesTrain = ['male_02_neg_1', 'male_12_neg_1', 'male_12_pos_1', 'male_13_pos_1', 'male_13_pos_3']
    recordingNamesPredict = ['student']

    evaluation = False                      #  parameters grid search

    slopeTh = 60.0                          #  contour combination slope difference threshold
    flatnoteTh = 80.0                       #  threshold for deciding one note as flat pitch note
    #recordingNamesPredict = ['male_02_neg_1', 'male_12_neg_1', 'male_12_pos_1', 'male_13_pos_1', 'male_13_pos_3']       # evaluation

    ################################################## predict #########################################################
    # segmentation
    nc2 = nc.noteClass()
    nc2.noteSegmentationFeatureExtraction(pitchtrackNotePredictFolderPath,
                                          featureVecPredictFolderPath,
                                          pitchtrackNotePredictFolderPath,
                                          recordingNamesPredict,
                                          segCoef=0.3137,predict=True)

    # predict
    ttknn2 = ttknn.TrainTestKNN()
    ttknn2.predict(pitchContourClassificationModelName,featureVecPredictFolderPath,
                   targetPredictFolderPath,recordingNamesPredict)


    ########################################### representation #########################################################
    for rm in recordingNamesPredict:
        #  filename declaration
        originalPitchtrackFilename = pitchtrackNotePredictFolderPath+rm+'_pitchtrack.csv'
        targetFilename = targetPredictFolderPath+rm+'.json'
        refinedSegmentFeaturesFilename = pitchtrackNotePredictFolderPath+rm+'_refinedSegmentFeatures.json'
        representationFilename = pitchtrackNotePredictFolderPath+rm+'_representation.json'
        figureFilename = pitchtrackNotePredictFolderPath+rm+'_reprensentationContourFigure.png'

        # important txt files!!
        regressionPitchtrackFilename = pitchtrackNotePredictFolderPath+rm+'_regression_pitchtrack.csv'
        refinedSegmentationGroundtruthFilename = pitchtrackNotePredictFolderPath+rm+'_refinedSeg.csv'

        rsm1 = rsm.RefinedSegmentsManipulation()
        rsm1.process(refinedSegmentFeaturesFilename,targetFilename,
                     representationFilename,figureFilename,regressionPitchtrackFilename,
                     originalPitchtrackFilename = originalPitchtrackFilename,
                     refinedSegGroundtruthFilename=refinedSegmentationGroundtruthFilename,
                     slopeTh=slopeTh, flatnoteTh=flatnoteTh)

    runningTime = time.time() - start_time
    # print("--- %s seconds ---" % (time.time() - start_time))

    return runningTime
Exemplo n.º 11
0
Arquivo: demo.py Projeto: MTG/smc-2016
    ######### construct target json ###########

    fvt1 = fvt.FeatureVecTarget()
    fvt1.constructJson4DetailFeature(featureVecTrainFolderPath,targetTrainFolderPath,recordingNamesTrain,groundtruthNoteDetailPath)

    ################ train ####################
    ttknn1 = ttknn.TrainTestKNN()
    ttknn1.gatherFeatureTarget(featureVecTrainFolderPath,targetTrainFolderPath,recordingNamesTrain)
    # ttknn1.featureVec2DPlot([3,7])
    ttknn1.crossValidation(pitchContourClassificationModelName)
    '''

    ################################################## predict #########################################################
    # segmentation
    nc2 = nc.noteClass()
    nc2.noteSegmentationFeatureExtraction(pitchtrackNotePredictFolderPath,
                                          featureVecPredictFolderPath,
                                          recordingNamesPredict,
                                          segCoef=0.3137,predict=True)

    # predict
    ttknn2 = ttknn.TrainTestKNN()
    ttknn2.predict(pitchContourClassificationModelName,featureVecPredictFolderPath,
                   targetPredictFolderPath,recordingNamesPredict)

    '''
    ################################################ evaluation code ###################################################
    # uncomment it only when needs evaluation
    with open('./pYinOut/laosheng/predict/evaluationResult02.txt', "w") as outfile:
        for sc in np.linspace(0.2,0.5,30):
Exemplo n.º 12
0
    ######### construct target json ###########

    fvt1 = fvt.FeatureVecTarget()
    fvt1.constructJson4DetailFeature(featureVecTrainFolderPath,targetTrainFolderPath,recordingNamesTrain,groundtruthNoteDetailPath)

    ################ train ####################
    ttknn1 = ttknn.TrainTestKNN()
    ttknn1.gatherFeatureTarget(featureVecTrainFolderPath,targetTrainFolderPath,recordingNamesTrain)
    # ttknn1.featureVec2DPlot([3,7])
    ttknn1.crossValidation(pitchContourClassificationModelName)
    '''

    ################################################## predict #########################################################
    # segmentation
    nc2 = nc.noteClass()
    nc2.noteSegmentationFeatureExtraction(pitchtrackNotePredictFolderPath,
                                          featureVecPredictFolderPath,
                                          recordingNamesPredict,
                                          segCoef=0.3137,predict=True)

    # predict
    ttknn2 = ttknn.TrainTestKNN()
    ttknn2.predict(pitchContourClassificationModelName,featureVecPredictFolderPath,
                   targetPredictFolderPath,recordingNamesPredict)

    '''
    ################################################ evaluation code ###################################################
    # uncomment it only when needs evaluation
    with open('./pYinOut/laosheng/predict/evaluationResult02.txt', "w") as outfile:
        for sc in np.linspace(0.2,0.5,30):
Exemplo n.º 13
0
 def __init__(self):
     self.nc1 = nc.noteClass()