Ejemplo n.º 1
0
def generate_patches_with_attributions(dataset_dir,
                                       stage_name,
                                       shuffling=True,
                                       patch_size=5):
    cur_dataset_dir = os.path.join(dataset_dir, stage_name)
    slice_names = os.listdir(cur_dataset_dir)
    nc_rois = []
    art_rois = []
    pv_rois = []
    nc_patches = []
    art_patches = []
    pv_patches = []
    labels = []
    nc_attrs = []
    pv_attrs = []
    art_attrs = []

    for slice_name in slice_names:
        if slice_name.startswith('.DS'):
            continue
        print slice_name
        cur_label = int(slice_name[-1])
        cur_slice_dir = os.path.join(cur_dataset_dir, slice_name)

        nc_img_path = glob(os.path.join(cur_slice_dir, 'NC_Image*.mhd'))[0]
        art_img_path = glob(os.path.join(cur_slice_dir, 'ART_Image*.mhd'))[0]
        pv_img_path = glob(os.path.join(cur_slice_dir, 'PV_Image*.mhd'))[0]
        nc_img = np.squeeze(read_mhd_image(nc_img_path))
        art_img = np.squeeze(read_mhd_image(art_img_path))
        pv_img = np.squeeze(read_mhd_image(pv_img_path))
        nc_mask_path = glob(os.path.join(cur_slice_dir, 'NC_Mask*.mhd'))[0]
        art_mask_path = glob(os.path.join(cur_slice_dir, 'ART_Mask*.mhd'))[0]
        pv_mask_path = glob(os.path.join(cur_slice_dir, 'PV_Mask*.mhd'))[0]
        nc_mask = np.squeeze(read_mhd_image(nc_mask_path))
        art_mask = np.squeeze(read_mhd_image(art_mask_path))
        pv_mask = np.squeeze(read_mhd_image(pv_mask_path))

        nc_mask, nc_min_xs, nc_min_ys, nc_max_xs, nc_max_ys = get_filled_mask(
            nc_mask)
        art_mask, art_min_xs, art_min_ys, art_max_xs, art_max_ys = get_filled_mask(
            art_mask)
        pv_mask, pv_min_xs, pv_min_ys, pv_max_xs, pv_max_ys = get_filled_mask(
            pv_mask)
        height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc, edge_nc = calculate_mask_attributes(
            nc_mask)
        nc_attr = [
            height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc
        ]
        height_art, width_art, perimeter_art, area_art, circle_metric_art, edge_art = calculate_mask_attributes(
            art_mask)
        art_attr = [
            height_art, width_art, perimeter_art, area_art, circle_metric_art
        ]
        height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv, edge_pv = calculate_mask_attributes(
            pv_mask)
        pv_attr = [
            height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv
        ]

        nc_liver_mask_path = get_liver_path(cur_slice_dir, 'nc')
        art_liver_mask_path = get_liver_path(cur_slice_dir, 'art')
        pv_liver_mask_path = get_liver_path(cur_slice_dir, 'pv')
        nc_liver_min_xs, nc_liver_min_ys, nc_liver_max_xs, nc_liver_max_ys = read_liver_mask(
            nc_liver_mask_path)
        art_liver_min_xs, art_liver_min_ys, art_liver_max_xs, art_liver_max_ys = read_liver_mask(
            art_liver_mask_path)
        pv_liver_min_xs, pv_liver_min_ys, pv_liver_max_xs, pv_liver_max_ys = read_liver_mask(
            pv_liver_mask_path)
        nc_liver = nc_img[nc_liver_min_xs:nc_liver_max_xs,
                          nc_liver_min_ys:nc_liver_max_ys]
        art_liver = art_img[art_liver_min_xs:art_liver_max_xs,
                            art_liver_min_ys:art_liver_max_ys]
        pv_liver = pv_img[pv_liver_min_xs:pv_liver_max_xs,
                          pv_liver_min_ys:pv_liver_max_ys]

        # 非病灶区域置0
        nc_roi_img = np.copy(nc_img)
        art_roi_img = np.copy(art_img)
        pv_roi_img = np.copy(pv_img)
        nc_roi_img[nc_mask != 1] = 0
        art_roi_img[art_mask != 1] = 0
        pv_roi_img[pv_mask != 1] = 0
        nc_roi_img = nc_roi_img[nc_min_xs:nc_max_xs, nc_min_ys:nc_max_ys]
        art_roi_img = art_roi_img[art_min_xs:art_max_xs, art_min_ys:art_max_ys]
        pv_roi_img = pv_roi_img[pv_min_xs:pv_max_xs, pv_min_ys:pv_max_ys]

        nc_h, nc_w = np.shape(nc_roi_img)
        art_h, art_w = np.shape(art_roi_img)
        pv_h, pv_w = np.shape(pv_roi_img)
        nc_size = nc_h * nc_w
        art_size = art_h * art_w
        pv_size = pv_h * pv_w
        if pv_size >= nc_size and pv_size >= art_size:
            target_h = pv_h
            target_w = pv_w
        elif art_size >= nc_size and art_size >= pv_size:
            target_h = art_h
            target_w = art_w
        elif nc_size >= art_size and nc_size >= pv_size:
            target_h = nc_h
            target_w = nc_w
        nc_roi_img = np.asarray(nc_roi_img, np.float32)
        art_roi_img = np.asarray(art_roi_img, np.float32)
        pv_roi_img = np.asarray(pv_roi_img, np.float32)
        nc_liver = np.asarray(nc_liver, np.float32)
        art_liver = np.asarray(art_liver, np.float32)
        pv_liver = np.asarray(pv_liver, np.float32)
        if target_h < patch_size:
            target_h = patch_size + 1
        if target_w < patch_size:
            target_w = patch_size + 1
        nc_roi_resized = cv2.resize(nc_roi_img, (target_h, target_w))
        art_roi_resized = cv2.resize(art_roi_img, (target_h, target_w))
        pv_roi_resized = cv2.resize(pv_roi_img, (target_h, target_w))
        nc_liver_resized = cv2.resize(nc_liver, (target_h, target_w))
        art_liver_resized = cv2.resize(art_liver, (target_h, target_w))
        pv_liver_resized = cv2.resize(pv_liver, (target_h, target_w))

        nc_roi_final = np.concatenate([
            np.expand_dims(nc_roi_resized, axis=2),
            np.expand_dims(nc_liver_resized, axis=2),
            np.expand_dims(nc_roi_resized, axis=2)
        ],
                                      axis=2)
        art_roi_final = np.concatenate([
            np.expand_dims(art_roi_resized, axis=2),
            np.expand_dims(art_liver_resized, axis=2),
            np.expand_dims(art_roi_resized, axis=2)
        ],
                                       axis=2)
        pv_roi_final = np.concatenate([
            np.expand_dims(pv_roi_resized, axis=2),
            np.expand_dims(pv_liver_resized, axis=2),
            np.expand_dims(pv_roi_resized, axis=2)
        ],
                                      axis=2)
        cur_nc_patches, cur_art_patches, cur_pv_patches = extract_patches(
            nc_roi_final, art_roi_final, pv_roi_final, patch_size=patch_size)
        print('nc mean is ', nc_roi_final.mean((0, 1)))
        print('art mean is ', art_roi_final.mean((0, 1)))
        print('pv mean is ', pv_roi_final.mean((0, 1)))
        print('size of roi is ', np.shape(nc_roi_final),
              np.shape(art_roi_final), np.shape(pv_roi_final),
              len(cur_nc_patches))
        if len(cur_nc_patches) == 0:
            print('the number of patches is zero')
            assert False
        nc_patches.extend(cur_nc_patches)
        art_patches.extend(cur_art_patches)
        pv_patches.extend(cur_pv_patches)
        labels.extend([cur_label] * len(cur_pv_patches))
        nc_rois.extend([nc_roi_final] * len(cur_nc_patches))
        art_rois.extend([art_roi_final] * len(cur_art_patches))
        pv_rois.extend([pv_roi_final] * len(cur_pv_patches))
        nc_attrs.extend([nc_attr] * len(cur_nc_patches))
        art_attrs.extend([art_attr] * len(cur_art_patches))
        pv_attrs.extend([pv_attr] * len(cur_pv_patches))

        if len(nc_rois) != len(nc_patches) or len(nc_rois) != len(
                art_patches) or len(nc_patches) != len(art_patches) or len(
                    nc_rois) != len(pv_patches) or len(nc_rois) != len(
                        pv_rois):
            print('the number is not equal')
            assert False

    nc_rois = np.asarray(nc_rois)
    art_rois = np.asarray(art_rois)
    pv_rois = np.asarray(pv_rois)
    nc_patches = np.asarray(nc_patches)
    art_patches = np.asarray(art_patches)
    pv_patches = np.asarray(pv_patches)
    nc_attrs = np.asarray(nc_attrs)
    art_attrs = np.asarray(art_attrs)
    pv_attrs = np.asarray(pv_attrs)
    labels = np.asarray(labels)
    nc_attrs /= config.MAX_ATTRS
    art_attrs /= config.MAX_ATTRS
    pv_attrs /= config.MAX_ATTRS
    if shuffling:
        random.seed(RANDOM_SEED)
        idx = range(len(nc_rois))
        random.shuffle(idx)
        nc_rois = nc_rois[idx]
        art_rois = art_rois[idx]
        pv_rois = pv_rois[idx]
        nc_patches = nc_patches[idx]
        art_patches = art_patches[idx]
        pv_patches = pv_patches[idx]

        nc_attrs = nc_attrs[idx]
        art_attrs = art_attrs[idx]
        pv_attrs = pv_attrs[idx]
        labels = labels[idx]
        print(len(nc_rois), len(art_rois), len(pv_rois), len(nc_patches),
              len(art_patches), len(pv_patches), len(nc_attrs), len(art_attrs),
              len(pv_attrs), len(labels))
    attrs = np.concatenate([nc_attrs, art_attrs, pv_attrs], axis=1)
    print('the shape of nc_roi is ', np.shape(nc_rois))
    print('nc_roi mean is ', compute_mean_img(nc_rois))
    print('art_roi mean is ', compute_mean_img(art_rois))
    print('pv_roi mean is ', compute_mean_img(pv_rois))
    print('attrs shape is ', np.shape(attrs))
    return nc_rois, art_rois, pv_rois, nc_patches, art_patches, pv_patches, attrs, labels
