Skip to content
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

PyCharm Printing Numpy Arrays (IndexError: tuple index out of range) #10

Closed
CF2220160244 opened this issue Sep 12, 2018 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@CF2220160244
Copy link

when i print (labels) in datasets.py ,row 143, there are a problem:
i can not print (lables), but i can print (labels[0][0]), print(labels0.shape)

Load labels

        if os.path.isfile(label_path):
            labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 5)
            print(labels0.shape)    #143
            print(labels0[0][0])      #144
            print(labels)                #145
            exit()

#############

Traceback (most recent call last):
File "train.py", line 193, in
main(opt)
File "train.py", line 116, in main
for i, (imgs, targets) in enumerate(dataloader):
File "/home/chenfei/Downloads/yolov3-master1/utils/datasets.py", line 143, in next
print(labels)
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 1504, in array_str
return array2string(a, max_line_width, precision, suppress_small, ' ', "")
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 668, in array2string
return _array2string(a, options, separator, prefix)
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 460, in wrapper
return f(self, *args, **kwargs)
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 495, in _array2string
summary_insert, options['legacy'])
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 796, in _formatArray
curr_width=line_width)
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 750, in recurser
word = recurser(index + (-i,), next_hanging_indent, next_width)
File "/home/chenfei/anaconda3/lib/python3.6/site-packages/numpy/core/arrayprint.py", line 704, in recurser
return format_function(a[index])
IndexError: tuple index out of range

@glenn-jocher
Copy link
Member

glenn-jocher commented Sep 13, 2018

@CF2220160244 I get the same error on printing numpy arrays, but I think in my case this is a PyCharm problem. In PyCharm if I convert the numpy array to a torch tensor print works fine:

labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 5)

print(labels0)
Traceback (most recent call last):
...
IndexError: tuple index out of range

print(torch.from_numpy(labels0))
tensor([[76.00000,  0.35609,  0.44456,  0.54970,  0.16180],
        [ 0.00000,  0.48129,  0.40587,  0.94952,  0.80312]])

In Spyder the same operation shows no errors:

ipdb> labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 5)

ipdb> labels0
array([[76.      ,  0.356086,  0.444563,  0.549703,  0.161803],
       [ 0.      ,  0.481289,  0.405874,  0.949516,  0.803123]], dtype=float32)

ipdb> print(labels0)
[[76.        0.356086  0.444563  0.549703  0.161803]
 [ 0.        0.481289  0.405874  0.949516  0.803123]]

@glenn-jocher glenn-jocher changed the title print(labels) in datasets.py—— bug Printing Numpy Arrays (IndexError: tuple index out of range) Sep 13, 2018
@glenn-jocher glenn-jocher added the bug Something isn't working label Sep 19, 2018
@glenn-jocher glenn-jocher changed the title Printing Numpy Arrays (IndexError: tuple index out of range) PyCharm Printing Numpy Arrays (IndexError: tuple index out of range) Sep 20, 2018
@simedw
Copy link

simedw commented Oct 3, 2018

The issue seem to be that the print option for float_kind has a typo (https://github.com/ultralytics/yolov3/blob/master/utils/utils.py#L10).
Try changing
np.set_printoptions(linewidth=320, formatter={'float_kind': '{11.5g}'.format})
to
np.set_printoptions(linewidth=320, formatter={'float_kind': '{:11.5g}'.format})
(format was trying to access the 11th element of the input instead of using 11.5g as formatting)

@glenn-jocher
Copy link
Member

@simedw you are right, this fixes the problem! I implemented this change in commit bce94f6.

@NaumanKhan665
Copy link

@simedw you are right, this fixes the problem! I implemented this change in commit bce94f6.
But this error is not fixed by using th above suggestion
return a.reshape((1, a.shape[0], a.shape[1]))
IndexError: tuple index out of range

@glenn-jocher
Copy link
Member

glenn-jocher commented Oct 8, 2019

@NaumanKhan665
Hello, thank you for your interest in our work! Please note that most technical problems are due to:

  • Your changes to the default repository. If your issue is not reproducible in a fresh git clone version of this repository we can not debug it. Before going further run this code and ensure your issue persists:
sudo rm -rf yolov3  # remove exising repo
git clone https://github.com/ultralytics/yolov3 && cd yolov3 # git clone latest
python3 detect.py  # verify detection
python3 train.py  # verify training (a few batches only)
# CODE TO REPRODUCE YOUR ISSUE HERE
  • Your custom data. If your issue is not reproducible with COCO data we can not debug it. Visit our Custom Training Tutorial for exact details on how to format your custom data. Examine train_batch0.jpg and test_batch0.jpg for a sanity check of training and testing data.
  • Your environment. If your issue is not reproducible in a GCP Quickstart Guide VM we can not debug it. Ensure you meet the requirements specified in the README: Unix, MacOS, or Windows with Python >= 3.7, Pytorch >= 1.1, etc. You can also use our Google Colab Notebook to test your code in working environment.

If none of these apply to you, we suggest you close this issue and raise a new one using the Bug Report template, providing screenshots and minimum viable code to reproduce your issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants