Exemple #1
0
def save_to_db():
    threading.Timer(60.0, save_to_db).start() # save one data point per minute
    if time_to_save_data():
        image = util_guru.download(session)
        input = util_image.get_single_input_data(image)
        output = network.predict(input)[0][0]
        d = Data(output)
        print "Adding ", time.strftime("%m/%d %H:%M:%S", time.localtime()), " => ", output, "..."
        db.session.add(d)
        db.session.commit()
Exemple #2
0
def current():
    for file in glob.glob("web/static/img/*.jpg"):
        os.remove(file)
    image = util_guru.download(session)
    timestamp = time.time()
    file = "web/static/img/img-{}.jpg".format(timestamp)
    util_image.save(image, file)
    imageFile = "static/img/img-{}.jpg".format(timestamp)
    input = util_image.get_single_input_data(image)
    output = network.predict(input)[0][0]
    return jsonify(currentImg=imageFile, currentNum=output)
Exemple #3
0
mode = raw_input("1: Train\n2: Load\n3: Live\n")
exp = theanets.Experiment(
        theanets.feedforward.Regressor,
        layers=(config.IMG_W * config.IMG_H, 500, 1)
        )

if mode == "1":
    trainer.train(exp)

if mode == "2":
    exp = exp.load(path="net.data")
    print "Manual validation:"
    for file in glob.glob("data/manual/*.jpg"):
        image = util_image.load(file)
        input = util_image.data(image)
        input = input.reshape(1, len(input))
        output = exp.predict(input)
        print "Prediction for ", file, " = ", output

if mode == "3":
    exp = exp.load(path="net.data")
    session = util_guru.start()
    while True:
        image = util_guru.download(session)
        print "Opening image..."
        image.show()
        input = util_image.get_single_input_data(image)
        output = exp.predict(input)[0][0]
        print "Crowded Level: ", output
        raw_input("Any key to download another image...")