Esempio n. 1
0
def batch_show(batch,
               nr_show=16,
               grid_desc=('4v', '4h'),
               resize=(600, 800),
               title='batch_show'):
    """
    Show a batch of images.

    :param batch: The batched data: can be either a ndarray of shape (batch_size, h, w, c) or a list
    of images.
    :param nr_show: Number of images to be displayed. Default set to be 16.
    :param grid_desc: Grid description. See `tartist.image.image_grid` for details.
    :param resize: Resize factor, a tuple (min_dim, max_dim).
    :param title: The title of the shown window.
    """

    batch = batch[:nr_show]
    batch = np.array(batch)

    if len(batch) < 16:
        batch = np.concatenate([
            batch,
            np.zeros([
                16 - len(batch), batch.shape[1], batch.shape[2], batch.shape[3]
            ],
                     dtype=batch.dtype)
        ],
                               axis=0)

    img = image.image_grid(batch, grid_desc)
    img = image.resize_minmax(img, *resize, interpolation='NEAREST')
    image.imshow(title, img)
def main_demo(env, func):
    df = iter(make_dataflow_demo(env))
    nr_samples = get_env('demo.nr_samples', 40 * 8)
    grid_desc = get_env('demo.grid_desc', ('20v', '16h'))

    while True:
        all_imgs_ab = []
        all_imgs_ba = []
        for i in range(nr_samples):
            feed_dict = next(df)
            results = func(**feed_dict)
            img_a, img_b = feed_dict['img_a'][0], feed_dict['img_b'][0]
            img_ab, img_ba = results['img_ab'][0] * 255, results['img_ba'][
                0] * 255
            img_aba, img_bab = results['img_aba'][0] * 255, results['img_bab'][
                0] * 255

            all_imgs_ab.append(np.hstack([img_a, img_ab]).astype('uint8'))
            all_imgs_ba.append(np.hstack([img_b, img_ba]).astype('uint8'))

        all_imgs_ab = image.image_grid(all_imgs_ab, grid_desc)
        all_imgs_ba = image.image_grid(all_imgs_ba, grid_desc)
        sep = np.ones((all_imgs_ab.shape[0], 64, 3), dtype='uint8') * 255
        all_imgs = np.hstack([all_imgs_ab, sep, all_imgs_ba])
        image.imwrite('discogan.png', all_imgs)
        image.imshow('AtoB; BtoA', all_imgs)
def demo(feed_dict, result, extra_info):
    img = result['output'][0, :, :, 0]

    img = np.repeat(img[:, :, np.newaxis], 3, axis=2) * 255
    img = img.astype('uint8')
    img = image.resize_minmax(img, 256)

    image.imshow('demo', img)
Esempio n. 4
0
def imshow(img, resize=(600, 800), title='imshow'):
    """
    Image show with different parameter order.

    :param img: Image.
    :param resize: Resize factor, a tuple (min_dim, max_dim).
    :param title: The title of the shown window.
    """
    img = image.resize_minmax(img, *resize, interpolation='NEAREST')
    image.imshow(title, img)
Esempio n. 5
0
def main():
    m = rl.custom.MazeEnv(enable_noaction=False, visible_size=7)

    m.restart()
    demo = [r(m)]
    for i in range(19):
        a = random.choice(4)
        m.action(a)
        demo.append(r(m))

    i = image.image_grid(demo, ['5v', '4h'])
    image.imshow('Maze', i)
Esempio n. 6
0
def demo_vae(feed_dict, result, extra_info):
    reconstruct = get_env('demo.is_reconstruct', False)
    if reconstruct:
        img = feed_dict['img'][0, :, :, 0]
        omg = result['output'][0, :, :, 0]
        img = np.hstack((img, omg))
    else:
        img = result['output'][0, :, :, 0]

    img = np.repeat(img[:, :, np.newaxis], 3, axis=2) * 255
    img = img.astype('uint8')
    img = image.resize_minmax(img, 256)

    image.imshow('demo', img)
Esempio n. 7
0
def demo(feed_dict, result, extra_info):
    img = feed_dict['img'][0, :, :, 0]
    label = extra_info['label']

    img = np.repeat(img[:, :, np.newaxis], 3, axis=2) * 255
    img = img.astype('uint8')
    img = image.resize_minmax(img, 256)
    outputs = [img, np.zeros(shape=[50, 256, 3], dtype='uint8')]
    outputs = np.vstack(outputs)

    text = 'Pred: {}'.format(result['pred'][0])
    text += ' Gt: {}'.format(int(label))
    # cv2.putText(outputs, text, (20, 256 + 25), cv2.FONT_HERSHEY_PLAIN, 1.5, (255, 255, 255))
    print(text)

    image.imshow('demo', outputs)
Esempio n. 8
0
def main():
    m = rl.custom.MazeEnv(map_size=15, enable_noaction=True, visible_size=None) 
    obstacles = itertools.chain(
            [(i, 7) for i in range(15) if i not in (3, 11)], 
            [(7, i) for i in range(15) if i not in (3, 11)]
    )
    m.restart(obstacles=obstacles, start_point=(3, 3), finish_point=(11, 11))

    demo = [r(m)]
    for i in range(19):
        a = random.choice(4)
        m.action(a)
        demo.append(r(m))
   
    i = image.image_grid(demo, ['5v', '4h'])
    image.imshow('Maze', i) 
Esempio n. 9
0
def demo(feed_dict, result, extra_info):
    nr_classes = get_env('dataset.nr_classes')

    img = feed_dict['img'][0]
    label = extra_info['label']
    labels_name = _cifar_labels_name[nr_classes]

    img = img.astype('uint8')
    img = image.resize_minmax(img, 256)
    outputs = [img, np.zeros(shape=[50, 256, 3], dtype='uint8')]
    outputs = np.vstack(outputs)

    text = 'Pred: {}'.format(labels_name[result['pred'][0]])
    text += ' Gt: {}'.format(labels_name[int(label)])
    # cv2.putText(outputs, text, (20, 256 + 25), cv2.FONT_HERSHEY_PLAIN, 1.5, (255, 255, 255))
    print(text)

    image.imshow('demo', outputs)
Esempio n. 10
0
def demo_draw(feed_dict, result, extra_info):
    reconstruct = get_env('demo.is_reconstruct', False)
    grid_desc = get_env('demo.draw.grid_desc')

    all_outputs = []
    for i in range(1000):
        name = 'canvas_step{}'.format(i)
        if name in result:
            all_outputs.append(result[name][0, :, :, 0])

    final = image.image_grid(all_outputs, grid_desc)
    final = (final * 255).astype('uint8')

    if reconstruct:
        img = feed_dict['img'][0, :, :, 0]
        h = final.shape[0]
        w = int(img.shape[1] * h / img.shape[0])
        img = (img * 255).astype('uint8')
        img = image.resize(img, (h, w))
        final = np.hstack((img, final))

    final = image.resize_minmax(final, 480, 720)

    image.imshow('demo', final)
Esempio n. 11
0
# -*- coding:utf8 -*-
# File   : test_image_fbaug.py
# Author : Jiayuan Mao
# Email  : [email protected]
# Date   : 3/14/17
#
# This file is part of TensorArtist.

from tartist import image
from tartist.image.aug import cblk
import sys

if __name__ == '__main__':
    a = image.imread(sys.argv[1])
    b = cblk.fbaug(a)
    image.imshow('fbaug', b)
Esempio n. 12
0
def main():
    db = LMDBKVStore(args.input_dir, readonly=False)

    for f in tqdm(db.keys()):
        img = db.get(f)
        image.imshow(f, img)