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

TypeError: 'range' object is not callable #70

Open
Nikhil-Rao20 opened this issue Oct 14, 2024 · 0 comments
Open

TypeError: 'range' object is not callable #70

Nikhil-Rao20 opened this issue Oct 14, 2024 · 0 comments

Comments

@Nikhil-Rao20
Copy link

Nikhil-Rao20 commented Oct 14, 2024

I am getting an unkown error, while iterating through my data generator. I have followed the same instructions provided. I am using the PASCAL VOC 2012.

  1. This is a sample of annotation files :

/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2010_004120.jpg 23,107,493,330,8
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2008_001742.jpg 40,99,154,375,15
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2011_001669.jpg 331,240,359,259,7
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2007_007161.jpg 5,57,332,500,15
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2012_002212.jpg 76,7,283,404,15
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2010_004807.jpg 45,122,400,341,12 234,47,467,167,12
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2011_004769.jpg 159,95,292,436,15
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2009_001013.jpg 144,24,243,258,15 35,88,377,362,13
/content/VOC2012_train_val/VOC2012_train_val/JPEGImages/2012_003165.jpg 194,192,275,471,15

  1. This is how i read the annotations files :
with open('/content/2012_train.txt', encoding='utf-8') as f:
    train_lines = f.readlines()
with open( '/content/2012_val.txt', encoding='utf-8') as f:
    val_lines   = f.readlines()
  1. I have used the YoloDataset from the repo itself , all same
  2. This is my generators declaration :
gen             = DataLoader(train_dataset, shuffle = shuffle, batch_size = batch_size, num_workers = num_workers, pin_memory=True,drop_last=True, collate_fn=yolo_dataset_collate, sampler=train_sampler, worker_init_fn=partial(worker_init_fn, rank=rank, seed=seed))
gen_val         = DataLoader(val_dataset  , shuffle = shuffle, batch_size = batch_size, num_workers = num_workers, pin_memory=True, drop_last=True, collate_fn=yolo_dataset_collate, sampler=val_sampler, worker_init_fn=partial(worker_init_fn, rank=rank, seed=seed))
  1. And I am running this code (to see my images and boxes in gen):
for img2, box2 in gen_val:
  img=img2
  box=box2
  break

And there I get the following error :

Error :

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-83-5f541636a18e>](https://localhost:8080/#) in <cell line: 1>()
----> 1 for img2, box2 in gen_val:
      2   img=img2
      3   box=box2
      4   break

3 frames
[/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py](https://localhost:8080/#) in __next__(self)
    628                 # TODO(https://github.com/pytorch/pytorch/issues/76750)
    629                 self._reset()  # type: ignore[call-arg]
--> 630             data = self._next_data()
    631             self._num_yielded += 1
    632             if self._dataset_kind == _DatasetKind.Iterable and \

[/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py](https://localhost:8080/#) in _next_data(self)
   1342             else:
   1343                 del self._task_info[idx]
-> 1344                 return self._process_data(data)
   1345 
   1346     def _try_put_index(self):

[/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py](https://localhost:8080/#) in _process_data(self, data)
   1368         self._try_put_index()
   1369         if isinstance(data, ExceptionWrapper):
-> 1370             data.reraise()
   1371         return data
   1372 

[/usr/local/lib/python3.10/dist-packages/torch/_utils.py](https://localhost:8080/#) in reraise(self)
    704             # instantiate since we don't know how to
    705             raise RuntimeError(msg) from None
--> 706         raise exception
    707 
    708 

TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 309, in _worker_loop
    data = fetcher.fetch(index)  # type: ignore[possibly-undefined]
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "<ipython-input-61-b6184597b9a6>", line 49, in __getitem__
    image, box      = self.get_random_data(self.annotation_lines[index], self.input_shape, random = self.train)
  File "<ipython-input-61-b6184597b9a6>", line 100, in get_random_data
    box     = np.array([np.array(list(map(int,box.split(',')))) for box in line[1:]])
  File "<ipython-input-61-b6184597b9a6>", line 100, in <listcomp>
    box     = np.array([np.array(list(map(int,box.split(',')))) for box in line[1:]])
TypeError: 'range' object is not callable

I need guidance over this and help me to solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant