Esempio n. 1
0
    def test_ggd_batches(self):
        graphres = torch.load(
            os.path.join(mydir, "data", "basic-duke_graph_3_00190415.pck"))

        with TemporaryDirectory() as tmpdir:
            model = NNModelGraphresPerConnection()
            model.load_state_dict(
                torch.load(os.path.join(mydir, "data",
                                        "snapshot_009.pyt"))['model_state'])
            model.eval()

            lst = GraphDiffList(tmpdir, model)

            old = []
            batch_size = 4
            n = (len(graphres) // batch_size) * batch_size
            for i in range(n):
                ex1 = graphres[i]
                old.append((model(ex1.pos) - model(ex1.neg)).item())
                lst.append(graphres[i])

            for i0 in range(0, n, batch_size):
                batch = make_ggd_batch(
                    [lst[i] for i in range(i0, i0 + batch_size)])
                l = model.ggd_batch_forward(batch)
                for i in range(i0, i0 + batch_size):
                    assert abs(l[i - i0].item() - old[i]) < 1e-3
Esempio n. 2
0
def main():
    dataset = Duke('data', cachedir="cachedir")  #_mc5")
    model = NNModelGraphresPerConnection()
    logdir = dataset.logdir
    print(logdir)
    fn = sorted(glob("%s/snapshot_???.pyt" % logdir))[-1]
    model.load_state_dict(torch.load(fn)['model_state'])
    model.eval()

    gt_not_in_graph = long_connections = long_connections_within_bound = 0

    for name, cam in tqdm(graph_names(dataset, "eval"),
                          "Estimating long structure"):
        name = name.replace("/lunarc/nobackup/projects/lu-haar/ggdtrack/", "")
        graph, detection_weight_features, connection_batch = torch.load(
            name + '-%s-eval_graph' % model.feature_name)
        promote_graph(graph)
        connection_weights = model.connection_batch_forward(connection_batch)
        detection_weights = model.detection_model(detection_weight_features)

        scene = dataset.scene(cam)
        gt_tracks, gt_graph_frames = ground_truth_tracks(
            scene.ground_truth(), graph)
        for tr in gt_tracks:
            prv = tr[0]
            for det in tr[1:]:
                prv.gt_next = det
                prv = det

        for det in graph:
            for i, nxt in zip(det.weight_index, det.next):
                if det.track_id == nxt.track_id != None and nxt.frame - det.frame > 1:
                    long_connections += 1
                    upper = get_upper_bound_from_gt(det, nxt,
                                                    connection_weights,
                                                    detection_weights)
                    if upper is None:
                        gt_not_in_graph += 1
                    elif 0 < connection_weights[i] < upper:
                        long_connections_within_bound += 1
                    # print ("  %s -[%4.2f]-> %s" % (det.track_id, connection_weights[i], nxt.track_id),
                    #        det.frame, nxt.frame, upper)

        # tracks = lp_track(graph, connection_batch, detection_weight_features, model)
        # print(tracks)

        print()
        print(gt_not_in_graph, long_connections, long_connections_within_bound)
        print(long_connections_within_bound /
              (long_connections - gt_not_in_graph))
        print()
Esempio n. 3
0
def main():
    max_extra = 3
    dataset = Duke("data")

    logdir = "cachedir/logdir_1.0_0.2"
    model = NNModelGraphresPerConnection()
    fn = sorted(glob("%s/snapshot_???.pyt" % logdir))[-max_extra-1]
    snapshot = torch.load(fn)
    model.load_state_dict(snapshot['model_state'])

    prep_eval_tracks(dataset, logdir, model, 'test', threads=1)
    eval_prepped_tracks_csv(dataset, logdir, 'test')

    os.system("cat  %s/result_duke_test_int/*_submit.txt > %s/duke.txt" % (logdir, logdir))
    if os.path.exists("%s/duke.zip" % logdir):
        os.unlink("%s/duke.zip" % logdir)
    os.system("cd %s; zip duke.zip duke.txt" % logdir)
Esempio n. 4
0
import re
from glob import glob
from os import stat
from random import shuffle

import torch

from ggdtrack.duke_dataset import Duke
from ggdtrack.eval import eval_hamming, ConnectionBatch, prep_eval_graphs
from ggdtrack.model import NNModelGraphresPerConnection
from ggdtrack.utils import save_json

dataset = Duke("data")
model = NNModelGraphresPerConnection()

prep_eval_graphs(dataset, NNModelGraphresPerConnection(), parts=["train"])

models = glob("cachedir/logdir/model*")
shuffle(models)

hammings = []
for fn in models:
    model.load_state_dict(torch.load(fn))
    hamming = eval_hamming(dataset, None, model)
    print(hamming)
    t = stat(fn).st_ctime_ns / 1e9
    hammings.append((t, hamming))
    save_json(hammings, "cachedir/logdir/hammings.json")