Lileb-Training/src/experiments/_utils/plot.py
def plot_results(x, nsample=1, res=1., renorm=True, cmap='viridis'):
    """
    x is a list of tuples (name, value) where value
    is a dict of with keys 'in' and 'out', corresponding
    to the input and output sequences given to the model 
    """
    # retrieving max image value to not renorm
    
    vmin = np.inf
    vmax = - np.inf
    for _, v in x:
        for l in v:
            if v[l][0][0].shape[0] != 2:
                vls = [vli[:nsample] for vli in v[l]]
                vmin = min(vmin, np.min(vls))
                vmax = max(vmax, np.max(vls))

    x = OrderedDict(x)
    # calculating max column length
    maxincols, maxoutcols = 0, 0
    for k in x:
        if 'in' in x[k]:
            maxincols = max(len(x[k]['in']), maxincols)
        if 'out' in x[k]:
            maxoutcols = max(len(x[k]['out']), maxoutcols)
    cols = maxincols + maxoutcols
    rows = len(x) * nsample

    def plot_one(im, title='', cmap='viridis', renorm=True):
        if im.shape[0] == 2:
            raise NotImplementedError
        plt.axis('off')
        plt.imshow(im.squeeze(), origin='lower', cmap=cmap, vmin=vmin, vmax=vmax)
    
    plt.figure(figsize=(cols * res, rows * res))
    for i, k in enumerate(x):
        for s in range(nsample):
            if 'in' in x[k]:
                
                title = '{}, in'.format(k)
                for t in range(len(x[k]['in'])):
                    n = s * len(x) * cols + cols * i + t
                    im = x[k]['in'][t][s]
                    plt.subplot(rows, cols, n + 1)
                    plot_one(im, title, cmap=cmap, renorm=renorm)
            if 'out' in x[k]:
                title = '{}, out'.format(k)
                for t in range(maxincols, maxincols + len(x[k]['out'])):
                    im = x[k]['out'][t - maxincols][s]
                    n = s * len(x) * cols + cols * i + t
                    plt.subplot(rows, cols, n + 1)
                    plot_one(im, title, cmap=cmap, renorm=renorm)
    plt.tight_layout()
    plt.subplots_adjust(wspace=0.001, hspace=0.1)
    return plt.gcf()

    x is a list of tuples (name, value) where value
    is a dict of with keys 'in' and 'out', corresponding
    to the input and output sequences given to the model 
    
x is a list of tuples (name, value) where value
is a dict of with keys 'in' and 'out', corresponding
to the input and output sequences given to the model
x is a list of tuples ( name value ) where value is a dict of with keys ' in ' and ' out ' corresponding to the input and output sequences given to the model
def plot_results(x, nsample=1, res=1., renorm=True, cmap='viridis'):
    vmin = np.inf
    vmax = - np.inf
    for _, v in x:
        for l in v:
            if v[l][0][0].shape[0] != 2:
                vls = [vli[:nsample] for vli in v[l]]
                vmin = min(vmin, np.min(vls))
                vmax = max(vmax, np.max(vls))
    x = OrderedDict(x)
    maxincols, maxoutcols = 0, 0
    for k in x:
        if 'in' in x[k]:
            maxincols = max(len(x[k]['in']), maxincols)
        if 'out' in x[k]:
            maxoutcols = max(len(x[k]['out']), maxoutcols)
    cols = maxincols + maxoutcols
    rows = len(x) * nsample
    def plot_one(im, title='', cmap='viridis', renorm=True):
        if im.shape[0] == 2:
            raise NotImplementedError
        plt.axis('off')
        plt.imshow(im.squeeze(), origin='lower', cmap=cmap, vmin=vmin, vmax=vmax)
    plt.figure(figsize=(cols * res, rows * res))
    for i, k in enumerate(x):
        for s in range(nsample):
            if 'in' in x[k]:
                title = '{}, in'.format(k)
                for t in range(len(x[k]['in'])):
                    n = s * len(x) * cols + cols * i + t
                    im = x[k]['in'][t][s]
                    plt.subplot(rows, cols, n + 1)
                    plot_one(im, title, cmap=cmap, renorm=renorm)
            if 'out' in x[k]:
                title = '{}, out'.format(k)
                for t in range(maxincols, maxincols + len(x[k]['out'])):
                    im = x[k]['out'][t - maxincols][s]
                    n = s * len(x) * cols + cols * i + t
                    plt.subplot(rows, cols, n + 1)
                    plot_one(im, title, cmap=cmap, renorm=renorm)
    plt.tight_layout()
    plt.subplots_adjust(wspace=0.001, hspace=0.1)
    return plt.gcf()
def plot_results ( x , nsample = 1 , res = 1. , renorm = True , cmap = 'viridis' ) : vmin = np . inf vmax = - np . inf for _ , v in x : for l in v : if v [ l ] [ 0 ] [ 0 ] . shape [ 0 ] != 2 : vls = [ vli [ : nsample ] for vli in v [ l ] ] vmin = min ( vmin , np . min ( vls ) ) vmax = max ( vmax , np . max ( vls ) ) x = OrderedDict ( x ) maxincols , maxoutcols = 0 , 0 for k in x : if 'in' in x [ k ] : maxincols = max ( len ( x [ k ] [ 'in' ] ) , maxincols ) if 'out' in x [ k ] : maxoutcols = max ( len ( x [ k ] [ 'out' ] ) , maxoutcols ) cols = maxincols + maxoutcols rows = len ( x ) * nsample def plot_one ( im , title = '' , cmap = 'viridis' , renorm = True ) : if im . shape [ 0 ] == 2 : raise NotImplementedError plt . axis ( 'off' ) plt . imshow ( im . squeeze ( ) , origin = 'lower' , cmap = cmap , vmin = vmin , vmax = vmax ) plt . figure ( figsize = ( cols * res , rows * res ) ) for i , k in enumerate ( x ) : for s in range ( nsample ) : if 'in' in x [ k ] : title = '{}, in' . format ( k ) for t in range ( len ( x [ k ] [ 'in' ] ) ) : n = s * len ( x ) * cols + cols * i + t im = x [ k ] [ 'in' ] [ t ] [ s ] plt . subplot ( rows , cols , n + 1 ) plot_one ( im , title , cmap = cmap , renorm = renorm ) if 'out' in x [ k ] : title = '{}, out' . format ( k ) for t in range ( maxincols , maxincols + len ( x [ k ] [ 'out' ] ) ) : im = x [ k ] [ 'out' ] [ t - maxincols ] [ s ] n = s * len ( x ) * cols + cols * i + t plt . subplot ( rows , cols , n + 1 ) plot_one ( im , title , cmap = cmap , renorm = renorm ) plt . tight_layout ( ) plt . subplots_adjust ( wspace = 0.001 , hspace = 0.1 ) return plt . gcf ( )
x is a list of tuples (name, value) where value
is a dict of with keys 'in' and 'out', corresponding
to the input and output sequences given to the model
x is a list of tuples ( name value ) where value is a dict of with keys ' in ' and ' out ' corresponding to the input and output sequences given to the model
"""
    x is a list of tuples (name, value) where value
    is a dict of with keys 'in' and 'out', corresponding
    to the input and output sequences given to the model 
    """ # retrieving max image value to not renorm # calculating max column length
x
nsample
res
renorm
cmap