コード例 #1
0
ファイル: unittests.py プロジェクト: ChuangWang-Zoox/Software
def run_test(id_test, test, id_estimator, estimator):
    global W, H

    logger.info('     id_test: %s' % id_test)
    logger.info('id_estimator: %s' % id_estimator)
    from led_detection.unit_tests import LEDDetectionUnitTest
    assert isinstance(test, LEDDetectionUnitTest)
    query = test.get_query()
    print( query['images']['rgb'][0].shape)
    H, W, _ = query['images']['rgb'][0].shape
    print('shape is %s, %s'%(W, H))
    result = estimator.detect_led(**query)

    # We are testing whether the expected detections are a subset of
    # the returned ones, we will accept duplicate detections of the
    # same LED
    match_count = [0]*len(test.expected)
    for r in result.detections:
        m = find_match(r, test.expected)
        if(m != -1):
            match_count[m]+=1

    missedLEDs = [test.expected[i] for i in range(0,  len(match_count)) if match_count[i]==0]
    if(missedLEDs):
        logger.error('missed LED detections (%s): \n %s' % (len(missedLEDs),missedLEDs))

    # Valerio: check this - sometimes the error above is thrown, but the test
    # does not return False
    return not 0 in match_count
コード例 #2
0
ファイル: unittests.py プロジェクト: abdelq/duckietown
def run_test(id_test, test, id_estimator, estimator):
    global W, H

    logger.info('     id_test: %s' % id_test)
    logger.info('id_estimator: %s' % id_estimator)
    from led_detection.unit_tests import LEDDetectionUnitTest
    assert isinstance(test, LEDDetectionUnitTest)
    query = test.get_query()
    print( query['images']['rgb'][0].shape)
    H, W, _ = query['images']['rgb'][0].shape
    print('shape is %s, %s'%(W, H))
    result = estimator.detect_led(**query)

    # We are testing whether the expected detections are a subset of
    # the returned ones, we will accept duplicate detections of the
    # same LED
    match_count = [0]*len(test.expected)
    for r in result.detections:
        m = find_match(r, test.expected)
        if(m != -1):
            match_count[m]+=1

    missedLEDs = [test.expected[i] for i in range(0,  len(match_count)) if match_count[i]==0]
    if(missedLEDs):
        logger.error('missed LED detections (%s): \n %s' % (len(missedLEDs),missedLEDs))

    return not 0 in match_count
コード例 #3
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = 'I need two arguments. Please see README.md for documentation.'
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    package_dir = get_ros_package_path('led_detection')
    logger.debug('Package dir: %r' % package_dir)

    # dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    #filename = 'all_tests.yaml'
    filename = os.path.join(package_dir, 'scripts', 'dp45_tests.yaml')

    alltests = load_tests(filename)
    estimators = {
        'baseline':
        LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
        'LEDDetector_plots':
        LEDDetector(True, True, True)
    }
    #,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' %
                (which_estimators0, which_estimators))

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator,
                              estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info('All tests passed')
    else:
        which = [k for k, v in test_results.items() if not v]
        logger.error('These tests failed: %s ' % which)
        sys.exit(3)
コード例 #4
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = """
Usage:

    rosrun led_detection <script> <tests> <algorithms>
    
where:

    <tests> = comma separated list of algorithms. May use "*".
    <algorithms> = comma separated list of algorithms. May use  "*".
    
For example, this runs all tests on all algorithms:


    rosrun led_detection <script> '*' '*'
    
"""

        msg = msg.replace('<script>', script_name)
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    root = os.environ['DUCKIETOWN_ROOT']
    dirname = 'catkin_ws/src/led_detection/scripts/'
    filename = '20160312-allblinking_test1-argo.led_detection_test.yaml'
    filename = os.path.join(root, dirname, filename)

    alltests = load_tests(filename)
    estimators = {'dummy': DummyLEDDetector()}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' %
                (which_estimators0, which_estimators))

    # which tests to execute
    for id_test in which_tests:
        for id_estimator in which_estimators:
            test_results = run_test(id_test, alltests[id_test], id_estimator,
                                    estimators[id_estimator])
コード例 #5
0
ファイル: unittests.py プロジェクト: 71ananab/Software
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = """
Usage:

    rosrun led_detection <script> <tests> <algorithms>
    
where:

    <tests> = comma separated list of algorithms. May use "*".
    <algorithms> = comma separated list of algorithms. May use  "*".
    
For example, this runs all tests on all algorithms:


    rosrun led_detection <script> '*' '*'
    
"""

        msg = msg.replace('<script>', script_name)
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    root = os.environ['DUCKIETOWN_ROOT']
    dirname = 'catkin_ws/src/led_detection/scripts/'
    filename = '20160312-allblinking_test1-argo.led_detection_test.yaml'
    filename = os.path.join(root, dirname, filename)

    alltests = load_tests(filename)
    estimators = {'dummy': DummyLEDDetector()}
    
    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' % (which_estimators0, which_estimators))

    # which tests to execute
    for id_test in which_tests:
        for id_estimator in which_estimators:
            test_results = run_test(id_test, alltests[id_test],
                                    id_estimator, estimators[id_estimator])
コード例 #6
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = """
Usage:

    rosrun led_detection <script> <tests> <algorithms>

where:

    <tests> = comma separated list of algorithms. May use "*".
    <algorithms> = comma separated list of algorithms. May use  "*".

For example, this runs all tests on all algorithms:


    rosrun led_detection <script> '*' '*'

The default algorithm is called "baseline", and the tests are invoked using:

    rosrun led_detection <script> '*' 'baseline'

"""

        msg = msg.replace('<script>', script_name)
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    root = os.environ['DUCKIETOWN_ROOT']
    dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    #filename = 'all_tests.yaml'
    filename = 'dp45_tests.yaml'
    filename = os.path.join(root, dirname, filename)

    alltests = load_tests(filename)
    estimators = {
        'baseline':
        LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
        'LEDDetector_plots':
        LEDDetector(True, True, True)
    }
    #,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' %
                (which_estimators0, which_estimators))

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator,
                              estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info('All tests passed')
    else:
        which = [k for k, v in test_results.items() if not v]
        logger.error('These tests failed: %s ' % which)
        sys.exit(3)
コード例 #7
0
ファイル: unittests.py プロジェクト: ChuangWang-Zoox/Software
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = """
Usage:

    rosrun led_detection <script> <tests> <algorithms>

where:

    <tests> = comma separated list of algorithms. May use "*".
    <algorithms> = comma separated list of algorithms. May use  "*".

For example, this runs all tests on all algorithms:


    rosrun led_detection <script> '*' '*'

The default algorithm is called "baseline", and the tests are invoked using:

    rosrun led_detection <script> '*' 'baseline'


"""

        msg = msg.replace('<script>', script_name)
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    root = os.environ['DUCKIETOWN_ROOT']
    dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    filename = 'all_tests.yaml'
    filename = os.path.join(root, dirname, filename)

    alltests = load_tests(filename)
    estimators = {  'baseline' :
                    LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
                    'LEDDetector_plots' : LEDDetector(True, True, True)}
                 #,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' % (which_estimators0, which_estimators))

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator, estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info('All tests passed')
    else:
        which = [k for k, v in test_results.items() if not v]
        logger.error('These tests failed: %s ' % which)
        sys.exit(3)