Example #1
0
def parse_command_line():
    parser = argparse.ArgumentParser(
        description="""Train, validate, and test a face detection classifier that will determine if
        two faces are the same or different.""")

    parser.add_argument("--test_data", help="Use preTrain model on test data, calcu the accuracy and ROC.", action="store_true")
    parser.add_argument("--test_val", help="Use preTrain model on validation data, calcu the accuracy and ROC.", action="store_true")
    parser.add_argument("--weights", help="""The trained model weights to use; if not provided
        defaults to the network that was just trained""", type=str, default=None)
    parser.add_argument("-t", "--threshold", help="The margin of two dense", type=int, default=80)

    args = vars(parser.parse_args())

    if os.environ.get("CAFFEHOME") == None:
        print "You must set CAFFEHOME to point to where Caffe is installed. Example:"
        print "export CAFFEHOME=/usr/local/caffe"
        exit(1)

    # Ensure the random number generator always starts from the same place for consistent tests.
    random.seed(0)

    lfw = data.Lfw()
    lfw.load_data()
    lfw.pair_data()

    if args["weights"] == None:
        args["weights"] = constants.TRAINED_WEIGHTS

    if args["test_data"] == True:
        test_pairings(lfw, weight_file=args["weights"], is_test=True, threshold=args["threshold"])
    elif args["test_val"] == True:
        test_pairings(lfw, weight_file=args["weights"], threshold=args["threshold"])
    else:
        train(True, data=lfw)
Example #2
0
def train(output_graphs, data=None, weight_file=None, note=None):
    print("Training data, generating graphs: %r" % (output_graphs))

    run()
    copy_model_definitions()
    generate_parsed_logs()
    (training_details, validation_details) = parse_logs()
    trained_weight_file = get_trained_weight_file()

    if output_graphs:
        graph.plot_results(training_details, validation_details, note)

        # If no weight file is provided by callers to this method, parse out the one we just
        # trained.
        #if weight_file == None:
        #    weight_file = trained_weight_file
        #predict.test_clusters(data, weight_file)
        predict.test_pairings(data, trained_weight_file)