Example #1
0
def full_extract(fhs,config_fname):
    fh = fhs[0][0][1]
    params, featsel = get_params(config_fname)
    
    arr = image2array(params,fh)

    orig_imga,orig_imga_conv = image_preprocessing(arr,params)
    fvector_l = []
    filt_l = get_gabor_filters(params['filter'])      
    for cidx in xrange(orig_imga_conv.shape[2]):
        imga0 = map_preprocessing(orig_imga_conv[:,:,cidx],params)
        
        imga1 = v1f.v1like_norm(imga0[:,:,sp.newaxis], conv_mode, **params['normin'])
        
        imga2 = v1f.v1like_filter(imga1[:,:,0], conv_mode, filt_l)

        minout = params['activ']['minout'] # sustain activity
        maxout = params['activ']['maxout'] # saturation
        imga3 = imga2.clip(minout, maxout)

        imga4 = v1f.v1like_norm(imga3, conv_mode, **params['normout'])

        if "sparsify" in params and params["sparsify"]:
            imga4 = (imga4.max(2)[:,:,None] == imga4)

        imga5 = v1f.v1like_pool(imga4, conv_mode, **params['pool'])
        output = imga5

        fvector = include_map_level_features(imga1,imga2,imga3,imga4,imga5,output,featsel)

        fvector_l += [fvector]
        
    # -- include image-level bells & whistles
    fvector_l = include_image_level_features(orig_imga,fvector_l, featsel)

    # -- reshape  
    fvector_l = [fvector.ravel() for fvector in fvector_l]
    out = sp.concatenate(fvector_l).ravel()
    
    return cPickle.dumps(out)
Example #2
0
def normalize(fhs,config_fname,pset):

    fh = fhs[0][0][1]
    assert pset in ['in','out'], 'pset not recognized'
    params, featsel = get_params(config_fname)
    conv_mode = params['conv_mode']
    input = cPickle.loads(fh.read())
    
    output = {}
    for cidx in input.keys():
       if len(input[cidx].shape) == 3:
          inobj = input[cidx]
       else:
          inobj = input[cidx][:,:,sp.newaxis]
       output[cidx] = v1f.v1like_norm(inobj, conv_mode, **params['norm' + pset])

    return cPickle.dumps(output)