Ejemplo n.º 2
0
def generate_roi_feature_with_attributions(
        cur_dataset_dir, slice_name, patch_size, sess, logits,
        nc_roi_placeholder, art_roi_placeholder, pv_roi_placeholder,
        nc_patch_placeholder, art_patch_placeholder, pv_patch_placeholder,
        attrs_placeholder, batch_size_placeholder):

    cur_slice_dir = os.path.join(cur_dataset_dir, slice_name)

    nc_img_path = glob(os.path.join(cur_slice_dir, 'NC_Image*.mhd'))[0]
    art_img_path = glob(os.path.join(cur_slice_dir, 'ART_Image*.mhd'))[0]
    pv_img_path = glob(os.path.join(cur_slice_dir, 'PV_Image*.mhd'))[0]
    nc_img = np.squeeze(read_mhd_image(nc_img_path))
    art_img = np.squeeze(read_mhd_image(art_img_path))
    pv_img = np.squeeze(read_mhd_image(pv_img_path))
    nc_mask_path = glob(os.path.join(cur_slice_dir, 'NC_Mask*.mhd'))[0]
    art_mask_path = glob(os.path.join(cur_slice_dir, 'ART_Mask*.mhd'))[0]
    pv_mask_path = glob(os.path.join(cur_slice_dir, 'PV_Mask*.mhd'))[0]
    nc_mask = np.squeeze(read_mhd_image(nc_mask_path))
    art_mask = np.squeeze(read_mhd_image(art_mask_path))
    pv_mask = np.squeeze(read_mhd_image(pv_mask_path))

    nc_mask, nc_min_xs, nc_min_ys, nc_max_xs, nc_max_ys = get_filled_mask(
        nc_mask)
    art_mask, art_min_xs, art_min_ys, art_max_xs, art_max_ys = get_filled_mask(
        art_mask)
    pv_mask, pv_min_xs, pv_min_ys, pv_max_xs, pv_max_ys = get_filled_mask(
        pv_mask)
    height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc, edge_nc = calculate_mask_attributes(
        nc_mask)
    nc_attr = [height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc]
    height_art, width_art, perimeter_art, area_art, circle_metric_art, edge_art = calculate_mask_attributes(
        art_mask)
    art_attr = [
        height_art, width_art, perimeter_art, area_art, circle_metric_art
    ]
    height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv, edge_pv = calculate_mask_attributes(
        pv_mask)
    pv_attr = [height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv]

    nc_liver_mask_path = get_liver_path(cur_slice_dir, 'nc')
    art_liver_mask_path = get_liver_path(cur_slice_dir, 'art')
    pv_liver_mask_path = get_liver_path(cur_slice_dir, 'pv')
    nc_liver_min_xs, nc_liver_min_ys, nc_liver_max_xs, nc_liver_max_ys = read_liver_mask(
        nc_liver_mask_path)
    art_liver_min_xs, art_liver_min_ys, art_liver_max_xs, art_liver_max_ys = read_liver_mask(
        art_liver_mask_path)
    pv_liver_min_xs, pv_liver_min_ys, pv_liver_max_xs, pv_liver_max_ys = read_liver_mask(
        pv_liver_mask_path)
    nc_liver = nc_img[nc_liver_min_xs:nc_liver_max_xs,
                      nc_liver_min_ys:nc_liver_max_ys]
    art_liver = art_img[art_liver_min_xs:art_liver_max_xs,
                        art_liver_min_ys:art_liver_max_ys]
    pv_liver = pv_img[pv_liver_min_xs:pv_liver_max_xs,
                      pv_liver_min_ys:pv_liver_max_ys]

    # 非病灶区域置0
    nc_roi_img = np.copy(nc_img)
    art_roi_img = np.copy(art_img)
    pv_roi_img = np.copy(pv_img)
    nc_roi_img[nc_mask != 1] = 0
    art_roi_img[art_mask != 1] = 0
    pv_roi_img[pv_mask != 1] = 0
    nc_roi_img = nc_roi_img[nc_min_xs:nc_max_xs, nc_min_ys:nc_max_ys]
    art_roi_img = art_roi_img[art_min_xs:art_max_xs, art_min_ys:art_max_ys]
    pv_roi_img = pv_roi_img[pv_min_xs:pv_max_xs, pv_min_ys:pv_max_ys]

    nc_h, nc_w = np.shape(nc_roi_img)
    art_h, art_w = np.shape(art_roi_img)
    pv_h, pv_w = np.shape(pv_roi_img)
    nc_size = nc_h * nc_w
    art_size = art_h * art_w
    pv_size = pv_h * pv_w
    if pv_size >= nc_size and pv_size >= art_size:
        target_h = pv_h
        target_w = pv_w
    elif art_size >= nc_size and art_size >= pv_size:
        target_h = art_h
        target_w = art_w
    elif nc_size >= art_size and nc_size >= pv_size:
        target_h = nc_h
        target_w = nc_w
    nc_roi_img = np.asarray(nc_roi_img, np.float32)
    art_roi_img = np.asarray(art_roi_img, np.float32)
    pv_roi_img = np.asarray(pv_roi_img, np.float32)
    nc_liver = np.asarray(nc_liver, np.float32)
    art_liver = np.asarray(art_liver, np.float32)
    pv_liver = np.asarray(pv_liver, np.float32)
    nc_roi_resized = cv2.resize(nc_roi_img, (target_h, target_w))
    art_roi_resized = cv2.resize(art_roi_img, (target_h, target_w))
    pv_roi_resized = cv2.resize(pv_roi_img, (target_h, target_w))
    nc_liver_resized = cv2.resize(nc_liver, (target_h, target_w))
    art_liver_resized = cv2.resize(art_liver, (target_h, target_w))
    pv_liver_resized = cv2.resize(pv_liver, (target_h, target_w))

    nc_roi_final = np.concatenate([
        np.expand_dims(nc_roi_resized, axis=2),
        np.expand_dims(nc_liver_resized, axis=2),
        np.expand_dims(nc_roi_resized, axis=2)
    ],
                                  axis=2)
    art_roi_final = np.concatenate([
        np.expand_dims(art_roi_resized, axis=2),
        np.expand_dims(art_liver_resized, axis=2),
        np.expand_dims(art_roi_resized, axis=2)
    ],
                                   axis=2)
    pv_roi_final = np.concatenate([
        np.expand_dims(pv_roi_resized, axis=2),
        np.expand_dims(pv_liver_resized, axis=2),
        np.expand_dims(pv_roi_resized, axis=2)
    ],
                                  axis=2)
    print('nc mean is ', nc_roi_final.mean((0, 1)))
    print('art mean is ', art_roi_final.mean((0, 1)))
    print('pv mean is ', pv_roi_final.mean((0, 1)))
    cur_nc_patches, cur_art_patches, cur_pv_patches = extract_patches(
        nc_roi_final, art_roi_final, pv_roi_final, patch_size=patch_size)

    nc_rois = [nc_roi_final] * len(cur_nc_patches)
    art_rois = [art_roi_final] * len(cur_art_patches)
    pv_rois = [pv_roi_final] * len(cur_pv_patches)
    nc_attrs = [nc_attr] * len(cur_nc_patches)
    art_attrs = [art_attr] * len(cur_art_patches)
    pv_attrs = [pv_attr] * len(cur_pv_patches)

    labels = [int(slice_name[-1])] * len(cur_pv_patches)
    dataset = Generate_Batch_Data_v2_with_attributes(
        nc_rois, art_rois, pv_rois, cur_nc_patches, cur_art_patches,
        cur_pv_patches, nc_attrs, art_attrs, pv_attrs, config.val_batch_size,
        labels)
    generator = dataset.generate_next_batch()
    logits_values = []
    batch_count = 1
    while True:
        nc_batch_rois, art_batch_rois, pv_batch_rois, \
        nc_batch_patches, art_batch_patches, pv_batch_patches, \
        attrs, batch_label, epoch_end = generator.next()
        feed_dict = {
            nc_roi_placeholder: nc_batch_rois,
            art_roi_placeholder: art_batch_rois,
            pv_roi_placeholder: pv_batch_rois,
            nc_patch_placeholder: nc_batch_patches,
            art_patch_placeholder: art_batch_patches,
            pv_patch_placeholder: pv_batch_patches,
            batch_size_placeholder: len(pv_batch_patches),
            attrs_placeholder: attrs
        }
        logits_v = sess.run(logits, feed_dict=feed_dict)
        logits_values.extend(np.argmax(logits_v, axis=1))
        if batch_count % 100 == 0:
            print logits_values
        batch_count += 1
        if epoch_end:
            break
    print logits_values
    return logits_values
