How to use the gala.evaluate.vi function in gala

To help you get started, we’ve selected a few gala examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github janelia-flyem / gala / tests / test_agglo.py View on Github external
def test_agglomeration():
    i = 1
    g = agglo.Rag(wss[i], probs[i], agglo.boundary_mean,
                  normalize_probabilities=True)
    g.agglomerate(0.51)
    assert_allclose(ev.vi(g.get_segmentation(), results[i]), 0.0,
                    err_msg='Mean agglomeration failed.')
github janelia-flyem / gala / tests / test_agglo.py View on Github external
def test_mean_agglo_fast_rag(dummy_data):
    frag, gt, g = dummy_data
    g.agglomerate(0.5)
    assert ev.vi(g.get_segmentation(), gt) == 0
github janelia-flyem / gala / tests / test_server.py View on Github external
def test_server_long(data):
    frag, gt, pr = data
    host, port = 'tcp://localhost', 5590
    solver = serve.Solver(frag, pr, port=port, host='tcp://*')
    thread = threading.Thread(target=solver.listen, name='solver')
    thread.start()
    _, dst = serve.proofread(frag, gt, host=host, port=port,
                             stop_when_finished=True, random_state=0)
    result = np.array(dst)[frag]
    # test: resulting segmentation should be improvement over fragments alone
    assert (ev.vi(result, gt, ignore_x=[], ignore_y=[]) <
            ev.vi(frag, gt, ignore_x=[], ignore_y=[]))
    thread.join()
github janelia-flyem / gala / tests / test_evaluate.py View on Github external
def test_vi():
    seg = np.array([1, 2, 3, 4])
    gt = np.array([1, 1, 8, 8])
    assert_equal(ev.vi(seg, gt), 1)
github janelia-flyem / gala / tests / test_agglo.py View on Github external
def test_mito():
    i = 5
    def frozen(g, i):
        "hardcoded frozen nodes representing mitochondria"
        return i in [3, 4]
    g = agglo.Rag(wss[i], probs[i], agglo.no_mito_merge(agglo.boundary_mean),
                  normalize_probabilities=True, isfrozennode=frozen,
                  use_slow=True)
    g.agglomerate(0.15)
    g.merge_priority_function = agglo.mito_merge
    g.rebuild_merge_queue()
    g.agglomerate(1.0)
    assert_allclose(ev.vi(g.get_segmentation(), results[i]), 0.0,
                    err_msg='Mito merge failed')
github janelia-flyem / gala / tests / test_gala.py View on Github external
def test_segment_with_classifier_4_channel():
    if PYTHON_VERSION == 2:
        rf = classify.load_classifier(
            os.path.join(rundir, 'example-data/rf-4.joblib'))
    else:
        fn = os.path.join(rundir, 'example-data/rf4-py3.joblib')
        with tar_extract(fn) as fn:
            rf = joblib.load(fn)
    learned_policy = agglo.classifier_probability(fc, rf)
    g_test = agglo.Rag(ws_test, p4_test, learned_policy, feature_manager=fc)
    g_test.agglomerate(0.5)
    seg_test = g_test.get_segmentation()
    seg_expected = imio.read_h5_stack(
            os.path.join(rundir, 'example-data/test-seg-4.lzf.h5'))
    assert_allclose(ev.vi(seg_test, seg_expected), 0.0)
github janelia-flyem / gala / tests / test_agglo.py View on Github external
def test_ladder_agglomeration():
    i = 2
    g = agglo.Rag(wss[i], probs[i], agglo.boundary_mean,
                  normalize_probabilities=True, use_slow=True,
                  update_unchanged_edges=True)
    g.agglomerate_ladder(3)
    g.agglomerate(0.51)
    assert_allclose(ev.vi(g.get_segmentation(), results[i]), 0.0,
                    err_msg='Ladder agglomeration failed.')
github janelia-flyem / gala / tests / test_server.py View on Github external
def test_server_imperfect_fragments(dummy_data2):
    frag, gt, fman = dummy_data2
    host, port = 'tcp://localhost', 5589
    solver = serve.Solver(frag, feature_manager=fman,
                          port=port, host='tcp://*')
    thread = threading.Thread(target=solver.listen, name='solver')
    thread.start()
    _, dst = serve.proofread(frag, gt, host=host, port=port, num_operations=2,
                             stop_when_finished=True, random_state=0)
    result = np.array(dst)[frag]
    # test: resulting segmentation should be improvement over fragments alone
    assert (ev.vi(result, gt, ignore_x=[], ignore_y=[]) <
            ev.vi(frag, gt, ignore_x=[], ignore_y=[]))
    thread.join()
github janelia-flyem / gala / tests / test_server.py View on Github external
def test_server_imperfect_fragments(dummy_data2):
    frag, gt, fman = dummy_data2
    host, port = 'tcp://localhost', 5589
    solver = serve.Solver(frag, feature_manager=fman,
                          port=port, host='tcp://*')
    thread = threading.Thread(target=solver.listen, name='solver')
    thread.start()
    _, dst = serve.proofread(frag, gt, host=host, port=port, num_operations=2,
                             stop_when_finished=True, random_state=0)
    result = np.array(dst)[frag]
    # test: resulting segmentation should be improvement over fragments alone
    assert (ev.vi(result, gt, ignore_x=[], ignore_y=[]) <
            ev.vi(frag, gt, ignore_x=[], ignore_y=[]))
    thread.join()
github janelia-flyem / gala / gala / viz.py View on Github external
gt : np.ndarray
        The ground truth corresponding to the RAG.

    fig : plt.Figure, optional
        Use this figure for plotting. If not provided, a new figure is created.

    Returns
    -------
    None
    """
    v = []
    n = []
    seg = g.get_segmentation()
    for i in history:
        seg[seg==i[1]] = i[0]
        v.append(evaluate.vi(seg, gt))
        n.append(len(np.unique(seg)-1))
    if fig is None:
        fig = plt.figure()
    plt.plot(n, v, figure = fig)
    plt.xlabel('Number of segments', figure = fig)
    plt.ylabel('vi', figure = fig)