Ejemplo n.º 1
0
def test_get_lighting_generator():
    a_shape = (5, 16, 16)
    b_shape = (1, 16, 16)
    c_shape = (1, 16, 16)
    n = 5
    a_input = Input(shape=a_shape)
    b_input = Input(shape=b_shape)
    c_input = Input(shape=c_shape)

    scale_black, scale_white, shift64 = get_lighting_generator(
        [a_input, b_input, c_input], n)

    model = Model([a_input, b_input, c_input],
                  [scale_black, scale_white, shift64])
    model.compile('adam', 'mse')
    bs = (64, )
    a = np.random.sample(bs + a_shape)
    b = np.random.sample(bs + b_shape)
    c = np.random.sample(bs + c_shape)

    y_scale_black = np.random.sample(bs + (1, 64, 64))
    y_scale_white = np.random.sample(bs + (1, 64, 64))
    y_shift64 = np.random.sample(bs + (1, 64, 64))
    model.train_on_batch([a, b, c], [y_scale_black, y_scale_white, y_shift64])
Ejemplo n.º 2
0
def test_get_lighting_generator():
    a_shape = (5, 16, 16)
    b_shape = (1, 16, 16)
    c_shape = (1, 16, 16)
    n = 5
    a_input = Input(shape=a_shape)
    b_input = Input(shape=b_shape)
    c_input = Input(shape=c_shape)

    scale_black, scale_white, shift64 = get_lighting_generator(
        [a_input, b_input, c_input], n)

    model = Model([a_input, b_input, c_input],
                  [scale_black, scale_white, shift64])
    model.compile('adam', 'mse')
    bs = (64, )
    a = np.random.sample(bs + a_shape)
    b = np.random.sample(bs + b_shape)
    c = np.random.sample(bs + c_shape)

    y_scale_black = np.random.sample(bs + (1, 64, 64))
    y_scale_white = np.random.sample(bs + (1, 64, 64))
    y_shift64 = np.random.sample(bs + (1, 64, 64))
    model.train_on_batch([a, b, c], [y_scale_black, y_scale_white, y_shift64])
Ejemplo n.º 3
0
    def _build_generator_given_z_offset_and_labels(self):
        labels = Input(shape=self.labels_shape, name='input_labels')
        z_offset = Input(shape=(self.z_dim_offset, ), name='input_z_offset')

        outputs = OrderedDict()
        labels_without_bits = Subtensor(self.nb_bits,
                                        self.labels_shape[0],
                                        axis=1)(labels)
        raw_tag3d, tag3d_depth_map = self.tag3d_network(labels)

        tag3d = ScaleUnitIntervalTo(-1, 1)(raw_tag3d)
        outputs['tag3d'] = tag3d
        outputs['tag3d_depth_map'] = tag3d_depth_map

        segmentation = Segmentation(threshold=-0.08,
                                    smooth_threshold=0.2,
                                    sigma=1.5,
                                    name='segmentation')

        tag3d_downsampled = PyramidReduce()(tag3d)
        tag3d_segmented = segmentation(raw_tag3d)
        outputs['tag3d_segmented'] = tag3d_segmented
        tag3d_segmented_blur = GaussianBlur(sigma=0.66)(tag3d_segmented)

        out_offset_front = get_offset_front(
            [z_offset, ZeroGradient()(labels_without_bits)],
            self.generator_units)

        light_depth_map = get_preprocess(tag3d_depth_map,
                                         self.preprocess_units,
                                         nb_conv_layers=2)
        light_outs = get_lighting_generator(
            [out_offset_front, light_depth_map], self.generator_units)
        offset_depth_map = get_preprocess(tag3d_depth_map,
                                          self.preprocess_units,
                                          nb_conv_layers=2)
        offset_middle_light = get_preprocess(concat(light_outs),
                                             self.preprocess_units,
                                             resize=['down', 'down'])

        offset_middle_tag3d = get_preprocess(tag3d_downsampled,
                                             self.preprocess_units // 2,
                                             resize=['down', ''],
                                             nb_conv_layers=2)
        out_offset_middle = get_offset_middle([
            out_offset_front, offset_depth_map, offset_middle_light,
            offset_middle_tag3d
        ], self.generator_units)

        offset_back_tag3d_downsampled = get_preprocess(tag3d_downsampled,
                                                       self.preprocess_units //
                                                       2,
                                                       nb_conv_layers=2)

        offset_back_feature_map, out_offset_back = get_offset_back(
            [out_offset_middle, offset_back_tag3d_downsampled],
            self.generator_units)

        blur_factor = get_blur_factor(out_offset_middle, min=0.25, max=1.)
        outputs['blur_factor'] = blur_factor

        tag3d_blur = BlendingBlur(sigma=2.0)([tag3d, blur_factor])
        outputs['tag3d_blur'] = tag3d_blur
        outputs['light_black'] = light_outs[0]
        outputs['light_white'] = light_outs[1]
        outputs['light_shift'] = light_outs[2]
        tag3d_lighten = AddLighting(
            scale_factor=0.90, shift_factor=0.90)([tag3d_blur] + light_outs)
        tag3d_lighten = InBounds(clip=True, weight=15)(tag3d_lighten)
        outputs['tag3d_lighten'] = tag3d_lighten

        outputs['background_offset'] = out_offset_back
        blending = Background(name='blending')(
            [out_offset_back, tag3d_lighten, tag3d_segmented_blur])
        outputs['fake_without_noise'] = blending
        details = get_details([
            blending, tag3d_segmented_blur, tag3d, out_offset_back,
            offset_back_feature_map
        ] + light_outs, self.generator_units)
        outputs['details_offset'] = details
        details_high_pass = HighPass(3.5, nb_steps=3)(details)
        outputs['details_high_pass'] = details_high_pass
        fake = InBounds(-2.0, 2.0)(merge([details_high_pass, blending],
                                         mode='sum'))
        outputs['fake'] = fake
        for name in outputs.keys():
            outputs[name] = name_tensor(outputs[name], name)

        self.generator_given_z_and_labels = Model([z_offset, labels], [fake])
        self.sample_generator_given_z_and_labels_output_names = list(
            outputs.keys())
        self.sample_generator_given_z_and_labels = Model([z_offset, labels],
                                                         list(
                                                             outputs.values()))
