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: invalid index to scalar variable. #1

Open
juechen-zzz opened this issue Jan 12, 2020 · 17 comments
Open

IndexError: invalid index to scalar variable. #1

juechen-zzz opened this issue Jan 12, 2020 · 17 comments

Comments

@juechen-zzz
Copy link

juechen-zzz commented Jan 12, 2020

When I run the code, it will break down sometimes.

Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

@pgu-nd
Copy link

pgu-nd commented Mar 5, 2020

When I run the code, it will break down sometimes.

Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

Hi, did you solve that problem?

@ZhangXY1996
Copy link

When I run the code, it will break down sometimes.

Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

@pgu-nd
Copy link

pgu-nd commented Mar 25, 2020

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

@ZhangXY1996
Copy link

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

Thanks,I have tried to increment the number of training samples and remove the wrong samples, and finally the code can run.

@yangwf1102
Copy link

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

Thanks,I have tried to increment the number of training samples and remove the wrong samples, and finally the code can run.

Hi,I met this problem too.I adjusted the dataset, but I still had this problem during training.can you tell me how to deal with the training data in detail?thank you!

@Young-GG
Copy link

Young-GG commented Sep 7, 2022

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

Thanks,I have tried to increment the number of training samples and remove the wrong samples, and finally the code can run.
你好,你解决这个问题了吗,能说一下修改方法

@Young-GG
Copy link

Young-GG commented Sep 7, 2022

你好,请问你解决这个问题

@Young-GG
Copy link

Young-GG commented Sep 7, 2022

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

Thanks,I have tried to increment the number of training samples and remove the wrong samples, and finally the code can run.

Hi,I met this problem too.I adjusted the dataset, but I still had this problem during training.can you tell me how to deal with the training data in detail?thank you!

你好,请问你解决这个问题了吗

@jiayoujiang
Copy link

When I run the code, it will break down sometimes.
Traceback (most recent call last):
File "demo_MDvsFA_pytorch.py", line 446, in
for bt_idx, data in enumerate(trainset):
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 637, in next
return self._process_next_batch(batch)
File "/home/test/anaconda3/lib/python3.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/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/test/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "demo_MDvsFA_pytorch.py", line 96, in getitem
input_images = real_input[:, :, 2] * 2 - 1
IndexError: invalid index to scalar variable.

I also met this problem, did you solve it?

I think it is because of the data. If you train the model with few images, say the first 100 images, you can run the code without any problems.

Thanks,I have tried to increment the number of training samples and remove the wrong samples, and finally the code can run.

Hi,I met this problem too.I adjusted the dataset, but I still had this problem during training.can you tell me how to deal with the training data in detail?thank you!

你好,请问你解决这个问题了吗

你好请问这个问题最后得到解决了吗?我也有这个问题啊

@jiayoujiang
Copy link

这个问题我这边是解决了,所以发在这里
造成这个bug的主要原因就是数据的问题,real_input那个变量无法读取数据,所以运行时这个变量的值时nan,表示为空
解决办法:寻找数据集的存储路径,imageset_dir后面的路径是否正确注意要使用“/”不要用“\”,使用正确的路径之后就可以real_input就会有值了。

@Drinkwaterever
Copy link

我尝试了你说的这种解决方法,但还是报一样的错误。

@Drinkwaterever
Copy link

这个问题我这边是解决了,所以发在这里 造成这个bug的主要原因就是数据的问题,real_input那个变量无法读取数据,所以运行时这个变量的值时nan,表示为空 解决办法:寻找数据集的存储路径,imageset_dir后面的路径是否正确注意要使用“/”不要用“\”,使用正确的路径之后就可以real_input就会有值了。

我尝试了你说的这种解决方法,但还是报一样的错误。

@jiayoujiang
Copy link

jiayoujiang commented Oct 27, 2022 via email

@Drinkwaterever
Copy link

数据集里面有五十张左右的图片坏了,扫描数据集的图片找到它们,然后删了就好了

