def processVideo(vid,IDT_DIR,FV_DIR,gmm_list): """ Extracts the IDTFs, constructs a Fisher Vector, and saves the Fisher Vector at FV_DIR output_file: the full path to the newly constructed fisher vector. gmm_list: a list of gmms """ input_file = os.path.join(IDT_DIR, vid.split('.')[0]+'.bin') output_file = os.path.join(FV_DIR, vid.split('.')[0]+'.fv') if not os.path.exists(input_file): print '%s IDT Feature does not exist!' % vid return False if os.path.exists(output_file+'.mat'): print '%s Fisher Vector exists, skip!' % vid return False video_desc = IDT_feature.vid_descriptors(IDT_feature.read_IDTF_file(input_file)) computeFV.create_fisher_vector(gmm_list, video_desc, output_file) return True
def processVideo(vid, IDT_DIR, FV_DIR, gmm_list): """ Extracts the IDTFs, constructs a Fisher Vector, and saves the Fisher Vector at FV_DIR output_file: the full path to the newly constructed fisher vector. gmm_list: a list of gmms """ input_file = os.path.join(IDT_DIR, vid.split('.')[0] + '.bin') output_file = os.path.join(FV_DIR, vid.split('.')[0] + '.fv') if not os.path.exists(input_file): print '%s IDT Feature does not exist!' % vid return False if os.path.exists(output_file + '.mat'): print '%s Fisher Vector exists, skip!' % vid return False video_desc = IDT_feature.vid_descriptors( IDT_feature.read_IDTF_file(input_file)) computeFV.create_fisher_vector(gmm_list, video_desc, output_file) return True
else: svm = classify_library.load_model('../data/models/svm_nopca.sav') gmm_list = np.load(gmm_list + ".npz")['gmm_list'] index_class = np.load(class_index)['index_class'] index_class = index_class[()] points = [] # a list of IDT features. frame_lim = frame_step for line in sys.stdin: if line[0] != '[': # avoid getting info message as data frame = int(line.split()[0]) if frame_lim <= frame: frame_lim = frame_lim + frame_step # print frame_lim<=frame if points != []: video_desc = IDT_feature.vid_descriptors(points) fish = computeFV.create_fisher_vector_unsaved( gmm_list, video_desc) fish = np.array(fish).reshape(1, -1) if args.no_pca: result = svm.predict(fish) else: fish_pca = pca.transform(fish) result = svm.predict(fish_pca) print '\n' + 'RESULT: ' + OKGREEN + BOLD + index_class[ result[0]] + ENDC + '\n' points = [] points.append(IDT_feature.IDTFeature(line))
import numpy as np from yael import ynumpy import IDT_feature from tempfile import TemporaryFile import argparse import computeFV """ computes a Fisher vector given an input stream of IDTFs Usage: stream_of_IDTFs | python computeFVstream.py fisher_path gmm_list ./DenseTrackStab video_file | python computeFVstream.py fisher_path gmm_list """ #The input is a stream of IDTFs associated with a single video. if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("fisher_path", help="File to save the output Fisher Vector", type=str) parser.add_argument("gmm_list", help="File of saved list of GMMs", type=str) args = parser.parse_args() gmm_list = np.load(args.gmm_list+".npz")['gmm_list'] points = [] # a list of IDT features. for line in sys.stdin: points.append(IDT_feature.IDTFeature(line)) video_desc = IDT_feature.vid_descriptors(points) computeFV.create_fisher_vector(gmm_list, video_desc, args.fisher_path)