def runQuery(self): self.queryTrajectory = GeographicTrajectory(self.trajectoryBag) # XXX: query trajectory should be made on specified time range samples = self.imageBag.desample(-1, True, startOffsetTime=self.startOffset, stopOffsetTime=self.stopOffset) print("Ready") pool4 = mlc.SuperPool(n_cpu=self.numCPU) positions = pool4.map(self.processQuery, samples) print("Done") return positions
def main(): threshold = 0.5 crop_version = 'cropv3' crop_size = 512 np.random.seed(100) pool = mlc.SuperPool(16) for dataset in ['CheXpert-v1.0']: print(dataset) mask_dir = opj(DATA_DIR, 'external', dataset, 'images/masks_1024') image_dir = opj(DATA_DIR, 'external', dataset, 'images/images_1024') out_mask_dir = opj(DATA_DIR, 'external', dataset, 'images/masks_%s' % (crop_version)) out_image_dir = opj(DATA_DIR, 'external', dataset, 'images/images_%s' % (crop_version)) os.makedirs(out_mask_dir, exist_ok=True) os.makedirs(out_image_dir, exist_ok=True) result_dir = opj( RESULT_DIR, 'submissions', 'siim_lung_nobalance_unet_resnet34_cbam_v0a_i256_aug9_symmetriclovaszloss_4folds', 'fold0/epoch_final/default') result_df = pd.read_csv( opj(result_dir, 'results_%s.csv.gz' % 'chexpert')) result_probs = np.load(opj(result_dir, 'prob_%s.npz' % 'chexpert'))['data'] print(result_df.shape, result_probs.shape) params = [] for idx, fname in tqdm(enumerate(result_df[ID].values), total=len(result_df)): param = (idx, crop_size, fname, result_probs[idx], threshold, image_dir, mask_dir, out_mask_dir, out_image_dir, dataset) params.append(param) result_list = pool.map(generate_crop_images, params, description='create cropv3') box_df = pd.concat(result_list, ignore_index=True) box_file = opj(DATA_DIR, 'external', dataset, 'images/boxes_%s.csv.gz' % (crop_version)) box_df.to_csv(box_file, index=False, compression='gzip')
train_df = get_train_df_ohe() # external images public_df = get_public_df_ohe() colors = ['red', 'green', 'blue'] train_df = generate_hash(train_df, colors, dataset='train', is_update=False) public_df = generate_hash(public_df, colors, dataset='external', is_update=False) pool = mlc.SuperPool(3) params = [] for color in colors: base_tran_hash = train_df[color].values base_external_hash = public_df[color].values train_ids = train_df['img_base_path'].values external_ids = public_df['img_base_path'].values base_hash_all = np.concatenate((base_tran_hash, base_external_hash)) ids_all = np.concatenate((train_ids, external_ids)) params.append( (color, threshold, base_hash_all, base_hash_all, ids_all, ids_all)) df_list = pool.map(calc_hash, params)
src, fname, dst, size = param color = fname.replace('.jpg', '').split('_')[-1] try: im = np.array(Image.open(opj(src, fname)))[:, :, COLOR_INDEXS.get(color)] except: print('bad image : %s' % fname) im = cv2.imread(opj(src, fname))[:, :, -1::-1][:, :, COLOR_INDEXS.get(color)] im = cv2.resize(im, (size, size), interpolation=cv2.INTER_LINEAR) cv2.imwrite(opj(dst, fname), im, [int(cv2.IMWRITE_JPEG_QUALITY), 85]) if __name__ == '__main__': print('%s: calling main function ... ' % os.path.basename(__file__)) size = args.size src = opj(EXTERNEL_DIR, 'HPAv18/jpg') dst = opj(DATA_DIR, 'train/external_v18_%d' % size) fnames = np.sort(os.listdir(src)) os.makedirs(dst, exist_ok=True) start_num = max(0, len(os.listdir(dst)) - 48) fnames = fnames[start_num:] params = [(src, fname, dst, size) for fname in fnames] pool = mlc.SuperPool(10) pool.map(do_resize, params, description='resize image') print('success.')
parser.add_argument("--ime", type=str, choices=enhanceMethods, help='Preprocess image with this method') else: print("Enhancement not available; install im_enhance if you want") cmdArgs = parser.parse_args() queryBag = ImageBag(cmdArgs.bagfile, cmdArgs.topic) mapsource = None mapsource = GenericImageDatabase(cmdArgs.mapfile) if hasattr(cmdArgs, 'ime') and (cmdArgs.ime is not None): from place_recognizer.GenericImageMap import ime mapsource.useEnhancement = True mapsource.enhanceMethod = eval('ime.' + prog_arguments.ime) else: imeMethod = False bagLock = Lock() orb = cv2.ORB_create(6000) print("Ready") pool4 = mlc.SuperPool(n_cpu=1) samples = queryBag.desample(-1, True, cmdArgs.start, cmdArgs.stop) positions = pool4.map(processQuery, samples) mlc.save(positions, cmdArgs.output) print("Done")
def do_convert(fname_tif): img = np.array(Image.open(opj(tif_dir, fname_tif))) img = cv2.resize(img, (size, size), interpolation=cv2.INTER_LINEAR) fname_img = fname_tif.replace('.tif', '.png') cv2.imwrite(opj(img_dir, fname_img), img) parser = argparse.ArgumentParser(description='PyTorch Protein Classification') parser.add_argument('--dataset', type=str, default='train', help='dataset') parser.add_argument('--size', type=int, default=1536, help='size') args = parser.parse_args() if __name__ == '__main__': print('%s: calling main function ... ' % os.path.basename(__file__)) size = args.size dataset = args.dataset tif_dir = opj(TIF_DIR, dataset, 'tifs') img_dir = opj(DATA_DIR, dataset, 'images_%d' % size) n_cpu = 3 os.makedirs(img_dir, exist_ok=True) start_num = max(0, len(os.listdir(img_dir)) - n_cpu * 2) fnames = np.sort(os.listdir(tif_dir))[start_num:] pool = mlc.SuperPool(n_cpu) df_list = pool.map(do_convert, fnames, description='resize %s image' % dataset) print('\nsuccess!')