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

Can't train this model (ValueError: 'UNK' is not in list) #20

Open
Eom-taeseon opened this issue Nov 8, 2021 · 1 comment
Open

Can't train this model (ValueError: 'UNK' is not in list) #20

Eom-taeseon opened this issue Nov 8, 2021 · 1 comment

Comments

@Eom-taeseon
Copy link

Eom-taeseon commented Nov 8, 2021

I'm trying to follow ConvCap: Convolutional Image Captioning(README.md)
But it doesn't work

after I write the code
python main.py model_dir

It sends a error message like thie

[DEBUG] #words in wordlist: 9222
[DEBUG] Loading train data ... 3.029390 secs
C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\optim\lr_scheduler.py:82: UserWarning: Detected call of lr_scheduler.step() before optimizer.step(). In PyTorch 1.1.0 and later, you should call them in the opposite order: optimizer.step() before lr_scheduler.step(). Failure to do this will result in PyTorch skipping the first value of the learning rate schedule.See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
"https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate", UserWarning)
0%| | 0/5664 [00:00<?, ?it/s]
Traceback (most recent call last):
File "main.py", line 89, in
main()
File "main.py", line 72, in main
train(args)
File "D:\2021\컴퓨터 비전\eval\이미지 캡셔닝\train.py", line 90, in train
tqdm(enumerate(train_data_loader), total=nbatches):
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\tqdm\std.py", line 1180, in iter
for obj in iterable:
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\utils\data\dataloader.py", line 819, in next
return self._process_data(data)
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\utils\data\dataloader.py", line 846, in _process_data
data.reraise()
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch_utils.py", line 369, in reraise
raise self.exc_type(msg)
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\utils\data_utils\worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "C:\Users\410\anaconda3\envs\Image_Captioning\lib\site-packages\torch\utils\data_utils\fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "D:\2021\컴퓨터 비전\eval\이미지 캡셔닝\coco_loader.py", line 102, in getitem
wordclass[i, word_i] = self.wordlist.index(word)
ValueError: 'UNK' is not in list

How can I solve this?

@Eom-taeseon Eom-taeseon changed the title Can't train this model Can't train this model (ValueError: 'UNK' is not in list) Nov 8, 2021
@vakadanaveen
Copy link

vakadanaveen commented Dec 6, 2021

I am having the exact same error.
To solve this error I simply added 'UNK' token to the wordlist.
In the program coco_loader.py , line number 40.
Replace the line
self.wordlist = ['EOS'] + sorted(wordlist)
with
self.wordlist = ['EOS'] + sorted(wordlist)+['UNK']

Then the program works.

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