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

list index out of range #27

Open
kekeche opened this issue Nov 7, 2024 · 3 comments
Open

list index out of range #27

kekeche opened this issue Nov 7, 2024 · 3 comments

Comments

@kekeche
Copy link

kekeche commented Nov 7, 2024

python train.py
--hiera_path "/root/sam2-unet-main/sam2_hiera_large.pt"
--train_image_path "/root/autodl-tmp/DUTS-TR/DUTS-TR-Image/"
--train_mask_path "/root//autodl-tmp/DUTS-TR/DUTS-TR-Mask/"
--save_path "/root/sam2-unet-main"
--epoch 20
--lr 0.001
--batch_size 12
Traceback (most recent call last):
File "/root/sam2-unet-main/train.py", line 133, in
main(args)
File "/root/sam2-unet-main/train.py", line 105, in main
for i, batch in enumerate(dataloader):
File "/root/miniconda3/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 630, in next
data = self._next_data()
^^^^^^^^^^^^^^^^^
File "/root/miniconda3/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1344, in _next_data
return self._process_data(data)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/miniconda3/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1370, in _process_data
data.reraise()
File "/root/miniconda3/lib/python3.12/site-packages/torch/_utils.py", line 706, in reraise
raise exception
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/root/miniconda3/lib/python3.12/site-packages/torch/utils/data/_utils/worker.py", line 309, in _worker_loop
data = fetcher.fetch(index) # type: ignore[possibly-undefined]
^^^^^^^^^^^^^^^^^^^^
File "/root/miniconda3/lib/python3.12/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]

File "/root/sam2-unet-main/dataset.py", line 188, in getitem
label = self.binary_loader(self.gts[idx])
~~~~~~~~^^^^^
IndexError: list index out of range

为什么我一直报出这样的错误的,我已经检查过image与mask是一一对应的
@xiongxyowo
Copy link
Collaborator

Hi, you can debug these two lines of code in dataset.py to check if the data is loaded correctly:

self.images = [image_root + f for f in os.listdir(image_root) if f.endswith('.jpg') or f.endswith('.png')]
self.gts = [gt_root + f for f in os.listdir(gt_root) if f.endswith('.png')]
print(len(self.images))
print(len(self.gts))

@kekeche
Copy link
Author

kekeche commented Nov 8, 2024 via email

@kekeche
Copy link
Author

kekeche commented Dec 12, 2024 via email

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

2 participants