def featurize_and_save(f,out_prefix,factor=1,postfactor=1,maxcols=None,lock=None): ''' Featurize the video at path 'f'. But first, check if it exists on the dist at the output path already, if so, do not compute it again, just load it. lock is a semaphore (multiprocessing.Lock) in the case this is being called from a pool of workers This function handles both the prefactor and the postfactor parameters. Be sure to invoke actionbank.py with the same -f and -g parameters if you call it multiple times in the same experiment. '_featurize.npz' is the format to save them in. ''' oname = out_prefix + featurized_suffix if not path.exists(oname): print oname, "computing" featurized = spotting.featurize_video(f,factor=factor,maxcols=maxcols,lock=lock) if postfactor != 1: featurized = spotting.call_resample_with_7D(featurized,postfactor) of = gzip.open(oname,"wb") np.save(of,featurized) of.close() else: print oname, "skipping; already cached"
def load_single(self,i): ''' Load the ith template from the disk. ''' fp = gzip.open(path.join(self.bankpath,self.templates[i]),"rb") T = np.float32(np.load(fp)) # force a float32 format fp.close() #print "loading %s" % self.templates[i] # downsample if we need to if self.factor != 1: T = spotting.call_resample_with_7D(T,self.factor) return T