Beispiel #1
0
def select_seed(res_dir=RES_DIR, floor=0):
    if not os.path.exists(res_dir):
        return random.randrange(100)
    counts = {k: 0 for k in range(100)}
    for rec in load_all_data(dirpaths=(res_dir,)):
        if rec.floor == floor:
            counts[rec.seed] += 1
    pairs = list(counts.items())
    min_count = min([x[1] for x in pairs])
    min_seeds = [x[0] for x in pairs if x[1] == min_count]
    return random.choice(min_seeds)
def main():
    recordings = {}
    for recording in load_all_data():
        if not os.path.exists(cookie_path(recording)):
            img_hash = str(recording.load_frame(0).flatten().tolist())
            if img_hash not in recordings:
                recordings[img_hash] = []
            recordings[img_hash].append(recording)
    for img_hash, seed in seed_hashes():
        if not len(recordings):
            return
        if img_hash in recordings:
            print('got %d results for seed %d' %
                  (len(recordings[img_hash]), seed))
            for rec in recordings[img_hash]:
                rename_recording(rec, seed)
            del recordings[img_hash]
        else:
            print('NO RECORDINGS')
import json
import os
import random

from PIL import Image
from flask import Flask, send_file, send_from_directory
import numpy as np
import torch

from obs_tower2.labels import LabeledImage, load_all_labeled_images
from obs_tower2.model import StateClassifier
from obs_tower2.recording import load_all_data, sample_recordings

app = Flask(__name__, static_url_path='')
labelled = load_all_labeled_images()
recordings = load_all_data()

CLASSIFIER_PATH = '../scripts/save_classifier.pkl'
if os.path.exists(CLASSIFIER_PATH):
    classifier = StateClassifier()
    classifier.load_state_dict(torch.load(CLASSIFIER_PATH, map_location='cpu'))
else:
    classifier = None


@app.route('/assets/<path:path>')
def handle_asset(path):
    return send_from_directory('assets', path)


@app.route('/')