IndexError: single positional indexer is out-of-bounds
See original GitHub issueDescribe the bug
Trying to train a custom object detector when I get the error listed in the title. I think it’s because it’s not reading in my folders with the images and labels? I’ve tried 'labels' ,'/labels' and '/labels/'
Code and Data
from detecto import core, utils, visualize
# Images and XML files in separate folders
dataset = core.Dataset('labels/', 'images/')
image, target = dataset[0]
print(image, target)
model = core.Model(['bat', 'batter', 'pitch', 'field', 'player', 'scoreboard'])
model.fit(dataset)
# Specify the path to your image
image = utils.read_image('images/image0.jpg')
predictions = model.predict(image)
# predictions format: (labels, boxes, scores)
labels, boxes, scores = predictions
print(labels)
print(boxes)
print(scores)
Stacktrace
Traceback (most recent call last):
File "c:/Users/julis/Documents/ap-cricket/functions/train.py", line 9, in <module>
image, target = dataset[0]
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\detecto\core.py", line 148, in __getitem__
img_name = os.path.join(self._root_dir, self._csv.iloc[idx, 0])
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 873, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1443, in _getitem_tuple
self._has_valid_tuple(tup)
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 702, in _has_valid_tuple
self._validate_key(k, i)
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1352, in _validate_key
self._validate_integer(key, axis)
File "C:\Users\julis\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\indexing.py", line 1437, in _validate_integer
raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
Environment:
- OS: Windows 10
- Python version: 3.8
- Detecto version:
- torch version: 1.5.0
- torchvision version : 0.6.0
Additional context Image name is : ‘image0.jpg’ Label name is: ‘image0.xml’
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
iloc giving 'IndexError: single positional indexer is out-of-bounds'
This happens when you index a row/column with a number that is larger than the dimensions of your dataframe ...
Read more >IndexError: single positional indexer is out-of-bounds -
This error IndexError: single positional indexer is out-of-bounds is easy to fix and all to do with the index value that you are...
Read more >iloc giving \'IndexError: single positional indexer is out-of ...
The code indexerror: single positional indexer is out-of-bounds, shows that you misunderstood iloc function. The value before the colon(:) ...
Read more >single positional indexer is out-of-bounds · Issue #6785 - GitHub
2022-05-06 17:43:59,167 - freqtrade.strategy.strategy_wrapper - ERROR - Unexpected error single positional indexer is out-of-bounds calling ...
Read more >iloc giving 'IndexError: single positional indexer is out-of-bounds'
Indexing is out of bounds here most probably because there are less than 19 columns in your Dataset, so column 18 does not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m also caught up at the moment but will take a look when I can too!
This has come up again in another revisit of detecto – Out of curiosity @alankbi, is there a way to not make the strict requirement on
image_id
having to be both sequential and starting at 0 in both the training and test data? I would have thought aftertrain_test_split
, you should be able to just give both dataframes to DataLoader but it seems I then have to reassign all of theimage_ids
to satisfy that requirement. Presumably, theimage_ids
can just be abstracted away and just be created on the fly based on thefilename
column in each train/test dataframe going to the DataLoader. e.g. just like this here. i.e.I’m likely missing something behind the scenes that doesn’t allow this, though. On my most recent issue relating to this (I think)…
test.csv
and train.csv
As a check…
These being assigned here in my program…
Update It comes down to
iloc
indexing. So when the comments/docs link say the csv file contains…CSV file contains: filename, width, height, class, xmin, ymin, xmax, ymax
The actual order of those columns matters because of
--> 153 img_name = os.path.join(self._root_dir, object_entries.iloc[0, 0])
in core.pyGeneral comment though - shouldn’t this just be
object_entries.loc[0, 'filename']
so it’s agnostic to what order the columns are put in. Also, curious as to people’s thoughts on the nrgoup() function being run to just generate the image_ids in the backend?