Beispiel #1
0
    def _build_graph(self, x_train, hm_reg_scale, init_gamma, height_map_noise):
        input_img, depth_map = x_train

        with tf.device('/device:GPU:0'):
            height_map = optics.get_fourier_height_map(self.wave_resolution[0],
                                                       0.75,
                                                       height_map_regularizer=optics.laplace_l1_regularizer(
                                                       hm_reg_scale))

            optical_system = optics.SingleLensSetup(height_map=height_map,
                                        wave_resolution=self.wave_resolution,
                                        wave_lengths=self.wave_lengths,
                                        sensor_distance=self.sensor_distance,
                                        sensor_resolution=(self.patch_size, self.patch_size),
                                        input_sample_interval=self.sampling_interval,
                                        refractive_idcs=self.refractive_idcs,
                                        height_tolerance=height_map_noise,
                                        use_planar_incidence=False,
                                        depth_bins=self.depth_bins,
                                        upsample=False,
                                        psf_resolution=self.wave_resolution,
                                        target_distance=None)

            sensor_img = optical_system.get_sensor_img(input_img=input_img,
                                                       noise_sigma=None,
                                                       depth_dependent=True,
                                                       depth_map=depth_map)
            
            U_net = net.U_Net()
            output_image = U_net.build(sensor_img)
 
            optics.attach_summaries('output_image', output_image, image=True, log_image=False)

            return output_image
Beispiel #2
0
    def _build_graph(self, x_train, global_step, hm_reg_scale, init_gamma, height_map_noise, learned_target_depth, hm_init_type='random_normal'):
        input_img, depth_map = x_train

        with tf.device('/device:GPU:0'):
            with tf.variable_scope("optics"):
                height_map = optics.get_fourier_height_map(self.wave_resolution[0],
                                                           0.625,
                                                           height_map_regularizer=optics.laplace_l1_regularizer(hm_reg_scale))

                target_depth_initializer = tf.constant_initializer(1.)
                target_depth = tf.get_variable(name="target_depth",
                                        shape=(),
                                        dtype=tf.float32,
                                        trainable=True,
                                        initializer=target_depth_initializer)
                target_depth = tf.square(target_depth)
                tf.summary.scalar('target_depth', target_depth)

                optical_system = optics.SingleLensSetup(height_map=height_map,
                                                 wave_resolution=self.wave_resolution,
                                                 wave_lengths=self.wave_lengths,
                                                 sensor_distance=self.distance,
                                                 sensor_resolution=(self.patch_size, self.patch_size),
                                                 input_sample_interval=self.input_sample_interval,
                                                 refractive_idcs=self.refractive_idcs,
                                                 height_tolerance=height_map_noise,
                                                 use_planar_incidence=False,
                                                 depth_bins=self.depth_bins,
                                                 upsample=False,
                                                 psf_resolution=self.wave_resolution,
                                                 target_distance=target_depth)

                noise_sigma = tf.random_uniform(minval=0.001, maxval=0.02, shape=[])
                sensor_img = optical_system.get_sensor_img(input_img=input_img,
                                                           noise_sigma=noise_sigma,
                                                           depth_dependent=True,
                                                           depth_map=depth_map)
                output_image = tf.cast(sensor_img, tf.float32)

            # Now we deconvolve
            pad_width = output_image.shape.as_list()[1]//2

            output_image = tf.pad(output_image, [[0,0],[pad_width, pad_width],[pad_width,pad_width],[0,0]], mode='SYMMETRIC')
            output_image = deconv.inverse_filter(output_image, output_image, optical_system.target_psf, init_gamma=init_gamma)
            output_image = output_image[:,pad_width:-pad_width,pad_width:-pad_width,:]

            optics.attach_summaries('output_image', output_image, image=True, log_image=False)

            return output_image