def make_luna_validation_split(): luna_path = pathfinder.LUNA_DATA_PATH file_list = sorted(glob.glob(luna_path + "/*.mhd")) random.seed(317070) all_pids = [utils_lung.extract_pid_filename(f) for f in file_list] validation_pids = random.sample(all_pids, int(VALIDATION_SET_SIZE * len(file_list))) train_pids = list(set(all_pids) - set(validation_pids)) d = {} d['valid'] = validation_pids d['train'] = train_pids utils.save_pkl(d, pathfinder.LUNA_VALIDATION_SPLIT_PATH)
def make_luna_validation_split(): luna_path = pathfinder.LUNA_DATA_PATH file_list = sorted(glob.glob(luna_path + "/*.mhd")) random.seed(317070) all_pids = [utils_lung.extract_pid_filename(f) for f in file_list] validation_pids = random.sample(all_pids, int(VALIDATION_SET_SIZE * len(file_list))) train_pids = list(set(all_pids) - set(validation_pids)) d = {} d['valid'] = validation_pids d['train'] = train_pids utils.save_pkl(d, pathfinder.LUNA_VALIDATION_SPLIT_PATH)
luna_origin=None) rng = patch_class_config.rng # candidates after segmentations path predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) segmentation_outputs_path = predictions_dir + '/%s' % seg_config_name id2candidates_path = utils_lung.get_candidates_paths(segmentation_outputs_path) # filter our those, who are already generated predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) outputs_path = predictions_dir + '/dsb_c3_s2_p8a1_ls_elias' # TODO write it here correctly exclude_pids = [] if os.path.isdir(outputs_path): exclude_pids = os.listdir(outputs_path) exclude_pids = [utils_lung.extract_pid_filename(p) for p in exclude_pids] for pid in exclude_pids: id2candidates_path.pop(pid, None) data_iterator = data_iterators.CandidatesDSBDataGenerator(data_path=pathfinder.DATA_PATH, transform_params=p_transform, data_prep_fun=data_prep_function, id2candidates_path=id2candidates_path) def build_model(): metadata_dir = utils.get_dir_path('models', pathfinder.METADATA_PATH) metadata_path = utils.find_model_metadata(metadata_dir, patch_class_config.__name__.split('.')[-1]) metadata = utils.load_pkl(metadata_path) print 'Build model'
config_name = sys.argv[1] set_configuration('configs_seg_scan', config_name) predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) outputs_path = predictions_dir + '/%s' % config_name blob_files = sorted(glob.glob(outputs_path + '/*.pkl')) # print(blob_files) pid2annotations = utils_lung.read_luna_annotations(pathfinder.LUNA_LABELS_PATH) tp = 0 n_pos = 0 n_blobs = 0 for p in blob_files: pid = utils_lung.extract_pid_filename(p, '.pkl') blobs = utils.load_pkl(p) n_blobs += len(blobs) print(pid) print('n_blobs', len(blobs)) print('tp / n pos ', int(np.sum(blobs[:, -1])), len(pid2annotations[pid])) if int(np.sum(blobs[:, -1])) < len(pid2annotations[pid]): print('-------- HERE!!!!!! ------------') tp += np.sum(blobs[:, -1]) print('=====================================') print('n patients', len(blob_files)) print('TP', tp) print('n blobs', n_blobs) print(n_pos)
rng = patch_class_config.rng # candidates after segmentations path predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) segmentation_outputs_path = predictions_dir + '/%s' % seg_config_name id2candidates_path = utils_lung.get_candidates_paths(segmentation_outputs_path) # filter our those, who are already generated predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) outputs_path = predictions_dir + '/dsb_c3_s2_p8a1_ls_elias' # TODO write it here correctly exclude_pids = [] if os.path.isdir(outputs_path): exclude_pids = os.listdir(outputs_path) exclude_pids = [utils_lung.extract_pid_filename(p) for p in exclude_pids] for pid in exclude_pids: id2candidates_path.pop(pid, None) data_iterator = data_iterators.CandidatesDSBDataGenerator( data_path=pathfinder.DATA_PATH, transform_params=p_transform, data_prep_fun=data_prep_function, id2candidates_path=id2candidates_path) def build_model(): metadata_dir = utils.get_dir_path('models', pathfinder.METADATA_PATH) metadata_path = utils.find_model_metadata( metadata_dir, patch_class_config.__name__.split('.')[-1])
# predictions path predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) outputs_path = predictions_dir + '/%s' % config_name outputs_img_path = predictions_dir + '/%s_img' % config_name utils.auto_make_dir(outputs_img_path) blob_files = sorted(glob.glob(outputs_path + '/*.pkl')) p_transform = {'patch_size': (64, 64, 64), 'mm_patch_size': (64, 64, 64), 'pixel_spacing': (1., 1., 1.) } for p in blob_files: pid = utils_lung.extract_pid_filename(p, '.pkl') blobs = utils.load_pkl(p) blobs = np.asarray(sorted(blobs, key=lambda x: x[-1], reverse=True)) img, pixel_spacing = utils_lung.read_dicom_scan(pathfinder.DATA_PATH + '/' + pid) print pid for blob in blobs[:10]: patch_center = blob[:3] p1 = blob[-1] print p1 x, _ = data_transforms.transform_patch3d(data=img, luna_annotations=None, patch_center=patch_center, p_transform=p_transform, pixel_spacing=pixel_spacing, luna_origin=None,