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) # build tag3d tensors tag3d, tag3d_depth_map = self.tag3d_network(labels) tag3d_segmented = Segmentation(threshold=-0.08, smooth_threshold=0.2, sigma=1.5, name='segmentation')(tag3d) tag3d_segmented_blur = GaussianBlur(sigma=3.0)(tag3d_segmented) # get generator params blur_factor, lights, background, details = \ simple_gan_generator(self.generator_units, z_offset, labels_without_bits, tag3d_depth_map, tag3d, depth=self.generator_depth) tag3d_blur = BlendingBlur(sigma=1)([tag3d, blur_factor]) tag3d_lightin = AddLighting(scale_factor=0.85, shift_factor=0.75)([tag3d_blur] + lights) fake_without_noise = Background(name='bg')( [background, tag3d_lightin, tag3d_segmented_blur]) details_high_pass = HighPass(4, nb_steps=4)(details) fake = InBounds(-1.0, 1.0)(merge([details_high_pass, fake_without_noise], mode='sum')) outputs = [ ('tag3d', tag3d), ('tag3d_blur', tag3d_blur), ('tag3d_lightin', tag3d_lightin), ('fake_without_noise', fake_without_noise), ('fake', fake), ] outputs = OrderedDict([(name, name_tensor(x, name)) for name, x in outputs]) 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()))
def test_simple_gan_generator(): nb_units = 2 bs = 8 z = Input(batch_shape=(bs, 50)) labels = Input(batch_shape=(bs, 22)) depth_map = Input(batch_shape=(bs, 1, 16, 16)) tag3d = Input(batch_shape=(bs, 1, 64, 64)) blur, (light_sb, light_sw, light_t), background, details = \ simple_gan_generator(nb_units, z, labels, depth_map, tag3d, depth=2) inputs = [z, labels, depth_map, tag3d] fn = K.function([K.learning_phase(), z, labels, depth_map, tag3d], [blur, light_sb, light_sw, light_t, background, details]) out = fn([1] + [np.random.sample(get_layer(x).output_shape) for x in inputs]) assert out[0].shape == (bs, 1) for i, out_arr in enumerate(out[1:]): assert out_arr.shape == (bs, 1, 64, 64), i + 1
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) # build tag3d tensors tag3d, tag3d_depth_map = self.tag3d_network(labels) tag3d_segmented = Segmentation(threshold=-0.08, smooth_threshold=0.2, sigma=1.5, name='segmentation')(tag3d) tag3d_segmented_blur = GaussianBlur(sigma=3.0)(tag3d_segmented) # get generator params blur_factor, lights, background, details = \ simple_gan_generator(self.generator_units, z_offset, labels_without_bits, tag3d_depth_map, tag3d, depth=self.generator_depth) tag3d_blur = BlendingBlur(sigma=1)([tag3d, blur_factor]) tag3d_lightin = AddLighting(scale_factor=0.85, shift_factor=0.75)([tag3d_blur] + lights) fake_without_noise = Background(name='bg')( [background, tag3d_lightin, tag3d_segmented_blur]) details_high_pass = HighPass(4, nb_steps=4)(details) fake = InBounds(-1.0, 1.0)(merge([details_high_pass, fake_without_noise], mode='sum')) outputs = [ ('tag3d', tag3d), ('tag3d_blur', tag3d_blur), ('tag3d_lightin', tag3d_lightin), ('fake_without_noise', fake_without_noise), ('fake', fake), ] outputs = OrderedDict([(name, name_tensor(x, name)) for name, x in outputs]) 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()))