pybing/_pybing.py
def detect(bing, input_gpath_list, **kwargs):
        '''
            Run detection with a given loaded model on a list of images

            Args:
                input_gpath_list (list of str): the list of image paths that you want
                    to test

            Kwargs:
                numPerSz (int): the number of results per size

        '''
        # Default values
        params = odict([
            ('numPerSz',                     130),
            ('batch_size',                   None),
            ('results_val_array',            None),  # This value always gets overwritten
            ('results_len_array',            None),  # This value always gets overwritten
            ('RESULT_LENGTH',                None),  # This value always gets overwritten
            ('serial',                       False),
            ('verbose',                      bing.verbose),
            ('quiet',                        bing.quiet),
        ])
        params.update(kwargs)
        params['RESULT_LENGTH'] = RESULT_LENGTH

        # Try to determine the parallel processing batch size
        if params['batch_size'] is None:
            try:
                cpu_count = multiprocessing.cpu_count()
                if not params['quiet']:
                    print('[pybing py] Detecting with %d CPUs' % (cpu_count, ))
                params['batch_size'] = cpu_count
            except Exception:
                params['batch_size'] = 8

        # Run training algorithm
        batch_size = params['batch_size']
        del params['batch_size']  # Remove this value from params
        batch_num = int(len(input_gpath_list) / batch_size) + 1
        # Detect for each batch
        for batch in ut.ProgressIter(range(batch_num), lbl="[pybing py]", freq=1, invert_rate=True):
            begin = time.time()
            start = batch * batch_size
            end   = start + batch_size
            if end > len(input_gpath_list):
                end = len(input_gpath_list)
            input_gpath_list_        = input_gpath_list[start:end]
            num_images = len(input_gpath_list_)
            # Set image detection to be run in serial if less than half a batch to run
            if num_images < min(batch_size / 2, 8):
                params['serial'] = True
            # Final sanity check
            params['results_val_array'] = np.empty(num_images, dtype=NP_ARRAY_FLOAT)
            params['results_len_array'] = np.empty(num_images, dtype=C_INT)
            # Make the params_list
            params_list = [
                _cast_list_to_c(input_gpath_list_, C_CHAR),
                num_images,
            ] + params.values()
            BING_CLIB.detect(bing.detector_c_obj, *params_list)
            results_list = _extract_np_array(params['results_len_array'], params['results_val_array'], NP_ARRAY_FLOAT, NP_FLOAT32, RESULT_LENGTH)
            conclude = time.time()
            if not params['quiet']:
                print('[pybing py] Took %r seconds to compute %d images' % (conclude - begin, num_images, ))
            for input_gpath, result_list in zip(input_gpath_list_, results_list):
                result_list_ = []
                for result in result_list:
                    # Unpack result into a nice Python dictionary and return
                    temp = {}
                    temp['minx']    = int(result[0])
                    temp['miny']    = int(result[1])
                    temp['maxx']    = int(result[2])
                    temp['maxy']    = int(result[3])
                    result_list_.append(temp)
                yield (input_gpath, result_list_)
            params['results_val_array'] = None
            params['results_len_array'] = None

            Run detection with a given loaded model on a list of images

            Args:
                input_gpath_list (list of str): the list of image paths that you want
                    to test

            Kwargs:
                numPerSz (int): the number of results per size

        
Run detection with a given loaded model on a list of images
Run detection with a given loaded model on a list of images
def detect(bing, input_gpath_list, **kwargs):
        params = odict([
            ('numPerSz',                     130),
            ('batch_size',                   None),
            ('results_val_array',            None),  
            ('results_len_array',            None),  
            ('RESULT_LENGTH',                None),  
            ('serial',                       False),
            ('verbose',                      bing.verbose),
            ('quiet',                        bing.quiet),
        ])
        params.update(kwargs)
        params['RESULT_LENGTH'] = RESULT_LENGTH
        if params['batch_size'] is None:
            try:
                cpu_count = multiprocessing.cpu_count()
                if not params['quiet']:
                    print('[pybing py] Detecting with %d CPUs' % (cpu_count, ))
                params['batch_size'] = cpu_count
            except Exception:
                params['batch_size'] = 8
        batch_size = params['batch_size']
        del params['batch_size']  
        batch_num = int(len(input_gpath_list) / batch_size) + 1
        for batch in ut.ProgressIter(range(batch_num), lbl="[pybing py]", freq=1, invert_rate=True):
            begin = time.time()
            start = batch * batch_size
            end   = start + batch_size
            if end > len(input_gpath_list):
                end = len(input_gpath_list)
            input_gpath_list_        = input_gpath_list[start:end]
            num_images = len(input_gpath_list_)
            if num_images < min(batch_size / 2, 8):
                params['serial'] = True
            params['results_val_array'] = np.empty(num_images, dtype=NP_ARRAY_FLOAT)
            params['results_len_array'] = np.empty(num_images, dtype=C_INT)
            params_list = [
                _cast_list_to_c(input_gpath_list_, C_CHAR),
                num_images,
            ] + params.values()
            BING_CLIB.detect(bing.detector_c_obj, *params_list)
            results_list = _extract_np_array(params['results_len_array'], params['results_val_array'], NP_ARRAY_FLOAT, NP_FLOAT32, RESULT_LENGTH)
            conclude = time.time()
            if not params['quiet']:
                print('[pybing py] Took %r seconds to compute %d images' % (conclude - begin, num_images, ))
            for input_gpath, result_list in zip(input_gpath_list_, results_list):
                result_list_ = []
                for result in result_list:
                    temp = {}
                    temp['minx']    = int(result[0])
                    temp['miny']    = int(result[1])
                    temp['maxx']    = int(result[2])
                    temp['maxy']    = int(result[3])
                    result_list_.append(temp)
                yield (input_gpath, result_list_)
            params['results_val_array'] = None
            params['results_len_array'] = None