---Original--- From: @.> Date: Thu, Oct 27, 2022 16:49 PM To: @.>; Cc: @.@.>; Subject: Re: [wanghuanphd/MDvsFA_cGAN] IndexError: invalid index to scalarvariable. (#1) 这个问题我这边是解决了,所以发在这里 造成这个bug的主要原因就是数据的问题,real_input那个变量无法读取数据,所以运行时这个变量的值时nan,表示为空 解决办法:寻找数据集的存储路径,imageset_dir后面的路径是否正确注意要使用“/”不要用“\”,使用正确的路径之后就可以real_input就会有值了。 我尝试了你说的这种解决方法,但还是报一样的错误。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

按照您说的方法,代码成功跑起来了,非常感谢。但是在epoch1_40的时候,在这报错又出现了,请问您有遇到吗?

@EdwardBao1006
Copy link

如果直接删除破损图像,还是会报错,我是先删除了破损照片,然后对数据集里面的图像重新编号和命名,但是删除的时候一定要成对删除,image+mask,我用的代码如下,记住每次删除图像以后都要重新运行这个程序编号一下。

rename.py

import os
root_path = "./training"
filelist = os.listdir(root_path)

filelist.sort()
total_num = len(filelist)
i = 0
j = 0
for item in filelist:
    if item.endswith("_1.png"):
        src = os.path.join(os.path.abspath(root_path), item)
        s = str(i)
        s = s.zfill(6)  # 保留几位
        dst = os.path.join(os.path.abspath(root_path), s + '_1.png')

        try:
            os.rename(src, dst)
            print ('converting %s to %s ...' % (src, dst))
            i = i + 1
        except:
            continue

    if item.endswith("_2.png"):
        src = os.path.join(os.path.abspath(root_path), item)
        s = str(j)
        s = s.zfill(6)
        dst = os.path.join(os.path.abspath(root_path), s + '_2.png')

        try:
            os.rename(src, dst)
            print ('converting %s to %s ...' % (src, dst))
            j = j + 1
        except:
            continue

希望能帮上忙。

@YangBo0411
Copy link

数据集里面有五十张左右的图片坏了,扫描数据集的图片找到它们,然后删了就好了

---Original--- From: @.> Date: Thu, Oct 27, 2022 16:49 PM To: _@**._>; Cc: _@.@._>; Subject: Re: [wanghuanphd/MDvsFA_cGAN] IndexError: invalid index to scalarvariable. (#1) 这个问题我这边是解决了,所以发在这里 造成这个bug的主要原因就是数据的问题,real_input那个变量无法读取数据,所以运行时这个变量的值时nan,表示为空 解决办法:寻找数据集的存储路径,imageset_dir后面的路径是否正确注意要使用“/”不要用“\”,使用正确的路径之后就可以real_input就会有值了。 我尝试了你说的这种解决方法,但还是报一样的错误。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: _@_.*>

按照您说的方法,代码成功跑起来了,非常感谢。但是在epoch1_40的时候,在这报错又出现了,请问您有遇到吗?

遇到了同样的问题,请问解决了吗?

@CPaul33
Copy link

CPaul33 commented Aug 30, 2024

数据集里面有五十张左右的图片坏了,扫描数据集的图片找到它们,然后删了就好了

---Original--- From: @.> Date: Thu, Oct 27, 2022 16:49 PM To: _@**._>; Cc: _@.@._>; Subject: Re: [wanghuanphd/MDvsFA_cGAN] IndexError: invalid index to scalarvariable. (#1) 这个问题我这边是解决了,所以发在这里 造成这个bug的主要原因就是数据的问题,real_input那个变量无法读取数据,所以运行时这个变量的值时nan,表示为空 解决办法:寻找数据集的存储路径,imageset_dir后面的路径是否正确注意要使用“/”不要用“\”,使用正确的路径之后就可以real_input就会有值了。 我尝试了你说的这种解决方法,但还是报一样的错误。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: _@_.*>

按照您说的方法,代码成功跑起来了,非常感谢。但是在epoch1_40的时候,在这报错又出现了,请问您有遇到吗?

遇到了同样的问题,请问解决了吗?

请问同学你解决这个问题了吗?

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

10 participants