Пример #1
0
 def generate_sample(self, counter):
     n = int(np.random.random() *
             (len(self.x_data) - self.sampler_batch_size))
     x_batch = self.x_data[n:n + self.sampler_batch_size, :, :, :]
     z_batch = self.sess.run(self.sample_z_batch_op)
     sampler = [
         ops.inverse_transform(self.G),
         ops.inverse_transform(self.X_recons)
     ]
     g, x_recons = self.sess.run(sampler,
                                 feed_dict={
                                     self.X: x_batch,
                                     self.Z: z_batch
                                 })
     filename = '{}.png'.format(counter)
     recons_path = os.path.join(self.samples_path, 'recons')
     utils.make_sure_path_exits(recons_path)
     utils.save_images_h(os.path.join(recons_path, filename),
                         np.concatenate([x_batch, x_recons], 0),
                         self.sampler_batch_size)
     gens_path = os.path.join(self.samples_path, 'gens')
     utils.make_sure_path_exits(gens_path)
     utils.save_images_h(os.path.join(gens_path, filename), g,
                         int(np.sqrt(self.sampler_batch_size)))
     self.inc_scores.append(self.get_inception_score())
     self.diff_scores.append(self.get_inception_score_diff())
     self._save_score()
     return [gens_path, recons_path]
Пример #2
0
 def _post_train(self):
     imgs = []
     for path in self.sample_imgs:
         img = cv2.imread(path)
         imgs.append(cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
     imgs = np.array(imgs)
     samplefile_path = os.path.join(self.samples_path, 'combined.png')
     utils.save_images_h(samplefile_path, imgs, 10)
Пример #3
0
 def generate_sample(self, counter):
     z = self.sess.run(self.sample_z_batch_op)
     samples = self.sess.run(ops.inverse_transform(self.G),
                             feed_dict={self.Z: z})
     utils.make_sure_path_exits(self.samples_path)
     samplefile_path = os.path.join(self.samples_path,
                                    '{}.png'.format(counter))
     utils.save_images_h(path=samplefile_path,
                         images=samples,
                         imagesPerRow=self.sampler_interpolations)
     return [samplefile_path]
Пример #4
0
    def generate_sample(self, counter):
        z_batch = self.sess.run(self.sample_z_batch_op)
        g = self.sess.run(ops.inverse_transform(self.G),
                          feed_dict={self.Z: z_batch})
        # img_array = tf.transpose(samples, [1, 0, 2, 3, 4])
        utils.make_sure_path_exits(self.samples_path)
        samplefile_path = os.path.join(self.samples_path,
                                       '{}.png'.format(counter))
        utils.save_images_h(samplefile_path, g,
                            int(np.sqrt(self.sampler_batch_size)))

        self.inc_scores.append(self.get_inception_score())
        self._save_score()
        return [samplefile_path]
Пример #5
0
    def generate_sample(self, counter):
        x_batch, z_batch = self.sess.run(
            [self.sample_x_batch_op, self.sample_z_batch_op])
        sampler = [
            ops.inverse_transform(self.G),
            ops.inverse_transform(self.X_recons)
        ]
        g, x_recons = self.sess.run(sampler,
                                    feed_dict={
                                        self.X: x_batch,
                                        self.Z: z_batch
                                    })
        filename = '{}.png'.format(counter)
        recons_path = os.path.join(self.samples_path, 'train/recons')
        utils.make_sure_path_exits(recons_path)
        utils.save_images_h(os.path.join(recons_path, filename),
                            np.concatenate([x_batch, x_recons], 0),
                            self.sampler_batch_size)
        gens_path = os.path.join(self.samples_path, 'train/gens')
        utils.make_sure_path_exits(gens_path)
        utils.save_images_h(os.path.join(gens_path, filename), g,
                            int(np.sqrt(self.sampler_batch_size)))

        # Test set
        x_batch = self.sess.run(self.test_x_batch_op)
        g, x_recons = self.sess.run(sampler,
                                    feed_dict={
                                        self.X: x_batch,
                                        self.Z: self.test_z_batch
                                    })
        filename = '{}.png'.format(counter)
        recons_path = os.path.join(self.samples_path, 'test/recons')
        utils.make_sure_path_exits(recons_path)
        utils.save_images_h(os.path.join(recons_path, filename),
                            np.concatenate([x_batch, x_recons], 0),
                            self.sampler_batch_size)
        gens_path = os.path.join(self.samples_path, 'test/gens')
        utils.make_sure_path_exits(gens_path)
        utils.save_images_h(os.path.join(gens_path, filename), g,
                            int(np.sqrt(self.sampler_batch_size)))
        return [gens_path, recons_path]