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

UnboundLocalError: local variable 'image_path' referenced before assignment #170

Open
dw199777 opened this issue Nov 6, 2024 · 2 comments

Comments

@dw199777
Copy link

dw199777 commented Nov 6, 2024

Traceback (most recent call last):
[rank0]: File "/mnt/f/GOT-OCR2.0/./GOT-OCR-2.0-master/GOT/train/train_GOT.py", line 160, in
[rank0]: train()
[rank0]: File "/mnt/f/GOT-OCR2.0/./GOT-OCR-2.0-master/GOT/train/train_GOT.py", line 154, in train
[rank0]: trainer.train()
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/transformers/trainer.py", line 2122, in train
[rank0]: return inner_training_loop(
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/transformers/trainer.py", line 2426, in _inner_training_loop
[rank0]: batch_samples, num_items_in_batch = self.get_batch_samples(epoch_iterator, num_batches)
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/transformers/trainer.py", line 5038, in get_batch_samples
[rank0]: batch_samples += [next(epoch_iterator)]
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/accelerate/data_loader.py", line 552, in iter
[rank0]: current_batch = next(dataloader_iter)
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 701, in next
[rank0]: data = self._next_data()
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1465, in _next_data
[rank0]: return self._process_data(data)
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 1491, in _process_data
[rank0]: data.reraise()
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/_utils.py", line 715, in reraise
[rank0]: raise exception
[rank0]: UnboundLocalError: Caught UnboundLocalError in DataLoader worker process 0.
[rank0]: Original Traceback (most recent call last):
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/_utils/worker.py", line 351, in _worker_loop
[rank0]: data = fetcher.fetch(index) # type: ignore[possibly-undefined]
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
[rank0]: data = [self.dataset[idx] for idx in possibly_batched_index]
[rank0]: File "/root/miniconda3/envs/got/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 52, in
[rank0]: data = [self.dataset[idx] for idx in possibly_batched_index]
[rank0]: File "/mnt/f/GOT-OCR2.0/GOT-OCR-2.0-master/GOT/data/conversation_dataset_qwen.py", line 277, in getitem
[rank0]: image_name = image_path + image_file
[rank0]: UnboundLocalError: local variable 'image_path' referenced before assignment
请问训练时报这个错因为什么呢?

@ScarlettTianYou
Copy link

路径问题,你检查一下image_path看看最后面是不是多了个/,源代码image_name = image_path + image_file有点问题,这样写就可以解决了image_name = os.path.join(image_path, image_file)

@dw199777
Copy link
Author

路径问题,你检查一下image_path看看最后面是不是多了个/,源代码image_name = image_path + image_file有点问题,这样写就可以解决了image_name = os.path.join(image_path, image_file)

您好,修改代码image_name = os.path.join(image_path, image_file)后依然报错
image
数据集定义:CONVERSATION_DATA = {

'data_1': {
    'images': '/mnt/f/GOT-OCR2.0/GOT-OCR-2.0-master/Data-for-LaTeX_OCR/fullhand/images',
    'annotations': '/mnt/f/GOT-OCR2.0/GOT-OCR-2.0-master/Data-for-LaTeX_OCR/fullhand/data.json',
},

}
请问这是因为什么呢

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