(obj)
Convert and display an output tensor from BigGAN in the terminal.
        This function use `libsixel` and will only work in a libsixel-compatible terminal.
        Please refer to https://github.com/saitoha/libsixel for more details.

        Params:
            obj: tensor or numpy array of shape (batch_size, channels, height, width)
            file_name: path and beggingin of filename to save.
                Images will be saved as `file_name_{image_number}.png`
Convert and display an output tensor from BigGAN in the terminal.
        This function use `libsixel` and will only work in a libsixel-compatible terminal.
        Please refer to https://github.com/saitoha/libsixel for more details.
Convert and display an output tensor from BigGAN in the terminal . This function use libsixel and will only work in a libsixel - compatible terminal . Please refer to https : // github . com / saitoha / libsixel for more details .
def display_in_terminal(obj):
    """ Convert and display an output tensor from BigGAN in the terminal.
        This function use `libsixel` and will only work in a libsixel-compatible terminal.
        Please refer to https://github.com/saitoha/libsixel for more details.

        Params:
            obj: tensor or numpy array of shape (batch_size, channels, height, width)
            file_name: path and beggingin of filename to save.
                Images will be saved as `file_name_{image_number}.png`
    """
    try:
        import PIL
        from libsixel import (sixel_output_new, sixel_dither_new, sixel_dither_initialize,
                              sixel_dither_set_palette, sixel_dither_set_pixelformat,
                              sixel_dither_get, sixel_encode, sixel_dither_unref,
                              sixel_output_unref, SIXEL_PIXELFORMAT_RGBA8888,
                              SIXEL_PIXELFORMAT_RGB888, SIXEL_PIXELFORMAT_PAL8,
                              SIXEL_PIXELFORMAT_G8, SIXEL_PIXELFORMAT_G1)
    except ImportError:
        raise ImportError("Display in Terminal requires Pillow, libsixel "
                          "and a libsixel compatible terminal. "
                          "Please read info at https://github.com/saitoha/libsixel "
                          "and install with pip install Pillow libsixel-python")

    s = BytesIO()

    images = convert_to_images(obj)
    widths, heights = zip(*(i.size for i in images))

    output_width = sum(widths)
    output_height = max(heights)

    output_image = PIL.Image.new('RGB', (output_width, output_height))

    x_offset = 0
    for im in images:
        output_image.paste(im, (x_offset,0))
        x_offset += im.size[0]

    try:
        data = output_image.tobytes()
    except NotImplementedError:
        data = output_image.tostring()
    output = sixel_output_new(lambda data, s: s.write(data), s)

    try:
        if output_image.mode == 'RGBA':
            dither = sixel_dither_new(256)
            sixel_dither_initialize(dither, data, output_width, output_height, SIXEL_PIXELFORMAT_RGBA8888)
        elif output_image.mode == 'RGB':
            dither = sixel_dither_new(256)
            sixel_dither_initialize(dither, data, output_width, output_height, SIXEL_PIXELFORMAT_RGB888)
        elif output_image.mode == 'P':
            palette = output_image.getpalette()
            dither = sixel_dither_new(256)
            sixel_dither_set_palette(dither, palette)
            sixel_dither_set_pixelformat(dither, SIXEL_PIXELFORMAT_PAL8)
        elif output_image.mode == 'L':
            dither = sixel_dither_get(SIXEL_BUILTIN_G8)
            sixel_dither_set_pixelformat(dither, SIXEL_PIXELFORMAT_G8)
        elif output_image.mode == '1':
            dither = sixel_dither_get(SIXEL_BUILTIN_G1)
            sixel_dither_set_pixelformat(dither, SIXEL_PIXELFORMAT_G1)
        else:
            raise RuntimeError('unexpected output_image mode')
        try:
            sixel_encode(data, output_width, output_height, 1, dither, output)
            print(s.getvalue().decode('ascii'))
        finally:
            sixel_dither_unref(dither)
    finally:
        sixel_output_unref(output)
def display_in_terminal ( obj ) : try : import PIL from libsixel import ( sixel_output_new , sixel_dither_new , sixel_dither_initialize , sixel_dither_set_palette , sixel_dither_set_pixelformat , sixel_dither_get , sixel_encode , sixel_dither_unref , sixel_output_unref , SIXEL_PIXELFORMAT_RGBA8888 , SIXEL_PIXELFORMAT_RGB888 , SIXEL_PIXELFORMAT_PAL8 , SIXEL_PIXELFORMAT_G8 , SIXEL_PIXELFORMAT_G1 ) except ImportError : raise ImportError ( "Display in Terminal requires Pillow, libsixel " "and a libsixel compatible terminal. " "Please read info at https://github.com/saitoha/libsixel " "and install with pip install Pillow libsixel-python" ) s = BytesIO ( ) images = convert_to_images ( obj ) widths , heights = zip ( * ( i . size for i in images ) ) output_width = sum ( widths ) output_height = max ( heights ) output_image = PIL . Image . new ( 'RGB' , ( output_width , output_height ) ) x_offset = 0 for im in images : output_image . paste ( im , ( x_offset , 0 ) ) x_offset += im . size [ 0 ] try : data = output_image . tobytes ( ) except NotImplementedError : data = output_image . tostring ( ) output = sixel_output_new ( lambda data , s : s . write ( data ) , s ) try : if output_image . mode == 'RGBA' : dither = sixel_dither_new ( 256 ) sixel_dither_initialize ( dither , data , output_width , output_height , SIXEL_PIXELFORMAT_RGBA8888 ) elif output_image . mode == 'RGB' : dither = sixel_dither_new ( 256 ) sixel_dither_initialize ( dither , data , output_width , output_height , SIXEL_PIXELFORMAT_RGB888 ) elif output_image . mode == 'P' : palette = output_image . getpalette ( ) dither = sixel_dither_new ( 256 ) sixel_dither_set_palette ( dither , palette ) sixel_dither_set_pixelformat ( dither , SIXEL_PIXELFORMAT_PAL8 ) elif output_image . mode == 'L' : dither = sixel_dither_get ( SIXEL_BUILTIN_G8 ) sixel_dither_set_pixelformat ( dither , SIXEL_PIXELFORMAT_G8 ) elif output_image . mode == '1' : dither = sixel_dither_get ( SIXEL_BUILTIN_G1 ) sixel_dither_set_pixelformat ( dither , SIXEL_PIXELFORMAT_G1 ) else : raise RuntimeError ( 'unexpected output_image mode' ) try : sixel_encode ( data , output_width , output_height , 1 , dither , output ) print ( s . getvalue ( ) . decode ( 'ascii' ) ) finally : sixel_dither_unref ( dither ) finally : sixel_output_unref ( output )