Beispiel #1
0
def test_persons(tmpdb):
    print(facedb.persons())
    code = np.random.rand(128)
    session = facedb.assert_session()
    session.add(facedb.Person(name='Tobias Schoch', code=code))

    p = facedb.persons()[0]
    assert np.all(p.code == code)
Beispiel #2
0
 def get(self):
     session = facedb.Session()
     faces = list(
         map(lambda p: {'person': utils.person_to_dict(p)},
             facedb.persons(session)))
     session.close()
     return faces
Beispiel #3
0
def test_comparison(tmpdb):

    codes = np.random.rand(10, 128)
    for i in range(10):
        code = codes[i, :]
        facedb.teach(code, name='Tobias Schoch {}'.format(i))
        # facedb.session.add(facedb.Person(name='Tobias Schoch {}'.format(i),code=code))

    p = facedb.persons()[3]

    # teach again
    facedb.teach(codes[6, :] + np.random.randn(128) * 0.01, "Tobias Schoch 6",
                 0.8)
    assert (facedb.find_similar_persons(
        codes[6, :])[0].name) == "Tobias Schoch 6"

    # test comparison
    assert np.all(p.code == codes[3, :])

    assert np.all(
        facedb.find_similar_persons(codes[4, :])[0].code == codes[4, :])

    assert np.all(facedb.get_person("Tobias Schoch 5").code == codes[5, :])

    with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
        facedb.get_person('Mickey Mouse')
Beispiel #4
0
def test_thread_safe(tmpdb):
    codes = np.random.rand(10, 128)
    for i in range(10):
        code = codes[i, :]
        facedb.teach(code, name='Tobias Schoch {}'.format(i))
        # facedb.session.add(facedb.Person(name='Tobias Schoch {}'.format(i),code=code))

    p = facedb.persons()

    print(p)

    def _print_person(p):
        print(p.name)

    thread = threading.Thread(target=_print_person, args=(p[3], ))
    thread.start()
    thread.join()
Beispiel #5
0
            else:
                flash('Error: All the form fields are required. ')

        return render_template('teach.html', form=form)

    @app.errorhandler(utils.BadRequest)
    def handle_invalid_usage(error):
        response = jsonify(error.to_dict())
        response.status_code = error.status_code
        return response

    return app


if __name__ == "__main__":

    import logging
    logging.basicConfig(level=logging.INFO)

    # set database path to data dir
    datapath = os.path.join(os.path.split(__file__)[0], 'data')
    os.makedirs(datapath, exist_ok=True)
    facedb.set_db_path(datapath, persistent=True)
    logging.info("facedb database: {} containes {} persons...".format(
        facedb.get_db_file().absolute(), len(facedb.persons())))

    # Start app
    print("Starting WebServer...")
    app = create_app()
    app.run(host='0.0.0.0', port=80, debug=False)