Example #1
0
    def test_float_1_converts_to_uint8_255(self):
        green_uint8 = np.array([[[0, 255, 0]]], dtype='uint8') 
        green_float32 = np.array([[[0, 1, 0]]], dtype='float32') 

        a = summary.image(tensor=green_uint8, tag='')
        b = summary.image(tensor=green_float32, tag='')
        self.assertEqual(a, b)
Example #2
0
def save_img_results(imgs_tcpu, fake_imgs, num_imgs, count, image_dir,
                     summary_writer):
    num = cfg.TRAIN.VIS_COUNT

    # The range of real_img (i.e., self.imgs_tcpu[i][0:num])
    # is changed to [0, 1] by function vutils.save_image
    real_img = imgs_tcpu[-1][0:num]
    vutils.save_image(real_img,
                      '%s/real_samples.png' % (image_dir),
                      normalize=True)
    real_img_set = vutils.make_grid(real_img).numpy()
    real_img_set = np.transpose(real_img_set, (1, 2, 0))
    real_img_set = real_img_set * 255
    real_img_set = real_img_set.astype(np.uint8)
    sup_real_img = summary.image('real_img', real_img_set)
    summary_writer.add_summary(sup_real_img, count)

    for i in range(num_imgs):
        fake_img = fake_imgs[i][0:num]
        # The range of fake_img.data (i.e., self.fake_imgs[i][0:num])
        # is still [-1. 1]...
        vutils.save_image(fake_img.data,
                          '%s/count_%09d_fake_samples%d.png' %
                          (image_dir, count, i),
                          normalize=True)

        fake_img_set = vutils.make_grid(fake_img.data).cpu().numpy()

        fake_img_set = np.transpose(fake_img_set, (1, 2, 0))
        fake_img_set = (fake_img_set + 1) * 255 / 2
        fake_img_set = fake_img_set.astype(np.uint8)

        sup_fake_img = summary.image('fake_img%d' % i, fake_img_set)
        summary_writer.add_summary(sup_fake_img, count)
        summary_writer.flush()
Example #3
0
 def test_image_with_one_channel(self):
     summary.image('dummy',
                   np.random.rand(1, 32, 32).astype(np.float32),
                   dataformats='CHW')
     summary.image('dummy',
                   np.random.rand(32, 32).astype(np.float32),
                   dataformats='HW')
Example #4
0
 def test_float32_image(self):
     '''
     Tests that float32 image (pixel values in [0, 1]) are scaled correctly
     to [0, 255]
     '''
     test_image = tensor_N(shape=(3, 32, 32))
     compare_proto(summary.image('dummy', test_image), self)
Example #5
0
 def test_image_without_channel(self):
     compare_proto(summary.image('dummy', tensor_N(shape=(8, 8)), dataformats='HW'), self)
Example #6
0
 def test_image_with_four_channel_batched(self):
     compare_proto(summary.image('dummy', tensor_N(shape=(2, 4, 8, 8)), dataformats='NCHW'), self)
Example #7
0
 def test_uint8_image(self):
     '''
     Tests that uint8 image (pixel values in [0, 255]) is not changed
     '''
     test_image = tensor_N(shape=(3, 32, 32), dtype=np.uint8)
     compare_proto(summary.image('dummy', test_image), self)
Example #8
0
 def test_image_without_channel(self):
     np.random.seed(0)
     compare_proto(
         summary.image('dummy',
                       np.random.rand(8, 8).astype(np.float32),
                       dataformats='HW'), self)
Example #9
0
 def test_image_with_3_channel_batched(self):
     np.random.seed(0)
     compare_proto(
         summary.image('dummy',
                       np.random.rand(2, 3, 8, 8).astype(np.float32),
                       dataformats='NCHW'), self)