Esempio n. 1
0
from sklearn.cluster import KMeans
import gc


def nextpow2(x):
    x = int(x)
    return 1 << (x-1).bit_length()


def ispow2(x):
    x = int(x)
    return x > 0 and (x & (x - 1))

args.raw_train_pth = 'data/sunnybrook/WSI'

ufs.make_folder('../' + args.train_image_pth, True)
wsipaths = glob.glob('../{}/*.svs'.format(args.raw_train_pth))

' check if metadata gt.npy already exists to append to it '
metadata_pth = '../{}/gt.npy'.format(args.train_image_pth)
metadata = ufs.fetch_metadata(metadata_pth)

pwhs = {
    np.maximum(args.tile_w, args.tile_h): 0
}
wsipaths = sorted(wsipaths)
patch_id = 0

num_iters = 1  # each iter randomizes the centers of objects

for _ in range(num_iters):
def gallery(array, ncols):
    nindex, height, width, intensity = array.shape
    nrows = nindex//ncols
    assert nindex == nrows*ncols
    # want result.shape = (height*nrows, width*ncols, intensity)
    result = (array.reshape(nrows, ncols, height, width, intensity)
              .swapaxes(1, 2)
              .reshape(height*nrows, width * ncols, intensity))
    return result


args.patch_folder = '/home/ozan/ICIAR2018_BACH_Challenge/Photos'

if __name__ == '__main__':

    ufs.make_folder('../' + args.train_image_pth, False)

    ' map class names to codes '
    cls_codes = {
        'Normal': 0,
        'Benign': 1,
        'InSitu': 2,
        'Invasive': 3
    }

    ' check if metadata gt.npy already exists to append to it '
    metadata_pth = '../{}/gt.npy'.format(args.train_image_pth)
    metadata = ufs.fetch_metadata(metadata_pth)

    cls_folders = glob.glob('{}/*/'.format(args.patch_folder))
train_hr_pths = [
    args.train_hr_image_pth,
    'data/val_hr',
]
raw_train_pths = [
    args.raw_train_pth,
    'data/val',
]

us_kmeans = 8  # undersample the gt for faster processing
scan_level = 2  # of which we extract coordinates
min_center_points = dhr.HR_NUM_CNT_SAMPLES

for ij in range(2):

    ufs.make_folder('../' + train_hr_pths[ij], True)
    wsipaths = sorted(glob.glob('../{}/*.svs'.format(raw_train_pths[ij])))

    ' check if metadata gt.npy already exists to append to it '
    metadata_pth = '../{}/gt.npy'.format(train_hr_pths[ij])
    metadata = ufs.fetch_metadata(metadata_pth)

    for wsipath in tqdm(wsipaths):

        filename = os.path.basename(wsipath)

        'open scan'
        scan = openslide.OpenSlide(wsipath)
        wsi = scan.read_region(
            (0, 0), scan_level,
            scan.level_dimensions[scan_level]).convert('RGB')
Esempio n. 4
0
    args.patch_folder = '/home/ozan/Downloads/breastpathq/datasets/validation'
    args.label_csv_path = '/home/ozan/Downloads/breastpathq-test/val_labels.csv'
    #args.patch_folder = '/home/ozan/Downloads/breastpathq/datasets (copy)/validation'
    #args.label_csv_path = '/home/ozan/Downloads/breastpathq/datasets (copy)/val_labels.csv'
    savepath = args.val_image_pth
else:
    args.patch_folder = '/home/ozan/Downloads/breastpathq/datasets/train'
    args.label_csv_path = '/home/ozan/Downloads/breastpathq/datasets/train_labels.csv'
    #args.patch_folder = '/home/ozan/Downloads/breastpathq/datasets (copy)/train'
    #args.label_csv_path = '/home/ozan/Downloads/breastpathq/datasets (copy)/train_labels.csv'
    savepath = args.train_image_pth

if __name__ == '__main__':

    'train'
    ufs.make_folder('../' + savepath, is_spie)
    metadata_pth_train = '../{}/gt.npy'.format(savepath)
    metadata = ufs.fetch_metadata(metadata_pth_train)

    raw_gt = {}

    cc = []

    with open('{}'.format(args.label_csv_path)) as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        next(csv_reader)
        for row in csv_reader:
            image_id = int(row[0])
            region_id = int(row[1])
            cellularity = float(row[2])
            if image_id not in raw_gt:
Esempio n. 5
0
    root_dir = osp.join(cur_dir, '..')
    # data_dir = osp.join(root_dir, 'data')
    output_dir = osp.join(root_dir, 'output')
    model_dir = osp.join(output_dir, 'model_dump')
    vis_dir = osp.join(output_dir, 'vis')
    log_dir = osp.join(output_dir, 'log')
    result_dir = osp.join(output_dir, 'result')

    ## others
    num_thread = 8
    # gpu_ids = '0'
    # num_gpus = 1
    # continue_train = False

    # def set_args(self, gpu_ids, continue_train=False):
    #     self.gpu_ids = gpu_ids
    #     self.num_gpus = len(self.gpu_ids.split(','))
    #     self.continue_train = continue_train
    #     os.environ["CUDA_VISIBLE_DEVICES"] = self.gpu_ids
    #     print('>>> Using GPU: {}'.format(self.gpu_ids))

cfg = Config()

sys.path.insert(0, osp.join(cfg.root_dir, 'common'))
from utils.filesystem import add_pypath, make_folder
# add_pypath(osp.join(cfg.data_dir))
# add_pypath(osp.join(cfg.data_dir, cfg.dataset))
make_folder(cfg.model_dir)
make_folder(cfg.vis_dir)
make_folder(cfg.log_dir)
make_folder(cfg.result_dir)