Ejemplo n.º 1
0
def get_features(fnames,
                 featfunc,
                 kernel_type = DEFAULT_SIMFUNC,
                 simfunc = DEFAULT_SIMFUNC,
                 info_str = 'the',
                 ):
    
    # --------------------------------------------------------------------------
    # -- init
    # load first vector to get dimensionality
    fvector0 =  get_fvector(fnames[0],
                            featfunc,
                            kernel_type,
                            simfunc=simfunc)
    
    if kernel_type == "exp_mu_da":
        # hack for GB with 204 dims
        fvector0 = fvector0.reshape(-1, 204)
    else:
        fvector0 = fvector0.ravel()
    featshape = fvector0.shape
    featsize = fvector0.size

    # -- helper function
    # set up progress bar
    def load_features(x_fnames, info_str):        
        print "-"*80
        print "Loading %s data ..." % info_str
        pbar = ProgressBar(widgets=widgets, maxval=len(x_fnames))
        pbar.start()

        x_features = sp.empty((len(x_fnames),) + featshape,
                              dtype='float32')
        
        for i, one_or_two_fnames in enumerate(x_fnames):
            fvector = get_fvector(one_or_two_fnames,
                                  featfunc,                                  
                                  kernel_type,
                                  simfunc=simfunc)
            fvector = fvector.reshape(fvector0.shape)
            x_features[i] = fvector
            pbar.update(i+1)

        pbar.finish()
        print "-"*80        

        return x_features

    # -- load features from filenames
    try:
        features = load_features(fnames, info_str=info_str)
    except OverwriteError, err:
        print err
Ejemplo n.º 2
0
    def load_features(x_fnames, info_str):        
        print "-"*80
        print "Loading %s data ..." % info_str
        pbar = ProgressBar(widgets=widgets, maxval=len(x_fnames))
        pbar.start()

        x_features = sp.empty((len(x_fnames),) + featshape,
                              dtype='float32')
        
        for i, one_or_two_fnames in enumerate(x_fnames):
            fvector = get_fvector(one_or_two_fnames,
                                  featfunc,                                  
                                  kernel_type,
                                  simfunc=simfunc)
            fvector = fvector.reshape(fvector0.shape)
            x_features[i] = fvector
            pbar.update(i+1)

        pbar.finish()
        print "-"*80        

        return x_features