Ejemplo n.º 1
0
    optparser.add_option("-c", "--classifyExamples", default=None, dest="classifyExamples", help="Example File", metavar="FILE")
    optparser.add_option("--classIds", default=None, dest="classIds", help="Class ids", metavar="FILE")
    optparser.add_option("-m", "--model", default=None, dest="model", help="path to model file")
    #optparser.add_option("-w", "--work", default=None, dest="work", help="Working directory for intermediate and debug files")
    optparser.add_option("-o", "--output", default=None, dest="output", help="Output directory or file")
    optparser.add_option("-r", "--remote", default=None, dest="remote", help="Remote connection")
    #optparser.add_option("-c", "--classifier", default="SVMMultiClassClassifier", dest="classifier", help="Classifier Class")
    optparser.add_option("-p", "--parameters", default=None, dest="parameters", help="Parameters for the classifier")
    #optparser.add_option("-d", "--ids", default=None, dest="ids", help="")
    #optparser.add_option("--filterIds", default=None, dest="filterIds", help="")
    optparser.add_option("--install", default=None, dest="install", help="Install directory (or DEFAULT)")
    optparser.add_option("--installFromSource", default=False, action="store_true", dest="installFromSource", help="")
    (options, args) = optparser.parse_args()

    assert options.action in ["TRAIN", "CLASSIFY", "OPTIMIZE"]
    classifier = ScikitClassifier(Connection.getConnection(options.remote))
    if options.action == "TRAIN":
        import time
        trained = classifier.train(options.examples, options.output, options.parameters, options.classifyExamples)
        status = trained.getStatus()
        while status not in ["FINISHED", "FAILED"]:
            print >> sys.stderr, "Training classifier, status =", status
            time.sleep(10)
            status = trained.getStatus()
        print >> sys.stderr, "Training finished, status =", status
        if trained.getStatus() == "FINISHED":
            trained.downloadPredictions()
            trained.downloadModel()
    elif options.action == "CLASSIFY":
        classified = classifier.classify(options.examples, options.output, options.model, True)
        if classified.getStatus() == "FINISHED":
Ejemplo n.º 2
0
    optparser.add_option("-c", "--classifyExamples", default=None, dest="classifyExamples", help="Example File", metavar="FILE")
    optparser.add_option("--classIds", default=None, dest="classIds", help="Class ids", metavar="FILE")
    optparser.add_option("-m", "--model", default=None, dest="model", help="path to model file")
    #optparser.add_option("-w", "--work", default=None, dest="work", help="Working directory for intermediate and debug files")
    optparser.add_option("-o", "--output", default=None, dest="output", help="Output directory or file")
    optparser.add_option("-r", "--remote", default=None, dest="remote", help="Remote connection")
    #optparser.add_option("-c", "--classifier", default="SVMMultiClassClassifier", dest="classifier", help="Classifier Class")
    optparser.add_option("-p", "--parameters", default=None, dest="parameters", help="Parameters for the classifier")
    #optparser.add_option("-d", "--ids", default=None, dest="ids", help="")
    #optparser.add_option("--filterIds", default=None, dest="filterIds", help="")
    optparser.add_option("--install", default=None, dest="install", help="Install directory (or DEFAULT)")
    optparser.add_option("--installFromSource", default=False, action="store_true", dest="installFromSource", help="")
    (options, args) = optparser.parse_args()

    assert options.action in ["TRAIN", "CLASSIFY", "OPTIMIZE"]
    classifier = ScikitClassifier(Connection.getConnection(options.remote))
    if options.action == "TRAIN":
        import time
        trained = classifier.train(options.examples, options.output, options.parameters, options.classifyExamples)
        status = trained.getStatus()
        while status not in ["FINISHED", "FAILED"]:
            print >> sys.stderr, "Training classifier, status =", status
            time.sleep(10)
            status = trained.getStatus()
        print >> sys.stderr, "Training finished, status =", status
        if trained.getStatus() == "FINISHED":
            trained.downloadPredictions()
            trained.downloadModel()
    elif options.action == "CLASSIFY":
        classified = classifier.classify(options.examples, options.output, options.model, True)
        if classified.getStatus() == "FINISHED":
            if "," in options.install:
                destDir, downloadDir = options.install.split(",")
            else:
                destDir = options.install
        install(destDir, downloadDir, False, options.installFromSource)
        sys.exit()
