Пример #1
0
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"
Пример #2
0
def add_to_bank(bankpath,newvideos):
    '''  Add video(s) as new templates to the bank at path bankpath. '''

    if not path.isdir(newvideos):
        (h,t) = path.split(newvideos)
        print "adding %s\n"%(newvideos)
        F = spotting.featurize_video(newvideos);
        of = gzip.open(path.join(bankpath,t+".npy.gz"),"wb")
        np.save(of,F)
        of.close()
    else:
        files = os.listdir(newvideos)
        for f in files:
            F = spotting.featurize_video(path.join(newvideos,f));
            (h,t) = path.split(f)
            print "adding %s\n"%(t)
            of = gzip.open(path.join(bankpath,t+".npy.gz"),"wb")
            np.save(of,F)
            of.close()