train.py
def plot_stats(stats, save_dir):
    """
    Make all the plots in stats. Stats can be a dict or a path to json (str)
    """
    if type(stats) is str:
        assert os.path.isfile(stats)
        with open(stats,'r') as sf:
            stats = json.load(sf)
    assert type(stats) is dict

    assert type(save_dir) is str
    if not os.path.isdir(save_dir):
        os.makedirs(save_dir)

    def _plot(y,title):
        plt.Figure()
        if type(y) is list:
            plt.plot(range(1,len(y)+1),y)
        elif type(y) is dict:
            for key,z in y.items():
                plt.plot(range(1,len(z)+1),z,label=key)
            plt.legend()
        else:
            raise ValueError
        plt.xlabel('Epoch')
        plt.ylabel(title)
        plt.title(title)
        plt.savefig(os.path.join(save_dir,title.replace(' ','_')+'.png'))
        plt.close()

    # Loop over stats dict and plot. Dicts within stats get plotted together
    for key,value in stats.items():
        _plot(value,key)

    Make all the plots in stats. Stats can be a dict or a path to json (str)
    
Make all the plots in stats. Stats can be a dict or a path to json (str)
Make all the plots in stats . Stats can be a dict or a path to json ( str )
def plot_stats(stats, save_dir):
    if type(stats) is str:
        assert os.path.isfile(stats)
        with open(stats,'r') as sf:
            stats = json.load(sf)
    assert type(stats) is dict
    assert type(save_dir) is str
    if not os.path.isdir(save_dir):
        os.makedirs(save_dir)
    def _plot(y,title):
        plt.Figure()
        if type(y) is list:
            plt.plot(range(1,len(y)+1),y)
        elif type(y) is dict:
            for key,z in y.items():
                plt.plot(range(1,len(z)+1),z,label=key)
            plt.legend()
        else:
            raise ValueError
        plt.xlabel('Epoch')
        plt.ylabel(title)
        plt.title(title)
        plt.savefig(os.path.join(save_dir,title.replace(' ','_')+'.png'))
        plt.close()
    for key,value in stats.items():
        _plot(value,key)
def plot_stats ( stats , save_dir ) : if type ( stats ) is str : assert os . path . isfile ( stats ) with open ( stats , 'r' ) as sf : stats = json . load ( sf ) assert type ( stats ) is dict assert type ( save_dir ) is str if not os . path . isdir ( save_dir ) : os . makedirs ( save_dir ) def _plot ( y , title ) : plt . Figure ( ) if type ( y ) is list : plt . plot ( range ( 1 , len ( y ) + 1 ) , y ) elif type ( y ) is dict : for key , z in y . items ( ) : plt . plot ( range ( 1 , len ( z ) + 1 ) , z , label = key ) plt . legend ( ) else : raise ValueError plt . xlabel ( 'Epoch' ) plt . ylabel ( title ) plt . title ( title ) plt . savefig ( os . path . join ( save_dir , title . replace ( ' ' , '_' ) + '.png' ) ) plt . close ( ) for key , value in stats . items ( ) : _plot ( value , key )
Make all the plots in stats.
Make all the plots in stats .
"""
    Make all the plots in stats. Stats can be a dict or a path to json (str)
    """ # Loop over stats dict and plot. Dicts within stats get plotted together
stats
save_dir