Exemplo n.º 1
0
def test_labels_predicted_hdf5(multi_skel_vid_labels, tmpdir):
    labels = multi_skel_vid_labels
    filename = os.path.join(tmpdir, "test.h5")

    # Lets promote some of these Instances to predicted instances
    for label in labels:
        for i, instance in enumerate(label.instances):
            if i % 2 == 0:
                label.instances[i] = PredictedInstance.from_instance(
                    instance, 0.3)

    # Lets also add some from_predicted values
    for label in labels:
        label.instances[1].from_predicted = label.instances[0]

    # Try adding a node to the skeleton
    labels.skeletons[0].add_node("new node")

    # Save and compare the results
    Labels.save_hdf5(filename=filename, labels=labels)
    loaded_labels = Labels.load_hdf5(filename=filename)
    _check_labels_match(labels, loaded_labels)

    # Try deleting nodes from the skeleton
    node = labels.skeletons[0].nodes[-1]
    labels.skeletons[0].delete_node(node)
    node = labels.skeletons[0].nodes[-1]
    labels.skeletons[0].delete_node(node)

    # Save and compare the results
    Labels.save_hdf5(filename=filename, labels=labels)
    loaded_labels = Labels.load_hdf5(filename=filename)
    _check_labels_match(labels, loaded_labels)
Exemplo n.º 2
0
def test_hdf5_from_predicted(multi_skel_vid_labels, tmpdir):
    labels = multi_skel_vid_labels
    filename = os.path.join(tmpdir, "test.h5")

    # Add some predicted instances to create from_predicted links
    for frame_num, frame in enumerate(labels):
        if frame_num % 20 == 0:
            frame.instances[
                0].from_predicted = PredictedInstance.from_instance(
                    frame.instances[0], float(frame_num))
            frame.instances.append(frame.instances[0].from_predicted)

    # Save and load, compare the results
    Labels.save_hdf5(filename=filename, labels=labels)
    loaded_labels = Labels.load_hdf5(filename=filename)

    for frame_num, frame in enumerate(loaded_labels):
        if frame_num % 20 == 0:
            assert frame.instances[0].from_predicted.score == float(frame_num)
Exemplo n.º 3
0
def predicted_instances(instances):
    return [PredictedInstance.from_instance(i, 1.0) for i in instances]