def main(): args = parse_args() args.pred_list_dir = os.path.join(args.result_dir, 'List_Masks') if args.del_overlap: args.submission_path = os.path.join(args.result_dir, 'csv_files_del_overlap') else: args.submission_path = os.path.join(args.result_dir, 'csv_files') if not os.path.exists(args.submission_path): os.mkdir(args.submission_path) args.pred_image_list = os.listdir(args.pred_list_dir) test_video_list = os.listdir(args.test_video_list_dir) jobs = [] for i in xrange(len(test_video_list)): p = multiprocessing.Process(target=convertCsvWorker, args=(test_video_list[i], args)) jobs.append(p) p.start() # waiting for all jobs to finish for j in jobs: j.join() print("Finishing converting all the csv fils")
def main(): args = parse_args() frames = [] dataset = WAD_CVPR2018(args.dataset_dir) if args.del_overlap: args.submission_path = os.path.join(args.result_dir, 'csv_files_del_overlap') else: args.submission_path = os.path.join(args.result_dir, 'csv_files') print(args.submission_path) names = ['ImageId', 'LabelId', 'Confidence', 'PixelCount', 'EncodedPixels'] for csv_file in os.listdir(args.submission_path): df = pd.read_csv(os.path.join(args.submission_path, csv_file), names=names) df_new = df[df.PixelCount != 0] frames.append(df_new) if len(df) != len(df_new): print("We have zeros elements in the file: %s" % csv_file) sub_csv = pd.concat(frames, axis=0) sub_csv = sub_csv.dropna() # sub_csv.Confidence = 1 # THIS LINE NEEDS TO BE DELETED! #confs = [0.1, 0.2, 0.3, 0.4, 0.5] confs = [0.6, 0.7, 0.8, 0.9] for i in tqdm(range(len(confs))): conf = confs[i] sub_csv = sub_csv.reset_index(drop=True) sub_csv_new = submission_sanity_check(sub_csv, args.test_img_dir) sub_csv_new.Confidence = sub_csv_new.Confidence.astype(float) sub_csv_new = sub_csv_new.loc[sub_csv_new['Confidence'] > conf] sub_csv_new = sub_csv_new.reset_index(drop=True) sub_csv_new = sub_csv_new.reindex(columns=['ImageId', 'LabelId', 'PixelCount', 'Confidence', 'EncodedPixels']) sub_csv_new.LabelId = sub_csv_new.LabelId.astype(int) sub_csv_new.PixelCount = sub_csv_new.PixelCount.astype(int) sub_csv_new.Confidence = sub_csv_new.Confidence.round(6) # print some statistics count = [] for l in np.unique(sub_csv_new.LabelId): count.append(np.sum(sub_csv_new['LabelId'] == l)) count_ratio = np.array([x/np.sum(count) for x in count]) for i, l in enumerate(np.unique(sub_csv_new.LabelId)): print("%s --> %d --> %0.3f" %(dataset.id_map_to_cat[l], count[i], count_ratio[i])) print('Total instance number for conf %.1f is %d' % (conf, len(sub_csv_new))) if args.del_overlap: csv_file_name = os.path.join(args.result_dir, 'combined_%.2f_del_overlap.csv' % conf) else: csv_file_name = os.path.join(args.result_dir, 'combined_%.2f.csv' % conf) sub_csv_new.to_csv(csv_file_name, header=True, index=False) print("Finish saving file t: %s" % csv_file_name)
def main(): args = parse_args() args.pred_list_dir = os.path.join(args.result_dir, 'List_Masks') if args.del_overlap: args.submission_path = os.path.join(args.result_dir, 'csv_files_del_overlap') else: args.submission_path = os.path.join(args.result_dir, 'csv_files') if not os.path.exists(args.submission_path): os.mkdir(args.submission_path) args.pred_image_list = os.listdir(args.pred_list_dir) test_video_list = os.listdir(args.test_video_list_dir) jobs = [] for i in xrange(len(test_video_list)): video_path = test_video_list[i] videoname = video_path.split('.')[0] print('videoname:' + videoname) groundTruthImgList = [] predictionImgList = [] groundTruthList = open( os.path.join(args.test_video_list_dir, video_path), "r") groundTruthListlines = groundTruthList.readlines() for groundTruthListline in groundTruthListlines: gtfilename = groundTruthListline.split('\n')[0].split('\t')[0] groundTruthImgList.append(gtfilename) # We also read groudtruth md5 mapping mapping_file = open( os.path.join(args.mapping_dir, 'md5_mapping_' + video_path), "r") mappingLines = mapping_file.readlines() mapping_dict = {} for mapping in mappingLines: mapping_dict[mapping.split('\t')[1].replace( '\n', '')] = mapping.split('\t')[0] for gt in groundTruthImgList: predictionImgList.append(getPrediction(gt, args, mapping_dict)) for list_index, filename in enumerate(groundTruthImgList): args.csv_file_image = os.path.join( args.submission_path, videoname + '_FRAME_%d' % list_index + '_' + filename.split('/')[-1][:-4] + '.csv') if not os.path.exists(args.csv_file_image): if args.del_overlap: p = multiprocessing.Process( target=convertImages_with_postprocessing_image, args=(filename, list_index, predictionImgList, args, mapping_dict)) else: p = multiprocessing.Process( target=convertImages_with_image, args=(filename, list_index, predictionImgList, args, mapping_dict)) jobs.append(p) p.start() if len(jobs) > args.num_threads: jobs[-args.num_threads].join() # waiting for all jobs to finish for j in jobs: j.join() print("Finishing converting all the csv fils")