New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'start' referenced before assignment #222

shuxiaobo opened this Issue Sep 6, 2018 · 0 comments


None yet
1 participant

shuxiaobo commented Sep 6, 2018

Dear Author:
I just found an code logical bug in histogram. I think here should be raise an Exception.

def make_histogram(values, bins):
    """Convert values into a histogram proto using logic from"""
    values = values.reshape(-1)
    counts, limits = np.histogram(values, bins=bins)
    limits = limits[1:]
    # void Histogram::EncodeToProto in
    for i, c in enumerate(counts):
        if c > 0:
            start = max(0, i - 1)

    for i, c in enumerate(reversed(counts)):
        if c > 0:
            end = -(i)

    counts = counts[start:end]
    limits = limits[start:end]
    sum_sq =
    return HistogramProto(min=values.min(),

if all the elements in counts is 0 .there will be error like this:

File "/home/shuxiaobo/TR-experiments/cli/", line 62, in train
    writer.add_histogram(name + '/grad', param.grad.clone().cpu().data.numpy(), j)
  File "/home/shuxiaobo/python3/lib/python3.6/site-packages/tensorboardX/", line 395, in add_histogram
    self.file_writer.add_summary(histogram(tag, values, bins), global_step, walltime)
  File "/home/shuxiaobo/python3/lib/python3.6/site-packages/tensorboardX/", line 142, in histogram
    hist = make_histogram(values.astype(float), bins)
  File "/home/shuxiaobo/python3/lib/python3.6/site-packages/tensorboardX/", line 162, in make_histogram
    counts = counts[start:end]
UnboundLocalError: local variable 'start' referenced before assignment

@lanpa lanpa closed this in 936acdc Sep 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment