示例#1
0
def sign_up():
    """ Save new user info into Mongo Database """
    form = SignUp(csrf_enabled=False)

    name = []
    phone = []
    email = []
    occupation = []
    age = []
    description = []
    unique_id = []

    if request.method == "POST":

        name.append(form.name.data)
        phone.append(form.phone.data)
        email.append(form.email.data)
        occupation.append(form.occupation.data)
        age.append(form.age.data)
        description.append(form.description.data)
        unique_id.append(form.unique_id.data)

        # Save new user's image for retraining the face recognition model
        save_image_for_training(unique_id[0], name[0])

        new_entry = pd.DataFrame()

        new_entry["Name"] = name
        new_entry["Phone"] = phone
        new_entry["Email"] = email
        new_entry["Occupation"] = occupation
        new_entry["Age"] = age
        new_entry["Description"] = description
        new_entry["Unique ID"] = unique_id

        # Create new collection for users in app database and insert data
        collection = "users"
        db_cm = db[collection]
        data = new_entry.to_dict(orient='records')
        db_cm.insert(data)

        try:
            # Retrain model with new users
            print("Training KNN classifier...")
            train("static/train_test/train",
                  model_save_path="static/models/trained_knn_model.clf",
                  n_neighbors=None)
            print("Training complete!")
        except:
            print("Oh no, unable to train model.")

        status = "Agent assignment complete."
        return render_template("index.html", form=form, status=status)
    else:
        return render_template("index.html", form=form)
示例#2
0
def acquaintence_identification(uploaded_file):

    try: 
        # Retrain model with new users
        print("Training KNN classifier...")
        train("static/train_test/train", model_save_path="static/models/trained_knn_model.clf", n_neighbors=None)
        print("Training complete!")
    except:
        return render_template("search.html", status="Oops, no one is in here. Be the first to sign up! (:")

    print("Looking for faces in {}".format(uploaded_file))

    # Find all people in the image using a trained classifer model_path
    # Note: You can pass in either a classifier file name or a classifier model isntance
    predictions = predict(uploaded_file, model_path="static/models/trained_knn_model.clf")

    # Print results on the console
    for name, (top, right, bottom, left) in predictions:
        print("-Found {} at ({}, {})".format(name, left, top))
        if name == "unknown":
            return render_template("search.html", status="Sorry, unable to identify them :( Please try another photo.")
        else:
            collection = db.users
            query = collection.find({"Unique ID": name})
            for q in query:
                user_dict = {}
                user_dict['Name'] = q['Name']
                user_dict['Phone'] = q['Phone']
                user_dict['Email'] = q['Email']
                user_dict['Occupation'] = q['Occupation']
                user_dict['Description'] = q['Description']
            print(user_dict)
               
    # Display results overland on an image
    # show_prediction_labels_on_image(uploaded_file, predictions)
    
    print("Rendering template...")
    return render_template("search.html", status="No one here.", user=user_dict, src_path=uploaded_file )
示例#3
0

## Run and Check the correctness
path_to_training_images = 'data/training/images'
training_csv_file = 'data/training/steering_angles.csv'
path_to_testing_images = 'data/training/images'
testing_csv_file = 'data/training/steering_angles.csv'
time_limit = 600

#Setup timout handler - I think this will only work on unix based systems:
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(time_limit)

try:
    print("Training your network, start time: %s" % time.strftime("%H:%M:%S"))
    NN = tp.train(path_to_images=path_to_training_images,
                  csv_file=training_csv_file)

except ValueError as ex:
    pass

finally:
    signal.alarm(0)
    print("Ending Time: %s" % time.strftime("%H:%M:%S"))

print('Training Complete! \n')

print('Measuring performance...')
## Measure Performance:
data = np.genfromtxt(testing_csv_file, delimiter=',')
frame_nums = data[:, 0]
steering_angles = data[:, 1]
示例#4
0
        # train predict loop for each feat set
        #for fset, fset_results in all_tgt_results[tgt_name][est_type].items():
        for fset_name, fset_list in fset_dict.items():
            zeit = time.time()
            print(
                '%s/%s/%s/%d: scoring used:' %
                (tgt_name, est_type, fset_name, fsets_count_int), scoring)

            #feat_train = fset_results.data['fset_list'] + gbl.clin_demog_feats
            feat_train = fset_list + gbl.clin_demog_feats

            ests, train_scores = train(
                est_type=est_type,
                task=subs.tgt_task,
                X=subs.pat_frame_train_norm.loc[:, feat_train],
                y=subs.pat_frame_train_y,
                cv_folds=subs.cv_folds,
                params=params['params'],
                scoring=scoring,
                thresh=thresh)
            print(
                '%s/%s/%s/%d: trained cv over grid:' %
                (tgt_name, est_type, fset_name, fsets_count_int), train_scores)

            pred_scores, pred_frames = pred(
                est_type=est_type,
                task=subs.tgt_task,
                ests=ests,
                X=subs.pat_frame_test_norm.loc[:, feat_train],
                y=subs.pat_frame_test_y.iloc[:, 0],
                scoring=scoring,