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

您好,我在读取数据遇到了IndexError: too many indices for array的问题 #9

Open
userpei opened this issue Dec 1, 2020 · 3 comments

Comments

@userpei
Copy link

userpei commented Dec 1, 2020

Traceback (most recent call last):
File "train.py", line 155, in
train(opt)
File "train.py", line 76, in train
data = loader.get_batch('train')
File "VSUA-Captioning-master/dataloader.py", line 144, in get_batch
ix, tmp_wrapped = self._prefetch_process[split].get()
File "VSUA-Captioning-master/dataloader.py", line 368, in get
tmp = self.split_loader.next()
File "/home/usr2/anaconda2//lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 623, in next
return self._process_next_batch(batch)
File "/home/usr2/anaconda2/envs/pyx/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 658, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
IndexError: Traceback (most recent call last):
File "/home/usr2/anaconda2//lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/VSUA-Captioning-master/dataloader.py", line 253, in getitem
sg_data = self.get_graph_data(index)
File "/VSUA-Captioning-master/dataloader.py", line 277, in get_graph_data
rela['edges'] = triplet[:, 0:2]
IndexError: too many indices for array

@kkunli
Copy link

kkunli commented Dec 28, 2020

您好,我也在使用semantic relationship时遇到了这个问题,请问解决了吗?

@userpei
Copy link
Author

userpei commented Dec 30, 2020

您好,我也在使用semantic relationship时遇到了这个问题,请问解决了吗?

    if sg_use['rela_matrix'].shape[0] == 0:
        sg_use['rela_matrix'] = np.array([[0, 0, self.sg_vocab['near']]], dtype=sg_use['rela_matrix'].dtype)

修改之后,没有报错了

@kkunli
Copy link

kkunli commented Jan 5, 2021

修改后迭代几次,还是报错,您没发生这个问题吗?

KeyError: 'Traceback (most recent call last):\n File "/home/b604_1/anaconda2/envs/pyli2.7/lib/python2.7/site-packages/torch/utils/data/dataloader.py", line 57, in _worker_loop\n samples = collate_fn([dataset[i] for i in batch_indices])\n File "/home/b604_1/aaa/VSUA-Captioning/dataloader.py", line 253, in getitem\n sg_data = self.get_graph_data(index)\n File "/home/b604_1/aaa/VSUA-Captioning/dataloader.py", line 270, in get_graph_data\n sg_use['rela_matrix'] = np.array([[0, 0, self.sg_vocab['near']]], dtype=sg_use['rela_matrix'].dtype)\nKeyError: 'near'\n'

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