(compute, dataset, sample_size=None, batch_size=10, k=100,
        cachefile=None, **kwargs)
Computes the topk statistics for a large data sample that can be
    computed from a dataset.  The compute function should return one
    batch of samples as a (sample, unit)-dimension tensor.

    k specifies the number of top samples to retain.
    Results are returned as a RunningTopK object.
Computes the topk statistics for a large data sample that can be
    computed from a dataset.  The compute function should return one
    batch of samples as a (sample, unit)-dimension tensor.
Computes the topk statistics for a large data sample that can be computed from a dataset . The compute function should return one batch of samples as a ( sample unit ) - dimension tensor .
def tally_topk(compute, dataset, sample_size=None, batch_size=10, k=100,
        cachefile=None, **kwargs):
    '''
    Computes the topk statistics for a large data sample that can be
    computed from a dataset.  The compute function should return one
    batch of samples as a (sample, unit)-dimension tensor.

    k specifies the number of top samples to retain.
    Results are returned as a RunningTopK object.
    '''
    with torch.no_grad():
        args = dict(sample_size=sample_size, k=k)
        cached_state = load_cached_state(cachefile, args)
        if cached_state is not None:
            return runningstats.RunningTopK(state=cached_state)
        rtk = runningstats.RunningTopK(k=k)
        loader = make_loader(dataset, sample_size, batch_size, **kwargs)
        for batch in pbar(loader):
            sample = call_compute(compute, batch)
            rtk.add(sample)
        rtk.to_('cpu')
        save_cached_state(cachefile, rtk, args)
        return rtk
def tally_topk ( compute , dataset , sample_size = None , batch_size = 10 , k = 100 , cachefile = None , * * kwargs ) : with torch . no_grad ( ) : args = dict ( sample_size = sample_size , k = k ) cached_state = load_cached_state ( cachefile , args ) if cached_state is not None : return runningstats . RunningTopK ( state = cached_state ) rtk = runningstats . RunningTopK ( k = k ) loader = make_loader ( dataset , sample_size , batch_size , * * kwargs ) for batch in pbar ( loader ) : sample = call_compute ( compute , batch ) rtk . add ( sample ) rtk . to_ ( 'cpu' ) save_cached_state ( cachefile , rtk , args ) return rtk