#    elif options.filterIds != None:
#        assert options.model != None
#        classifier = SVMMultiClassClassifier()
#        filteredIds = classifier.filterIds(options.filterIds, options.model, verbose=True)
#        if options.output != None:
#            filteredIds.write(options.output)
    else:
        assert options.action in ["TRAIN", "CLASSIFY", "OPTIMIZE"]
        classifier = SVMMultiClassClassifier(
            Connection.getConnection(options.remote))
        if options.action == "TRAIN":
            import time
            trained = classifier.train(options.examples, options.output,
                                       options.parameters,
                                       options.classifyExamples)
            status = trained.getStatus()
            while status not in ["FINISHED", "FAILED"]:
                print >> sys.stderr, "Training classifier, status =", status
                time.sleep(10)
                status = trained.getStatus()
            print >> sys.stderr, "Training finished, status =", status
            if trained.getStatus() == "FINISHED":
                trained.downloadPredictions()
                trained.downloadModel()
        elif options.action == "CLASSIFY":
Ejemplo n.º 4
0
        if options.install != "DEFAULT":
            if "," in options.install:
                destDir, downloadDir = options.install.split(",")
            else:
                destDir = options.install
        install(destDir, downloadDir, False, options.installFromSource)
        sys.exit()
#    elif options.filterIds != None:
#        assert options.model != None
#        classifier = SVMMultiClassClassifier()
#        filteredIds = classifier.filterIds(options.filterIds, options.model, verbose=True)
#        if options.output != None:
#            filteredIds.write(options.output)
    else:
        assert options.action in ["TRAIN", "CLASSIFY", "OPTIMIZE"]
        classifier = SVMMultiClassClassifier(Connection.getConnection(options.remote))
        if options.action == "TRAIN":
            import time
            trained = classifier.train(options.examples, options.output, options.parameters, options.classifyExamples)
            status = trained.getStatus()
            while status not in ["FINISHED", "FAILED"]:
                print >> sys.stderr, "Training classifier, status =", status
                time.sleep(10)
                status = trained.getStatus()
            print >> sys.stderr, "Training finished, status =", status
            if trained.getStatus() == "FINISHED":
                trained.downloadPredictions()
                trained.downloadModel()
        elif options.action == "CLASSIFY":
            classified = classifier.classify(options.examples, options.output, options.model, True)
            if classified.getStatus() == "FINISHED":
Ejemplo n.º 5
0
    optparser.add_option("-c", "--classifyExamples", default=None, dest="classifyExamples", help="Example File", metavar="FILE")
    optparser.add_option("--classIds", default=None, dest="classIds", help="Class ids", metavar="FILE")
    optparser.add_option("-m", "--model", default=None, dest="model", help="path to model file")
    #optparser.add_option("-w", "--work", default=None, dest="work", help="Working directory for intermediate and debug files")
    optparser.add_option("-o", "--output", default=None, dest="output", help="Output directory or file")
    optparser.add_option("-r", "--remote", default=None, dest="remote", help="Remote connection")
    #optparser.add_option("-c", "--classifier", default="SVMMultiClassClassifier", dest="classifier", help="Classifier Class")
    optparser.add_option("-p", "--parameters", default=None, dest="parameters", help="Parameters for the classifier")
    #optparser.add_option("-d", "--ids", default=None, dest="ids", help="")
    #optparser.add_option("--filterIds", default=None, dest="filterIds", help="")
    optparser.add_option("--install", default=None, dest="install", help="Install directory (or DEFAULT)")
    optparser.add_option("--installFromSource", default=False, action="store_true", dest="installFromSource", help="")
    (options, args) = optparser.parse_args()

    assert options.action in ["TRAIN", "CLASSIFY", "OPTIMIZE"]
    classifier = SKLearnSVM(Connection.getConnection(options.remote))
    if options.action == "TRAIN":
        import time
        trained = classifier.train(options.examples, options.output, options.parameters, options.classifyExamples)
        status = trained.getStatus()
        while status not in ["FINISHED", "FAILED"]:
            print >> sys.stderr, "Training classifier, status =", status
            time.sleep(10)
            status = trained.getStatus()
        print >> sys.stderr, "Training finished, status =", status
        if trained.getStatus() == "FINISHED":
            trained.downloadPredictions()
            trained.downloadModel()
    elif options.action == "CLASSIFY":
        classified = classifier.classify(options.examples, options.output, options.model, True)
        if classified.getStatus() == "FINISHED":