def compute_features_core(image_fh,filter_fh,model_config,convolve_func): m_config = model_config['config']['model'] conv_mode = m_config['conv_mode'] #preprocessing array = v1e.image2array(m_config ,image_fh) preprocessed,orig_imga = v1e.preprocess(array,m_config) #input normalization norm_in = v1e.norm(preprocessed,conv_mode,m_config.get('normin')) #filtering filtered = v1e.convolve(norm_in, filter_fh, m_config , convolve_func) #nonlinear activation activ = v1e.activate(filtered,m_config.get('activ')) #output normalization norm_out = v1e.norm(activ,conv_mode,m_config.get('normout')) #pooling pooled = v1e.pool(norm_out,conv_mode,m_config.get('pool')) return pooled
def extract_features(image_config, image_fs, filterbank, model_config, convolve_func): cached_val = get_from_cache((image_config,model_config),FEATURE_CACHE) if cached_val is not None: output = cached_val else: print('extracting', image_config, model_config) image_fh = image_fs.get_version(image_config['filename']) m_config = model_config conv_mode = m_config['conv_mode'] #preprocessing array = v1e.image2array(m_config ,image_fh) preprocessed,orig_imga = v1e.preprocess(array,m_config ) #input normalization norm_in = v1e.norm(preprocessed,conv_mode,m_config.get('normin')) #filtering filtered = v1e.convolve(norm_in, filterbank, m_config , convolve_func) #nonlinear activation activ = v1e.activate(filtered,m_config.get('activ')) #output normalization norm_out = v1e.norm(activ,conv_mode,m_config.get('normout')) #pooling pooled = v1e.pool(norm_out,conv_mode,m_config.get('pool')) #postprocessing fvector_l = v1e.postprocess(norm_in,filtered,activ,norm_out,pooled,orig_imga,m_config.get('featsel')) output = sp.concatenate(fvector_l).ravel() put_in_cache((image_config,m_config),output,FEATURE_CACHE) return output