Ejemplo n.º 1
0
def test_stack_augmentations(outdir, datadir):
    fname = "/home/leon/uni/bachelor/deepdecoder/test/data/00350.hdf5"
    myconfig = config.load(str(datadir.join('augmentation.yml')))

    dset = DistributionHDF5Dataset(fname)
    batch = next(dset.iter(15**2))

    image_save(str(outdir.join('real.png')), tile(batch['real']))
    image_save(str(outdir.join('fake.png')), np.clip(tile(batch['fake']), -1, 1))
    # for i, name in enumerate(['tag3d']):
    for i, name in enumerate(['tag3d', 'tag3d_lighten', 'fake_without_noise', 'fake']):
        augment = stack_augmentations(name, myconfig)
        xs = augment(batch)
        image_save(str(outdir.join('{}_{}_aug_tiled.png'.format(i, name))), tile(xs))
Ejemplo n.º 2
0
 def call(self, samples):
     tiles = []
     for tag3d, fake in zip(self.preprocess(samples['tag3d']),
                            self.preprocess(samples['fake'])):
         tiles.append(tag3d)
         tiles.append(fake)
     return tile(tiles, columns_must_be_multiple_of=2)
Ejemplo n.º 3
0
 def call(self, samples):
     tiles = []
     for tag3d, fake in zip(self.preprocess(samples['tag3d']),
                            self.preprocess(samples['fake'])):
         tiles.append(tag3d)
         tiles.append(fake)
     return tile(tiles, columns_must_be_multiple_of=2)
Ejemplo n.º 4
0
def save_samples(data, bits, outfname):
    print("bits", bits.shape)
    nb_bits = bits.shape[1]
    for i in range(len(data)):
        s = 64 // nb_bits
        for j in range(nb_bits):
            data[i, :s, s*j:s*(j+1)] = 2*bits[i, j] - 1
    image_save(outfname, np.clip(tile(data), -1, 1))
Ejemplo n.º 5
0
def save_samples(data, bits, outfname):
    print("bits", bits.shape)
    nb_bits = bits.shape[1]
    for i in range(len(data)):
        s = 64 // nb_bits
        for j in range(nb_bits):
            data[i, :s, s * j:s * (j + 1)] = 2 * bits[i, j] - 1
    image_save(outfname, np.clip(tile(data), -1, 1))
Ejemplo n.º 6
0
def save_real_images(real_hdf5_fname, output_dir, nb_visualise=20**2):
    real = next(train_data_generator(real_hdf5_fname, nb_visualise, 10))['data']
    print(real.shape)
    print(real.max())
    print(real.min())
    tiled = tile(real)
    fname = join(output_dir, 'real_{}.png'.format(nb_visualise))
    image_save(fname, tiled[0])
Ejemplo n.º 7
0
def save_real_images(real_hdf5_fname, output_dir, nb_visualise=20**2):
    real = next(train_data_generator(real_hdf5_fname, nb_visualise,
                                     10))['data']
    print(real.shape)
    print(real.max())
    print(real.min())
    tiled = tile(real)
    fname = join(output_dir, 'real_{}.png'.format(nb_visualise))
    image_save(fname, tiled[0])
Ejemplo n.º 8
0
def visualize_detection_tiles(dset, name, n=20**2):
    crown_vis = ResultCrownVisualizer()
    imgs_raw = []
    imgs_overlayed = []
    nb_tags = len(dset['tags'])
    n = min(nb_tags, n)
    indicies = np.arange(nb_tags)
    np.random.shuffle(indicies)
    for i in range(n):
        p = indicies[i]
        position = np.array([dset['tags'][0, 0].shape]) / 2
        tag = dset['tags'][p, 0]
        bits = (dset['bits'][p:p + 1] + 1) / 2.
        overlay = crown_vis(tag, position, np.zeros((1, 3)), bits)[0]
        overlayed = crown_vis.add_overlay((tag + 1) / 2, overlay)
        imgs_raw.append(tag)
        imgs_overlayed.append(2 * overlayed - 1)

    tiled_raw = tile([img.swapaxes(0, -1) for img in imgs_raw])
    tiled_overlayed = tile([img.swapaxes(0, -1) for img in imgs_overlayed])
    image_save(name + '_raw.png', tiled_raw)
    image_save(name + '_overlayed.png', tiled_overlayed)
Ejemplo n.º 9
0
def visualize_detection_tiles(dset, n=12**2):
    crown_vis = ResultCrownVisualizer()
    imgs = []
    indicies = np.arange(len(dset['tags']))
    np.random.shuffle(indicies)
    for i in range(n):
        p = indicies[i]
        position = np.array([dset['tags'][0, 0].shape]) / 2 + 140
        tag = dset['tags'][p, 0] / 255
        overlay = crown_vis(tag, position, np.zeros((1, 3)), dset['bits'][p:p+1])[0]
        imgs.append(crown_vis.add_overlay(tag, overlay))
    tiled = tile([img.swapaxes(0, -1) for img in imgs])
    imsave('visualize_debug_detections.png', tiled.swapaxes(0, -1))
Ejemplo n.º 10
0
def visualize_detection_tiles(dset, n=12**2):
    crown_vis = ResultCrownVisualizer()
    imgs = []
    indicies = np.arange(len(dset['tags']))
    np.random.shuffle(indicies)
    for i in range(n):
        p = indicies[i]
        position = np.array([dset['tags'][0, 0].shape]) / 2 + 140
        tag = dset['tags'][p, 0] / 255
        overlay = crown_vis(tag, position, np.zeros((1, 3)),
                            dset['bits'][p:p + 1])[0]
        imgs.append(crown_vis.add_overlay(tag, overlay))
    tiled = tile([img.swapaxes(0, -1) for img in imgs])
    imsave('visualize_debug_detections.png', tiled.swapaxes(0, -1))
Ejemplo n.º 11
0
 def call(self, samples):
     real = samples['real']
     scores = samples['discriminator_on_real']
     idx = np.argsort(scores.flatten())[::-1]
     real_sorted = real[idx]
     return tile(self.preprocess(real_sorted))
Ejemplo n.º 12
0
 def call(self, samples):
     fakes = samples['fake']
     scores = samples['discriminator_on_fake']
     idx = np.argsort(scores.flatten())[::-1]
     fakes_sorted = fakes[idx]
     return tile(self.preprocess(fakes_sorted))
Ejemplo n.º 13
0
 def call(self, samples):
     real = samples['real']
     scores = samples['discriminator_on_real']
     idx = np.argsort(scores.flatten())[::-1]
     real_sorted = real[idx]
     return tile(self.preprocess(real_sorted))
Ejemplo n.º 14
0
 def call(self, samples):
     fakes = samples['fake']
     scores = samples['discriminator_on_fake']
     idx = np.argsort(scores.flatten())[::-1]
     fakes_sorted = fakes[idx]
     return tile(self.preprocess(fakes_sorted))
Ejemplo n.º 15
0
def plot_anitaliasing(tag_dist, fname, a, nb_samples=64):
    _, masks, depth_map = next(generator(tag_dist, nb_samples, antialiasing=a))
    tiled = tile(masks)[0]
    imsave(fname.format(a), tiled)