Exemplo n.º 1
0
def main():
    beatscriptFile = open(sys.argv[1], "r")
    lines = beatscriptFile.readlines()
    context = readContext(lines)
    beatList = readBeatscript(lines, context)
    blockList = coalesceBeats(beatList)
    Features.initializeContextVars(context)
    dataLines = []
    for block in blockList:
        dataLines.append(createDataLine(context, block))
        context["BygoneBlocks"].append(block)

    outputFile = open(sys.argv[2], "w")
    for dataLine in dataLines:
        outputFile.write(DELIMITER.join([str(x) for x in dataLine]) + "\n")
        #outputFile.write(DELIMITER.join(dataLine) + "\n")
    outputFile.close()
def main():
    if len(sys.argv) < 2:
        print("Usage: python ClassificationProcess.py <Beatscript-Filename>")
        return 1
    # Initialization and Training
    classifiers, scaler = trainWithAllExamples(True)
    cutClassifiers, cutScaler = trainWithAllExamples(False)
    try:
        beatscript_file = open(sys.argv[1], "r")
    except IOError:
        print("Error: The Beatscipt could not be opened.")
        print("Usage: python ClassificationProcess.py <Beatscript-Filename>")
        return 1
    lines = beatscript_file.readlines()
    context = readContext(lines)#
    beatscript = readBeatscript(lines, context)
    Features.initializeContextVars(context)
    beatList = getBeatsBetweenFrames(beatscript, -1, 0)
    current_frame = 0
    lastBlock = beatList
    context["BygoneBlocks"] = []
    sys.stdout.write("Training finished." + "\n")
    sys.stdout.flush()
    # Get Distribution
    dist = classifyForShot(lastBlock, context, classifiers, scaler)
    cutBeforeThisClassification = classifyForCut(lastBlock, context, cutClassifiers,
        cutScaler)
    while True:
        choice = raw_input("")
        if choice == "e":
            printListOfEntities(context)
        elif choice == "t": # get the names of the target and the linetarget
            determine_targets(context, lastBlock)
        elif choice == "p": # print out the classification propabilities
            pickle.dump(dist, sys.stdout)

        elif choice == "c": # Print out, if we should cut at this point
            blockList = []
            decisions = []
            for block in context["BygoneBlocks"]:
                blockList.append(block)
                decisions.append(block[0].shot)
            blockList.append(lastBlock)
            decisions.append(dist.index(max(dist)))
            if cutBeforeThisClassification[0] < cutBeforeThisClassification[1]:
                sys.stdout.write("yes\n")
            else:
                sys.stdout.write("no\n")

        elif choice == "f": # check framenumber for a new block
            new_frame = int(raw_input(""))
            beatList = getBeatsBetweenFrames(beatscript, current_frame, new_frame)
            current_frame = new_frame
            if beatList :
                context["BygoneBlocks"].append(lastBlock)
                lastBlock = beatList
                dist = classifyForShot(lastBlock, context, classifiers, scaler)
                cutBeforeThisClassification = classifyForCut(lastBlock, context, cutClassifiers, cutScaler)
                sys.stdout.write("yes\n")
            else:
                sys.stdout.write("no\n")

        elif choice == "d": # recieve the decision for the lastBlock
            decision = int(raw_input(""))
            for beat in lastBlock:
                beat.shot = decision
            sys.stdout.write("decision recieved\n")

        elif choice == "q": # quit...
            sys.stdout.write("exiting...\n")
            sys.stdout.flush()
            break
        else:
            sys.stdout.write("You didn't enter something useful.\n")
        sys.stdout.flush()