Exemplo n.º 1
0
        def _image_summaries(prefix, y_c0_, x_c1, x_c0):

            if len(self.img_tensor_shape) == 5:
                data_dimension = 3
            elif len(self.img_tensor_shape) == 4:
                data_dimension = 2
            else:
                raise ValueError('Invalid image dimensions')

            if data_dimension == 3:
                y_c0_disp = y_c0_[:, :, :, self.exp_config.image_z_slice, :]
                x_c1_disp = x_c1[:, :, :, self.exp_config.image_z_slice, :]
                x_c0_disp = x_c0[:, :, :, self.exp_config.image_z_slice, :]
            else:
                y_c0_disp = y_c0_
                x_c1_disp = x_c1
                x_c0_disp = x_c0

            sum_gen = tf.summary.image(
                '%s_a_generated_CN' % prefix,
                tf_utils.put_kernels_on_grid(
                    y_c0_disp,
                    min_int=display_range[0],
                    max_int=display_range[1],
                    batch_size=self.exp_config.batch_size))
            sum_c1 = tf.summary.image(
                '%s_example_AD' % prefix,
                tf_utils.put_kernels_on_grid(
                    x_c1_disp,
                    min_int=display_range[0],
                    max_int=display_range[1],
                    batch_size=self.exp_config.batch_size))
            sum_c0 = tf.summary.image(
                '%s_example_CN' % prefix,
                tf_utils.put_kernels_on_grid(
                    x_c0_disp,
                    min_int=display_range[0],
                    max_int=display_range[1],
                    batch_size=self.exp_config.batch_size))

            difference_map_pl = tf.abs(y_c0_disp - x_c1_disp)
            sum_dif = tf.summary.image(
                '%s_b_difference_CN' % prefix,
                tf_utils.put_kernels_on_grid(
                    difference_map_pl, batch_size=self.exp_config.batch_size))

            return tf.summary.merge([sum_gen, sum_c1, sum_c0, sum_dif])
        def _image_summaries(prefix, x, y, y_gt):

            if len(self.image_tensor_shape) == 5:
                data_dimension = 3
            elif len(self.image_tensor_shape) == 4:
                data_dimension = 2
            else:
                raise ValueError('Invalid image dimensions')

            if data_dimension == 3:
                y_disp = tf.expand_dims(y[:, :, :,
                                          self.exp_config.tensorboard_slice],
                                        axis=-1)
                y_gt_disp = tf.expand_dims(
                    y_gt[:, :, :, self.exp_config.tensorboard_slice], axis=-1)
                x_disp = x[:, :, :, self.exp_config.tensorboard_slice, :]
            else:
                y_disp = tf.expand_dims(y, axis=-1)
                y_gt_disp = tf.expand_dims(y_gt, axis=-1)
                x_disp = x

            sum_y = tf.summary.image(
                '%s_mask_predicted' % prefix,
                tf_utils.put_kernels_on_grid(
                    y_disp,
                    batch_size=self.exp_config.batch_size,
                    mode='mask',
                    nlabels=self.exp_config.nlabels))
            sum_y_gt = tf.summary.image(
                '%s_mask_groundtruth' % prefix,
                tf_utils.put_kernels_on_grid(
                    y_gt_disp,
                    batch_size=self.exp_config.batch_size,
                    mode='mask',
                    nlabels=self.exp_config.nlabels))
            sum_x = tf.summary.image(
                '%s_input_image' % prefix,
                tf_utils.put_kernels_on_grid(
                    x_disp,
                    min_int=None,
                    max_int=None,
                    batch_size=self.exp_config.batch_size,
                    mode='image'))

            return tf.summary.merge([sum_y, sum_y_gt, sum_x])
Exemplo n.º 3
0
        def create_im_summary(img, name, rescale_mode, batch_size=self.exp_config.batch_size):

            if tfutils.tfndims(img) == 3:
                img_disp = tf.expand_dims(img, axis=-1)
            elif tfutils.tfndims(img) == 4:
                img_disp = img
            else:
                raise ValueError("Unexpected tensor ndim: %d" % tfutils.tfndims(img))

            nlabels = self.exp_config.nlabels if rescale_mode == 'labelmap' else None
            return tf.summary.image(name, tfutils.put_kernels_on_grid(img_disp, batch_size=batch_size, rescale_mode=rescale_mode, nlabels=nlabels))
# function to make tensor for put_kernels_on_grid out of 2D array
def make_test_tensor(image):
    image = np.reshape(image, (1, ) + image.shape + (1, 1))
    return tf.convert_to_tensor(image)


# self made testcases
thresh_test = np.array([-1.0, 1.0])
scale_test1 = np.array([0.0, 1.0])
scale_test2 = np.array([0.0, 2.0])

# test output
sess1 = tf.Session()
with sess1.as_default():
    thresh_out = tf_utils.put_kernels_on_grid(make_test_tensor(thresh_test),
                                              rescale_mode='centered',
                                              input_range=(0, 2),
                                              cutoff_abs=1.0).eval()
    scale1_out = tf_utils.put_kernels_on_grid(make_test_tensor(scale_test1),
                                              rescale_mode='centered',
                                              input_range=(0, 2)).eval()
    scale2_out = tf_utils.put_kernels_on_grid(make_test_tensor(scale_test2),
                                              rescale_mode='centered',
                                              input_range=(0, 2)).eval()
    print(np.squeeze(thresh_out))
    print(np.squeeze(scale1_out))
    print(np.squeeze(scale2_out))

# import data
data = adni_data_loader.load_and_maybe_process_data(
    input_folder=exp_config.data_root,
    preprocessing_folder=exp_config.preproc_folder,