Ejemplo n.º 3
0
def generate_roi_feature_with_attributions(
        cur_dataset_dir, slice_name, patch_size, sess, logits,
        nc_roi_placeholder, art_roi_placeholder, pv_roi_placeholder,
        nc_patch_placeholder, art_patch_placeholder, pv_patch_placeholder,
        attrs_placeholder, batch_size_placeholder):

    cur_slice_dir = os.path.join(cur_dataset_dir, slice_name)
    print('cur_slice_dir is ', cur_slice_dir)
    nc_img_path = glob(os.path.join(cur_slice_dir, 'NC_Image*.mhd'))[0]
    art_img_path = glob(os.path.join(cur_slice_dir, 'ART_Image*.mhd'))[0]
    pv_img_path = glob(os.path.join(cur_slice_dir, 'PV_Image*.mhd'))[0]
    nc_img = np.squeeze(read_mhd_image(nc_img_path))
    art_img = np.squeeze(read_mhd_image(art_img_path))
    pv_img = np.squeeze(read_mhd_image(pv_img_path))
    nc_mask_path = glob(os.path.join(cur_slice_dir, 'NC_Mask*.mhd'))[0]
    art_mask_path = glob(os.path.join(cur_slice_dir, 'ART_Mask*.mhd'))[0]
    pv_mask_path = glob(os.path.join(cur_slice_dir, 'PV_Mask*.mhd'))[0]
    nc_mask = np.squeeze(read_mhd_image(nc_mask_path))
    art_mask = np.squeeze(read_mhd_image(art_mask_path))
    pv_mask = np.squeeze(read_mhd_image(pv_mask_path))

    nc_mask, nc_min_xs, nc_min_ys, nc_max_xs, nc_max_ys = get_filled_mask(
        nc_mask)
    art_mask, art_min_xs, art_min_ys, art_max_xs, art_max_ys = get_filled_mask(
        art_mask)
    pv_mask, pv_min_xs, pv_min_ys, pv_max_xs, pv_max_ys = get_filled_mask(
        pv_mask)
    height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc, edge_nc = calculate_mask_attributes(
        nc_mask)
    nc_attr = [height_nc, width_nc, perimeter_nc, area_nc, circle_metric_nc]
    height_art, width_art, perimeter_art, area_art, circle_metric_art, edge_art = calculate_mask_attributes(
        art_mask)
    art_attr = [
        height_art, width_art, perimeter_art, area_art, circle_metric_art
    ]
    height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv, edge_pv = calculate_mask_attributes(
        pv_mask)
    pv_attr = [height_pv, width_pv, perimeter_pv, area_pv, circle_metric_pv]

    nc_liver_mask_path = get_liver_path(cur_slice_dir, 'nc')
    art_liver_mask_path = get_liver_path(cur_slice_dir, 'art')
    pv_liver_mask_path = get_liver_path(cur_slice_dir, 'pv')
    nc_liver_min_xs, nc_liver_min_ys, nc_liver_max_xs, nc_liver_max_ys = read_liver_mask(
        nc_liver_mask_path)
    art_liver_min_xs, art_liver_min_ys, art_liver_max_xs, art_liver_max_ys = read_liver_mask(
        art_liver_mask_path)
    pv_liver_min_xs, pv_liver_min_ys, pv_liver_max_xs, pv_liver_max_ys = read_liver_mask(
        pv_liver_mask_path)
    nc_liver = nc_img[nc_liver_min_xs:nc_liver_max_xs,
                      nc_liver_min_ys:nc_liver_max_ys]
    art_liver = art_img[art_liver_min_xs:art_liver_max_xs,
                        art_liver_min_ys:art_liver_max_ys]
    pv_liver = pv_img[pv_liver_min_xs:pv_liver_max_xs,
                      pv_liver_min_ys:pv_liver_max_ys]

    # 非病灶区域置0
    nc_roi_img = np.copy(nc_img)
    art_roi_img = np.copy(art_img)
    pv_roi_img = np.copy(pv_img)
    nc_roi_img[nc_mask != 1] = 0
    art_roi_img[art_mask != 1] = 0
    pv_roi_img[pv_mask != 1] = 0
    nc_roi_img = nc_roi_img[nc_min_xs:nc_max_xs, nc_min_ys:nc_max_ys]
    art_roi_img = art_roi_img[art_min_xs:art_max_xs, art_min_ys:art_max_ys]
    pv_roi_img = pv_roi_img[pv_min_xs:pv_max_xs, pv_min_ys:pv_max_ys]

    nc_h, nc_w = np.shape(nc_roi_img)
    art_h, art_w = np.shape(art_roi_img)
    pv_h, pv_w = np.shape(pv_roi_img)
    nc_size = nc_h * nc_w
    art_size = art_h * art_w
    pv_size = pv_h * pv_w
    if pv_size >= nc_size and pv_size >= art_size:
        target_h = pv_h
        target_w = pv_w
    elif art_size >= nc_size and art_size >= pv_size:
        target_h = art_h
        target_w = art_w
    elif nc_size >= art_size and nc_size >= pv_size:
        target_h = nc_h
        target_w = nc_w
    if target_h < patch_size:
        target_h = patch_size + 1
    if target_w < patch_size:
        target_w = patch_size + 1
    nc_roi_img = np.asarray(nc_roi_img, np.float32)
    art_roi_img = np.asarray(art_roi_img, np.float32)
    pv_roi_img = np.asarray(pv_roi_img, np.float32)
    nc_liver = np.asarray(nc_liver, np.float32)
    art_liver = np.asarray(art_liver, np.float32)
    pv_liver = np.asarray(pv_liver, np.float32)
    nc_roi_resized = cv2.resize(nc_roi_img, (target_h, target_w))
    art_roi_resized = cv2.resize(art_roi_img, (target_h, target_w))
    pv_roi_resized = cv2.resize(pv_roi_img, (target_h, target_w))
    nc_liver_resized = cv2.resize(nc_liver, (target_h, target_w))
    art_liver_resized = cv2.resize(art_liver, (target_h, target_w))
    pv_liver_resized = cv2.resize(pv_liver, (target_h, target_w))

    nc_roi_final = np.concatenate([
        np.expand_dims(nc_roi_resized, axis=2),
        np.expand_dims(nc_liver_resized, axis=2),
        np.expand_dims(nc_roi_resized, axis=2)
    ],
                                  axis=2)
    art_roi_final = np.concatenate([
        np.expand_dims(art_roi_resized, axis=2),
        np.expand_dims(art_liver_resized, axis=2),
        np.expand_dims(art_roi_resized, axis=2)
    ],
                                   axis=2)
    pv_roi_final = np.concatenate([
        np.expand_dims(pv_roi_resized, axis=2),
        np.expand_dims(pv_liver_resized, axis=2),
        np.expand_dims(pv_roi_resized, axis=2)
    ],
                                  axis=2)
    patch_step = 1
    cur_nc_patches, cur_art_patches, cur_pv_patches = extract_patches(
        nc_roi_final,
        art_roi_final,
        pv_roi_final,
        patch_size=patch_size,
        patch_step=patch_step)

    print('nc mean is ', nc_roi_final.mean((0, 1)))
    print('art mean is ', art_roi_final.mean((0, 1)))
    print('pv mean is ', pv_roi_final.mean((0, 1)))
    print('size of roi is ', np.shape(nc_roi_final), np.shape(art_roi_final),
          np.shape(pv_roi_final), len(cur_nc_patches))
    if len(cur_nc_patches) == 0:
        print('the number of patches is zero')
        assert False
    nc_rois = [nc_roi_final] * len(cur_nc_patches)
    art_rois = [art_roi_final] * len(cur_art_patches)
    pv_rois = [pv_roi_final] * len(cur_pv_patches)
    nc_attrs = [nc_attr] * len(cur_nc_patches)
    art_attrs = [art_attr] * len(cur_art_patches)
    pv_attrs = [pv_attr] * len(cur_pv_patches)

    labels = [int(slice_name[-1])] * len(cur_pv_patches)
    dataset = Generate_Batch_Data_v2_with_attributes(
        nc_rois, art_rois, pv_rois, cur_nc_patches, cur_art_patches,
        cur_pv_patches, nc_attrs, art_attrs, pv_attrs, config.val_batch_size,
        labels)
    generator = dataset.generate_next_batch()
    logits_values = []
    batch_count = 1
    while True:
        nc_batch_rois, art_batch_rois, pv_batch_rois, \
        nc_batch_patches, art_batch_patches, pv_batch_patches, \
        attrs, batch_label, epoch_end = generator.next()
        feed_dict = {
            nc_roi_placeholder: nc_batch_rois,
            art_roi_placeholder: art_batch_rois,
            pv_roi_placeholder: pv_batch_rois,
            nc_patch_placeholder: nc_batch_patches,
            art_patch_placeholder: art_batch_patches,
            pv_patch_placeholder: pv_batch_patches,
            batch_size_placeholder: len(pv_batch_patches),
            attrs_placeholder: attrs
        }
        logits_v = sess.run(logits, feed_dict=feed_dict)
        logits_values.extend(np.argmax(logits_v, axis=1))
        if batch_count % 100 == 0:
            print batch_count * config.val_batch_size, '/', len(nc_rois)
        batch_count += 1
        if epoch_end:
            break
    print logits_values
    count_idx = 0
    label_map = np.zeros([target_h, target_w, 3], np.uint8)
    label_rgb_mapping = {
        0: [0, 200, 0],
        1: [0, 0, 200],
        2: [255, 0, 0],
        3: [0, 255, 255],
        4: [200, 200, 0]
    }
    for i in range(patch_size / 2, target_h - patch_size / 2, patch_step):
        for j in range(patch_size / 2, target_w - patch_size / 2, patch_step):
            label_map[i, j, :] = label_rgb_mapping[logits_values[count_idx]]
            count_idx += 1
            # cur_nc_patch = nc_roi[i - patch_size / 2:i + patch_size / 2 + 1,
            #             j - patch_size / 2: j + patch_size / 2 + 1, :]
            # cur_art_patch = art_roi[i - patch_size / 2:i + patch_size / 2 + 1,
            #                j - patch_size / 2: j + patch_size / 2 + 1, :]
            # cur_pv_patch = pv_roi[i - patch_size / 2:i + patch_size / 2 + 1,
            #                j - patch_size / 2: j + patch_size / 2 + 1, :]
            # nc_patches.append(cur_nc_patch)
            # art_patches.append(cur_art_patch)
            # pv_patches.append(cur_pv_patch)

    # return logits_values, labels
    return label_map