Ejemplo n.º 1
0
def main(args):
    """ Main entry.
    """
    logging.info("Creating extractor ...")
    extractor = get_extractor(args.extractor, args.conf_file, {
        'use_gpu': args.gpu,
        'device_id': args.device_ids[0],
    })
    logging.info("\tDone!")

    if extractor is not None:
        lines = [
            l.strip().split(' ') for l in open(args.image_list) if l[0] != '#'
        ]
        heatmap_level = max(args.deep_model_level, args.heatmap_level)
        for l in lines:
            if len(l) > 1:
                wsi, msk_image = ['%s/%s' % (args.input_folder, v) for v in l]
                gen_heatmap(extractor, args.feat_name, wsi, msk_image,
                            args.mask_image_level, args.deep_model_level,
                            heatmap_level, args.window_size, args.augmentation,
                            args.batch_size, args.group_size, args.step_size,
                            args.patchmask)
            else:
                wsi = '%s/%s' % (args.input_folder, l[0])
                gen_heatmap(extractor, args.feat_name, wsi, None,
                            args.mask_image_level, args.deep_model_level,
                            heatmap_level, args.window_size, args.augmentation,
                            args.batch_size, args.group_size, args.step_size,
                            args.patchmask)
Ejemplo n.º 2
0
def main(args):
    """ Main entry.
    """
    logging.info("Creating extractor ...")
    extractor = get_extractor(
        args.extractor, args.conf_file,
        {
            'use_gpu': args.gpu,
            'device_id': args.device_ids[0],
        })
    logging.info("\tLoading Deep Model, Done!")

    if extractor is not None:
        wsi_root = '/home/dywang/CLC/Samples/wsi'
        hp_imgs = [l.strip().split('/')[-1] for l in os.popen('ls %s/T*.png'%args.input_folder)]

        logging.info("\tLoading Classification Model...")
        classifier = load_classificer(args)
        logging.info("\tLoading Classification Model, Done!")

        for hp_img in hp_imgs:
            hp_img_path = '%s/%s'%(args.input_folder, hp_img)
            hp_img_root = hp_img.split('.')[0]
            if hp_img[0] == 'T':
                wsi_path = '%s/01Tumor/%s.tif'%(wsi_root, hp_img_root)
            else:
                wsi_path = '%s/02Normal/%s.tif'%(wsi_root, hp_img_root)

            gen_heatmap_wsi(extractor, args.feat_name, classifier, wsi_path, hp_img_path, \
                args.model_level, args.mask_level, args.heatmap_level, args.window_size, args.augmentation, args.batch_size, args.group_size, args.step_size)
            break
Ejemplo n.º 3
0
def main(args):
    """ Main entry.
    """
    logging.info("Creating extractor ...")
    extractor = get_extractor(args.extractor, args.conf_file, {
        'use_gpu': args.gpu,
        'device_id': args.device_ids[0],
    })
    logging.info("\tLoading Deep Model, Done!")

    if extractor is not None:
        wsi_root = '/home/dywang/CLC/Samples/wsi'
        hp_imgs = []
        hp_imgs += [
            l.strip().split('/')[-1]
            for l in os.popen('ls %s/*.png' % args.input_folder)
        ]

        hp_imgs = hp_imgs[::-1]

        for hp_img in hp_imgs:
            hp_img_path = '%s/%s' % (args.input_folder, hp_img)
            hp_img_root = hp_img.split('.')[0]
            if hp_img_root.startswith('Tumor'):
                wsi_path = '%s/01Tumor/%s.tif' % (wsi_root, hp_img_root)
            elif hp_img_root.startswith("Normal"):
                wsi_path = '%s/02Normal/%s.tif' % (wsi_root, hp_img_root)
            elif hp_img_root.startswith("Test"):
                wsi_path = '%s/03Test/%s.tif' % (wsi_root, hp_img_root)

            gen_heatmap_wsi(extractor, args.feat_name, wsi_path, hp_img_path, args.threshold, \
                args.model_level, args.mask_level, args.heatmap_level, args.window_size, args.augmentation, args.batch_size, args.group_size, args.step_size)
