def script_verifyRecordedScoreMatchesDBScore(params): path_to_db = params.path_to_db path_to_hash = params.path_to_hash total_class_counts = params.total_class_counts img_path = params.img_path class_label = params.class_label video_id = params.video_id shot_id = params.shot_id class_idx = params.class_idx score_file = params.score_file mani = Tube_Manipulator(path_to_db) mani.openSession() toSelect = (Tube.idx, ) criterion = (Tube.class_idx_pascal == class_idx, Tube.video_id == video_id, Tube.shot_id == shot_id) total_shot_patches = mani.count(toSelect, criterion) #get patch id hash_info_patch = getHashInfoForImg(path_to_db, img_path) # patch_id=mani.select((Tube.idx,),(Tube.img_path==img_path,)); # assert len(patch_id)==1; # patch_id=patch_id[0][0]; # #get hash vals # mani_hash=TubeHash_Manipulator(path_to_db); # mani_hash.openSession(); # toSelect=(TubeHash.hash_table,TubeHash.hash_val) # criterion=(TubeHash.idx==patch_id,); # hash_info_patch=mani_hash.select(toSelect,criterion); #get hash_info of all patches in shot criterion = (Tube.class_idx_pascal == class_idx, Tube.video_id == video_id, Tube.shot_id == shot_id) hash_info_all = mani_hash.selectMix(toSelect, criterion) mani_hash.closeSession() mani.closeSession() hash_info_all = list(hash_info_all) hash_scores_patch = [] for idx_hash_info, hash_info_curr in enumerate(hash_info_patch): hash_file_curr = str(hash_info_curr[0]) + '_' + str( hash_info_curr[1]) + '_counts.p' hash_file_curr = os.path.join(path_to_hash, hash_file_curr) hash_bin_class_counts = pickle.load(open(hash_file_curr, 'rb')) hash_bin_class_count = hash_bin_class_counts[class_idx] numo = hash_bin_class_count - hash_info_all.count(hash_info_curr) deno = total_class_counts[class_idx] - total_shot_patches hash_scores_patch.append(numo / float(deno)) score_db = np.mean(hash_scores_patch) print len(hash_scores_patch), score_db, score_file assert np.isclose(score_db, score_file)
def script_verifyRecordedScoreMatchesDBScore(params): path_to_db = params.path_to_db path_to_hash = params.path_to_hash total_class_counts = params.total_class_counts img_path = params.img_path class_label = params.class_label video_id = params.video_id shot_id = params.shot_id class_idx = params.class_idx score_file = params.score_file mani=Tube_Manipulator(path_to_db); mani.openSession(); toSelect=(Tube.idx,); criterion=(Tube.class_idx_pascal==class_idx,Tube.video_id==video_id,Tube.shot_id==shot_id); total_shot_patches=mani.count(toSelect,criterion); #get patch id hash_info_patch=getHashInfoForImg(path_to_db,img_path); # patch_id=mani.select((Tube.idx,),(Tube.img_path==img_path,)); # assert len(patch_id)==1; # patch_id=patch_id[0][0]; # #get hash vals # mani_hash=TubeHash_Manipulator(path_to_db); # mani_hash.openSession(); # toSelect=(TubeHash.hash_table,TubeHash.hash_val) # criterion=(TubeHash.idx==patch_id,); # hash_info_patch=mani_hash.select(toSelect,criterion); #get hash_info of all patches in shot criterion=(Tube.class_idx_pascal==class_idx,Tube.video_id==video_id,Tube.shot_id==shot_id) hash_info_all=mani_hash.selectMix(toSelect,criterion); mani_hash.closeSession(); mani.closeSession() hash_info_all=list(hash_info_all); hash_scores_patch=[]; for idx_hash_info,hash_info_curr in enumerate(hash_info_patch): hash_file_curr=str(hash_info_curr[0])+'_'+str(hash_info_curr[1])+'_counts.p'; hash_file_curr=os.path.join(path_to_hash,hash_file_curr); hash_bin_class_counts=pickle.load(open(hash_file_curr,'rb')); hash_bin_class_count=hash_bin_class_counts[class_idx]; numo=hash_bin_class_count-hash_info_all.count(hash_info_curr); deno=total_class_counts[class_idx]-total_shot_patches; hash_scores_patch.append(numo/float(deno)); score_db=np.mean(hash_scores_patch); print len(hash_scores_patch),score_db,score_file assert np.isclose(score_db,score_file);
def getShotFrameCount(path_to_db,class_idx,video_id,shot_id): if type(path_to_db)==str: mani=Tube_Manipulator(path_to_db); mani.openSession(); else: mani=path_to_db toSelect=(Tube.idx,); criterion=(Tube.class_idx_pascal==class_idx,Tube.video_id==video_id,Tube.shot_id==shot_id); frame_count=mani.count(toSelect,criterion); if type(path_to_db)==str: mani.closeSession(); return frame_count;
def getShotFrameCount(path_to_db, class_idx, video_id, shot_id): if type(path_to_db) == str: mani = Tube_Manipulator(path_to_db) mani.openSession() else: mani = path_to_db toSelect = (Tube.idx, ) criterion = (Tube.class_idx_pascal == class_idx, Tube.video_id == video_id, Tube.shot_id == shot_id) frame_count = mani.count(toSelect, criterion) if type(path_to_db) == str: mani.closeSession() return frame_count
def verifyTotalClassBreakdowns(path_to_db,out_file): counts=pickle.load(open(out_file,'rb')); mani=Tube_Manipulator(path_to_db); mani.openSession(); for class_idx in range(10): print class_idx toSelect=(Tube.video_id,); criterion=(Tube.class_idx_pascal==class_idx,); count_video=mani.count(toSelect,criterion,distinct=True); toSelect=(Tube.video_id,Tube.shot_id); count_shot=mani.count(toSelect,criterion,distinct=True); toSelect=(Tube.video_id,Tube.shot_id,Tube.tube_id); count_tube=mani.count(toSelect,criterion,distinct=True); print counts['video'][class_idx],count_video, print counts['shot'][class_idx],count_shot, print counts['tube'][class_idx],count_tube assert counts['video'][class_idx]==count_video assert counts['shot'][class_idx]==count_shot assert counts['tube'][class_idx]==count_tube mani.closeSession();
def verifyTotalClassBreakdowns(path_to_db, out_file): counts = pickle.load(open(out_file, 'rb')) mani = Tube_Manipulator(path_to_db) mani.openSession() for class_idx in range(10): print class_idx toSelect = (Tube.video_id, ) criterion = (Tube.class_idx_pascal == class_idx, ) count_video = mani.count(toSelect, criterion, distinct=True) toSelect = (Tube.video_id, Tube.shot_id) count_shot = mani.count(toSelect, criterion, distinct=True) toSelect = (Tube.video_id, Tube.shot_id, Tube.tube_id) count_tube = mani.count(toSelect, criterion, distinct=True) print counts['video'][class_idx], count_video, print counts['shot'][class_idx], count_shot, print counts['tube'][class_idx], count_tube assert counts['video'][class_idx] == count_video assert counts['shot'][class_idx] == count_shot assert counts['tube'][class_idx] == count_tube mani.closeSession()
def getTotalCountsPerClass(path_to_db,class_idx_all): mani=Tube_Manipulator(path_to_db); mani.openSession(); total_counts={}; # total=0; for class_idx in class_idx_all: toSelect=(Tube.idx,) criterion = (Tube.class_idx_pascal==class_idx,); count_curr=mani.count(toSelect,criterion,distinct=True); total_counts[class_idx]=count_curr; # total=total+count_curr; # print class_label,class_idx,count_curr,count_curr/float(6371288),total_counts # print total mani.closeSession(); return total_counts
def getTotalCountsPerClass(path_to_db, class_idx_all): mani = Tube_Manipulator(path_to_db) mani.openSession() total_counts = {} # total=0; for class_idx in class_idx_all: toSelect = (Tube.idx, ) criterion = (Tube.class_idx_pascal == class_idx, ) count_curr = mani.count(toSelect, criterion, distinct=True) total_counts[class_idx] = count_curr # total=total+count_curr; # print class_label,class_idx,count_curr,count_curr/float(6371288),total_counts # print total mani.closeSession() return total_counts