Esempio n. 1
0
def writeMetaInfoToDb(path_to_db,out_files,idx_global,class_ids_all,path_to_data):
    mani=Tube_Manipulator(path_to_db);
    
    mani.openSession();
    for out_file_idx,out_file in enumerate(out_files):
        if out_file_idx%100==0:
            print out_file_idx,len(out_files)
        in_file_text=out_file.replace('.npz','.txt');
        patch_files=util.readLinesFromFile(in_file_text);
        # print out_file,in_file_text,len(patch_files);
        
        
        for idx_img_file,img_file in enumerate(patch_files):
            img_path=img_file;
            
            img_path_split=img_path.split('/');
            img_path_split=[segment for segment in img_path_split if segment!=''];
            mat_name=img_path_split[-3];
            
            class_id_pascal=mat_name[:mat_name.index('_')];
            
            video_id=int(mat_name[mat_name.index('_')+1:mat_name.rindex('_')]);
            shot_id=int(mat_name[mat_name.rindex('_')+1:]);
            tube_id=int(img_path_split[-2]);

            frame_id=img_path_split[-1];
            frame_id=int(frame_id[:frame_id.index('.')]);
            # frame_id+=1

            class_idx_pascal=class_ids_all.index(class_id_pascal);
            deep_features_path=out_file;
            deep_features_idx=idx_img_file;
            layer='fc7';

            frame_path=getFramePath(path_to_data,class_id_pascal,video_id,shot_id,frame_id+1)
            assert os.path.exists(frame_path);
            
            

            mani.insert(idx_global, img_path, frame_id, video_id, tube_id, shot_id, frame_path=frame_path, layer=layer, deep_features_path=deep_features_path, deep_features_idx=deep_features_idx, class_id_pascal=class_id_pascal, class_idx_pascal=class_idx_pascal,commit=False);
            idx_global+=1;
    mani.session.commit();
    mani.closeSession();
    return idx_global;