Example #1
0
def test_server_with_id_service(dummy_data):
    frag, gt, fman = dummy_data
    id_service_port = 5600
    config = {'client_url': 'tcp://*:5590',
              'id_service_url': 'tcp://localhost:%i' % id_service_port,
              'solver_url': 'tcp://localhost:5590'}
    with temporary_file('.json') as config_filename:
        with open(config_filename, 'w') as fout:
            json.dump(config, fout)
        solver = serve.Solver(frag, feature_manager=fman,
                              config_file=config_filename)
    starting_id = 23461
    id_thread = threading.Thread(target=id_serve, name='id-service',
                                 daemon=True,
                                 kwargs=dict(port=id_service_port,
                                             curr_id=starting_id))
    id_thread.start()
    thread = threading.Thread(target=solver.listen, name='solver')
    thread.start()
    host, port = config['solver_url'].rsplit(':', maxsplit=1)
    _, dst = serve.proofread(frag, gt, host=host, port=int(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=[]))
    # test 2: make sure ID service worked: starting ID should be as above
    # should be equal but boundary ID messes things up
    assert np.min(result) > starting_id
    thread.join()
Example #2
0
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()
Example #3
0
def test_server_imperfect_fragments(dummy_data2):
    frag, gt, fman = dummy_data2
    host, port = 'tcp://localhost', 5589
    solver = serve.Solver(frag, feature_manager=fman,
                          address='tcp://*:' + str(port))
    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()
Example #4
0
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()
Example #5
0
def test_server_with_periodic_send(dummy_data):
    frag, gt, fman = dummy_data
    id_service_port = 5601
    config = {
        'client_url': 'tcp://*:5591',
        'id_service_url': 'tcp://localhost:%i' % id_service_port,
        'solver_url': 'tcp://localhost:5591'
    }
    with temporary_file('.json') as config_filename:
        with open(config_filename, 'w') as fout:
            json.dump(config, fout)
        solver = serve.Solver(frag,
                              feature_manager=fman,
                              config_file=config_filename)
    starting_id = 23461
    id_thread = threading.Thread(target=id_serve,
                                 name='id-service',
                                 daemon=True,
                                 kwargs=dict(port=id_service_port,
                                             curr_id=starting_id))
    id_thread.start()
    thread = threading.Thread(target=solver.listen,
                              name='solver',
                              daemon=True,
                              kwargs=dict(send_every=10))
    thread.start()
    host, port = config['solver_url'].rsplit(':', maxsplit=1)
    _, dst = serve.proofread(frag,
                             gt,
                             host=host,
                             port=int(port),
                             num_operations=2,
                             stop_when_finished=True,
                             request_seg=False,
                             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=[]))
    # test 2: make sure ID service worked: starting ID should be as above
    # should be equal but boundary ID messes things up
    assert np.min(result) > starting_id
Example #6
0
def test_server_imperfect_fragments(dummy_data2):
    frag, gt, fman = dummy_data2
    host, port = 'tcp://localhost', 5589
    solver = serve.Solver(frag,
                          feature_manager=fman,
                          address='tcp://*:' + str(port))
    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()