def detect ( bing , input_gpath_list , ** kwargs ) : params = odict ( [ ( 'numPerSz' , 130 ) , ( 'batch_size' , None ) , ( 'results_val_array' , None ) , ( 'results_len_array' , None ) , ( 'RESULT_LENGTH' , None ) , ( 'serial' , False ) , ( 'verbose' , bing . verbose ) , ( 'quiet' , bing . quiet ) , ] ) params . update ( kwargs ) params [ 'RESULT_LENGTH' ] = RESULT_LENGTH if params [ 'batch_size' ] is None : try : cpu_count = multiprocessing . cpu_count ( ) if not params [ 'quiet' ] : print ( '[pybing py] Detecting with %d CPUs' % ( cpu_count , ) ) params [ 'batch_size' ] = cpu_count except Exception : params [ 'batch_size' ] = 8 batch_size = params [ 'batch_size' ] del params [ 'batch_size' ] batch_num = int ( len ( input_gpath_list ) / batch_size ) + 1 for batch in ut . ProgressIter ( range ( batch_num ) , lbl = "[pybing py]" , freq = 1 , invert_rate = True ) : begin = time . time ( ) start = batch * batch_size end = start + batch_size if end > len ( input_gpath_list ) : end = len ( input_gpath_list ) input_gpath_list_ = input_gpath_list [ start : end ] num_images = len ( input_gpath_list_ ) if num_images < min ( batch_size / 2 , 8 ) : params [ 'serial' ] = True params [ 'results_val_array' ] = np . empty ( num_images , dtype = NP_ARRAY_FLOAT ) params [ 'results_len_array' ] = np . empty ( num_images , dtype = C_INT ) params_list = [ _cast_list_to_c ( input_gpath_list_ , C_CHAR ) , num_images , ] + params . values ( ) BING_CLIB . detect ( bing . detector_c_obj , * params_list ) results_list = _extract_np_array ( params [ 'results_len_array' ] , params [ 'results_val_array' ] , NP_ARRAY_FLOAT , NP_FLOAT32 , RESULT_LENGTH ) conclude = time . time ( ) if not params [ 'quiet' ] : print ( '[pybing py] Took %r seconds to compute %d images' % ( conclude - begin , num_images , ) ) for input_gpath , result_list in zip ( input_gpath_list_ , results_list ) : result_list_ = [ ] for result in result_list : temp = { } temp [ 'minx' ] = int ( result [ 0 ] ) temp [ 'miny' ] = int ( result [ 1 ] ) temp [ 'maxx' ] = int ( result [ 2 ] ) temp [ 'maxy' ] = int ( result [ 3 ] ) result_list_ . append ( temp ) yield ( input_gpath , result_list_ ) params [ 'results_val_array' ] = None params [ 'results_len_array' ] = None
Run detection with a given loaded model on a list of images
Run detection with a given loaded model on a list of images
'''
            Run detection with a given loaded model on a list of images

            Args:
                input_gpath_list (list of str): the list of image paths that you want
                    to test

            Kwargs:
                numPerSz (int): the number of results per size

        ''' # Default values # This value always gets overwritten # This value always gets overwritten # This value always gets overwritten # Try to determine the parallel processing batch size # Run training algorithm # Remove this value from params # Detect for each batch # Set image detection to be run in serial if less than half a batch to run # Final sanity check # Make the params_list # Unpack result into a nice Python dictionary and return
bing
input_gpath_list
the list of image paths that you want
to test
the list of image paths that you want to test