Ejemplo n.º 4
0
    def _build_generator_given_z_offset_and_labels(self):
        labels = Input(shape=self.labels_shape, name='input_labels')
        z_offset = Input(shape=(self.z_dim_offset,), name='input_z_offset')

        outputs = OrderedDict()
        labels_without_bits = Subtensor(self.nb_bits, self.labels_shape[0], axis=1)(labels)
        raw_tag3d, tag3d_depth_map = self.tag3d_network(labels)

        tag3d = ScaleUnitIntervalTo(-1, 1)(raw_tag3d)
        outputs['tag3d'] = tag3d
        outputs['tag3d_depth_map'] = tag3d_depth_map

        segmentation = Segmentation(threshold=-0.08, smooth_threshold=0.2,
                                    sigma=1.5, name='segmentation')

        tag3d_downsampled = PyramidReduce()(tag3d)
        tag3d_segmented = segmentation(raw_tag3d)
        outputs['tag3d_segmented'] = tag3d_segmented
        tag3d_segmented_blur = GaussianBlur(sigma=0.66)(tag3d_segmented)

        out_offset_front = get_offset_front([z_offset, ZeroGradient()(labels_without_bits)],
                                            self.generator_units)

        light_depth_map = get_preprocess(tag3d_depth_map, self.preprocess_units,
                                         nb_conv_layers=2)
        light_outs = get_lighting_generator([out_offset_front, light_depth_map],
                                            self.generator_units)
        offset_depth_map = get_preprocess(tag3d_depth_map, self.preprocess_units,
                                          nb_conv_layers=2)
        offset_middle_light = get_preprocess(concat(light_outs), self.preprocess_units,
                                             resize=['down', 'down'])

        offset_middle_tag3d = get_preprocess(tag3d_downsampled,
                                             self.preprocess_units // 2,
                                             resize=['down', ''],
                                             nb_conv_layers=2)
        out_offset_middle = get_offset_middle(
            [out_offset_front, offset_depth_map,
             offset_middle_light, offset_middle_tag3d],
            self.generator_units)

        offset_back_tag3d_downsampled = get_preprocess(tag3d_downsampled,
                                                       self.preprocess_units // 2,
                                                       nb_conv_layers=2)

        offset_back_feature_map, out_offset_back = get_offset_back(
            [out_offset_middle, offset_back_tag3d_downsampled], self.generator_units)

        blur_factor = get_blur_factor(out_offset_middle, min=0.25, max=1.)
        outputs['blur_factor'] = blur_factor

        tag3d_blur = BlendingBlur(sigma=2.0)([tag3d, blur_factor])
        outputs['tag3d_blur'] = tag3d_blur
        outputs['light_black'] = light_outs[0]
        outputs['light_white'] = light_outs[1]
        outputs['light_shift'] = light_outs[2]
        tag3d_lighten = AddLighting(
            scale_factor=0.90, shift_factor=0.90)([tag3d_blur] + light_outs)
        tag3d_lighten = InBounds(clip=True, weight=15)(tag3d_lighten)
        outputs['tag3d_lighten'] = tag3d_lighten

        outputs['background_offset'] = out_offset_back
        blending = Background(name='blending')([out_offset_back, tag3d_lighten,
                                                tag3d_segmented_blur])
        outputs['fake_without_noise'] = blending
        details = get_details(
            [blending, tag3d_segmented_blur, tag3d, out_offset_back,
             offset_back_feature_map] + light_outs, self.generator_units)
        outputs['details_offset'] = details
        details_high_pass = HighPass(3.5, nb_steps=3)(details)
        outputs['details_high_pass'] = details_high_pass
        fake = InBounds(-2.0, 2.0)(
            merge([details_high_pass, blending], mode='sum'))
        outputs['fake'] = fake
        for name in outputs.keys():
            outputs[name] = name_tensor(outputs[name], name)

        self.generator_given_z_and_labels = Model([z_offset, labels], [fake])
        self.sample_generator_given_z_and_labels_output_names = list(outputs.keys())
        self.sample_generator_given_z_and_labels = Model([z_offset, labels],
                                                         list(outputs.values()))