Ejemplo n.º 4
0
def main(args):
    """ Main entry.
    """
    logging.info("Creating extractor ...")

    # Creates the extractor using a specified dictionary of parameters
    #   -> defined in the file deepfeat/__init__.py and
    #   -> the file deepfeat/caffe_extractor.py

    extractor = get_extractor(args.extractor, args.conf_file, {
        'use_gpu': args.gpu,
        'device_id': args.device_ids[0],
    })
    logging.info("\tDone!")

    # Conditions for the extractor existing:
    #   -> a (caffe, lasagne) model has been created
    #   -> a transformer model has been created
    #   -> the network has been successfully compiled

    if extractor is not None:

        # get all of the whole slide image names (stored in the argument wsi_list)
        # the character '#' is used to denote comments

        lines = [
            l.strip().split(' ') for l in open(args.wsi_list) if l[0] != '#'
        ]

        # The input to the program is a b/w tissue map at a particular zoom level (which is an input
        # argument to the code), but it is possible to generate a heatmap of (mitoses, tumors) at any
        # particular zoom level. heatmap_level is the level of the whole slide image from which the heatmap
        # must be generated

        heatmap_level = max(args.deep_model_level, args.heatmap_level)

        print("Found " + str(len(lines)) + " lines.")

        for l in lines:
            if len(l) > 1:
                wsi, msk_image = ['%s/%s' % (args.input_folder, v) for v in l]
                gen_heatmap_wsi(extractor, args.feat_name, wsi, msk_image,
                                args.mask_image_level, args.deep_model_level,
                                heatmap_level, args.window_size,
                                args.augmentation, args.batch_size,
                                args.group_size, args.step_size)
            else:
                wsi = '%s/%s' % (args.input_folder, l[0])
                gen_heatmap_wsi(extractor, args.feat_name, wsi, None,
                                args.mask_image_level, args.deep_model_level,
                                heatmap_level, args.window_size,
                                args.augmentation, args.batch_size,
                                args.group_size, args.step_size)
Ejemplo n.º 5
0
def main(args):
    """ Main entry.
    """
    logging.info("Creating extractor ...")
    extractor = get_extractor(args.extractor, args.conf_file, {
        'use_gpu': args.gpu,
        'device_id': args.device_ids[0],
    })
    logging.info("\tDone!")

    heatmap_level = max(args.deep_model_level, args.heatmap_level)
    if extractor is not None:
        hpgen = update_heatmap_par(args, extractor)
        hpgen.run()
Ejemplo n.º 6
0
def extract_proc(inp_queue, extractor_name, conf_file,
                 img_dir, out_dir, resource):

    logging.info("Creating extractor ...")
    extractor = get_extractor(extractor_name, conf_file, resource)
    logging.info("\tDone!")

    while True:
        inp = inp_queue.get()
        if inp is None:
            break
        first_idx, v_img = inp

        dump_feat(extractor, args.feat_name, v_img,
                  os.path.join(out_dir, "feat_%d.mat" % first_idx))
Ejemplo n.º 7
0
def main(args):
    """ Main entry.
    """
    images, first_idx, last_idx = init(args)

    logging.info("Creating extractor ...")
    extractor = get_extractor(args.extractor, args.conf_file, {
        'use_gpu': args.gpu,
        'device_id': args.device_ids[0],
    })
    logging.info("\tDone!")

    for i in xrange(first_idx, last_idx, args.batch_size):
        i_end = min(i + args.batch_size, last_idx)
        v_img = load_images(args.img_dir, images, i, i_end)
        dump_feat(extractor, args.feat_name, v_img,
                  os.path.join(args.out_dir, "feat_%010d.mat" % i))