Tensorboardx: UnboundLocalError: local variable 'start' referenced before assignment

Created on 6 Sep 2018  Â·  7Comments  Â·  Source: lanpa/tensorboardX

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 histogram.cc."""
    values = values.reshape(-1)
    counts, limits = np.histogram(values, bins=bins)
    limits = limits[1:]
    # void Histogram::EncodeToProto in histogram.cc
    for i, c in enumerate(counts):
        if c > 0:
            start = max(0, i - 1)
            break

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

    counts = counts[start:end]
    limits = limits[start:end]
    sum_sq = values.dot(values)
    return HistogramProto(min=values.min(),
                          max=values.max(),
                          num=len(values),
                          sum=values.sum(),
                          sum_squares=sum_sq,
                          bucket_limit=limits,
                          bucket=counts)

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

File "/home/shuxiaobo/TR-experiments/cli/train.py", 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/writer.py", 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/summary.py", line 142, in histogram
    hist = make_histogram(values.astype(float), bins)
  File "/home/shuxiaobo/python3/lib/python3.6/site-packages/tensorboardX/summary.py", line 162, in make_histogram
    counts = counts[start:end]
UnboundLocalError: local variable 'start' referenced before assignment

Most helpful comment

It turns out my values were NaN, I've fixed my bug.
Still, it would have been helpful if the error message told me that the values being NaN was the problem.

All 7 comments

I ran into the same problem but it could not find any PR or Issue related to the problem. Is there any specific reason for closing this issue?

@JonathanNiesel This should have been fixed in 936acdc. Please open a new issue and provide information if need. Thanks

Yup I'm getting this too.

what’s your tensorboardX version?
On Thu, Jan 17, 2019 at 1:40 AM mattphillipsphd notifications@github.com
wrote:

Yup I'm getting this too.

—
You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
https://github.com/lanpa/tensorboardX/issues/222#issuecomment-454871283,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB6ZSwww7-WRxm-S8mAP5LsYGjw1-UvCks5vD2QdgaJpZM4WcDLu
.

>

send from my phone

I'm getting the exact same error with tensorboardX version 1.6

It turns out my values were NaN, I've fixed my bug.
Still, it would have been helpful if the error message told me that the values being NaN was the problem.

It turns out my values were NaN, I've fixed my bug.
Still, it would have been helpful if the error message told me that the values being NaN was the problem.

This is the exact issue I had. Thank you @yoonholee for the pointer, and yes I agree, there should be something indicating this. May be related to RL

Was this page helpful?
0 / 5 - 0 ratings