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

AttributeError: 'NoneType' object has no attribute 'shape' #41

Open
wolfwaytx opened this issue Mar 16, 2023 · 14 comments
Open

AttributeError: 'NoneType' object has no attribute 'shape' #41

wolfwaytx opened this issue Mar 16, 2023 · 14 comments

Comments

@wolfwaytx
Copy link

wolfwaytx commented Mar 16, 2023

作者你好,训练时出现了这个报错:

File "/private/TX/anaconda3/envs/TCTrack/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
    data.reraise()
  File "/private/TX/anaconda3/envs/TCTrack/lib/python3.8/site-packages/torch/_utils.py", line 434, in reraise
    raise exception
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/private/TX/anaconda3/envs/TCTrack/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/private/TX/anaconda3/envs/TCTrack/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/private/TX/anaconda3/envs/TCTrack/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/private/TX/TCTrack-main/pysot/datasets/dataset.py", line 306, in __getitem__
    current_templatebox = self._get_bbox(current_templateimage, current[0][1])
  File "/private/TX/TCTrack-main/pysot/datasets/dataset.py", line 260, in _get_bbox
    imh, imw = image.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'

经过debug后发现在pysot/datasets/dataset.py中

        current_templateimage=cv2.imread(current[0][0])
        current_searchimg=cv2.imread(current[1][0])

中current_templateimage和current_searchimg获取到的信息为None 但是我单独写了一个test 代入同样的image路径和以上的代码 发现是可以读取到数据的(非None) test代码如下:

import cv2
import numpy as np

current=(('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_004614/000003.00.x.jpg', [864, 526, 911, 561]), ('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_004614/000010.00.x.jpg', [855, 515, 910, 555]))
current_templateimage=cv2.imread(current[0][0])
current_searchimg=cv2.imread(current[1][0])
cv2.imshow("test", current_templateimage)
cv2.waitKey(0)

请问该如何解决呢

@ospreyclaw
Copy link

我也遇到了一模一样的报错
AttributeError: Caught AttributeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/miniconda3/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/root/autodl-tmp/TCTrack-main/TCTrack-main/tools/../pysot/datasets/dataset.py", line 306, in __getitem__ current_templatebox = self._get_bbox(current_templateimage, current[0][1]) File "/root/autodl-tmp/TCTrack-main/TCTrack-main/tools/../pysot/datasets/dataset.py", line 260, in _get_bbox imh, imw = image.shape[:2] AttributeError: 'NoneType' object has no attribute 'shape'
并且前面有某些图片无法找到的warning,例如
[ WARN:0@13.534] global /io/opencv/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_('./train_dataset/got10k/crop511/GOT-10k_Train_split_12/GOT-10k_Train_005874/000041.00.x.jpg'): can't open/read file: check file path/integrity
但是当我真的把某张crop511的图片删除后,却没有显示未找到这张图片的警告,所以我觉得很奇怪。

@ospreyclaw
Copy link

因为在到这一步之前,还有一个没有找到vid数据集的报错,为了解决这个问题我改动了代码,直接输入了GOT10k作为参数,不知道是不是这里导致了错误(虽然我觉得应该不是)。

@ospreyclaw
Copy link

这里显示我打不开的图片包括:
GOT-10k_Train_split_04/GOT-10k_Train_001641/000038.00.x.jpg
GOT-10k_Train_split_04/GOT-10k_Train_001641/000024.00.x.jpg
GOT-10k_Train_split_13/GOT-10k_Train_006169/000188.00.x.jpg
GOT-10k_Train_split_13/GOT-10k_Train_006169/000183.00.x.jpg
GOT-10k_Train_split_06/GOT-10k_Train_002685/000089.00.x.jpg
等等,请问您的warning是和我的一样吗?

@wolfwaytx
Copy link
Author

是的,我也有同样的warning错误,并且在三个数据集中都有出现,但报错的图片和您的不同。如下是一部分warning:

[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/lasot/crop511/sheep-10/000235.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/lasot/crop511/sheep-10/000199.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/vid/crop511/a/ILSVRC2015_train_00034003/000116.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/vid/crop511/a/ILSVRC2015_train_00034003/000076.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/lasot/crop511/chameleon-1/001913.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/lasot/crop511/chameleon-1/001908.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_007777/000494.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@19.656] global loadsave.cpp:244 findDecoder imread_('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_007777/000527.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@20.024] global loadsave.cpp:244 findDecoder imread_('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_008013/000019.00.x.jpg'): can't open/read file: check file path/integrity
[ WARN:0@20.024] global loadsave.cpp:244 findDecoder imread_('./train_dataset/got10k/crop511/GOT-10k_Train/GOT-10k_Train_008013/000007.00.x.jpg'): can't open/read file: check file path/integrity

@ospreyclaw
Copy link

我怀疑是路径问题,你尝试把pysot文件夹的config.py中的DATASET.VID.ROOT的./改成../看看是否依然无法运行,我这样尝试了以后虽然有新的报错,但打不开文件的警告没有了。

@wolfwaytx
Copy link
Author

试过了,这样不行,直接就路径报错了

@FearlessArmy
Copy link

是因为图片读取错误,在制作crop511数据集时存在错误或者相对路径有问题,用debug跳转到该语句,查看相对路径,或者debug运行,查看报错时传入的参数

@852653835
Copy link

试过了,这样不行,直接就路径报错了
请问问题解决了吗?我遇到了同样的问题

@852653835
Copy link

我怀疑是路径问题,你尝试把pysot文件夹的config.py中的DATASET.VID.ROOT的./改成../看看是否依然无法运行,我这样尝试了以后虽然有新的报错,但打不开文件的警告没有了。

请问有解决问题吗?

@ziangcao0312
Copy link
Collaborator

这个是路径的问题,你可以debug一下这个地方,通常是cv2.imread()里面相对路径出现问题,可以考虑替换为绝对路径

@W-zzzp
Copy link

W-zzzp commented Sep 14, 2023

路径问题是因为在core文件夹下的dataset.py中加载的数据集路径直接使用的config.py的root路径,所以无法正确找到图片路径。但是我的问题是在第一次启动时,在dataset.py的291行,if neg值始终为True,这样的话current没有初始化,但是在298和299中使用到了未初始化的currents报错,这个有解决办法嘛

@hao666liu
Copy link

路径问题是因为在core文件夹下的dataset.py中加载的数据集路径直接使用的config.py的root路径,所以无法正确找到图片路径。但是我的问题是在第一次启动时,在dataset.py的291行,if neg值始终为True,这样的话current没有初始化,但是在298和299中使用到了未初始化的currents报错,这个有解决办法嘛

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

@zryzds
Copy link

zryzds commented Dec 15, 2023

试过了,这样不行,直接就路径报错了

您好,我遇到了相同的问题,请问您解决了吗

@zryzds
Copy link

zryzds commented Dec 15, 2023

路径问题是因为在core文件夹下的dataset.py中加载的数据集路径直接使用的config.py的root路径,所以无法正确找到图片路径。但是我的问题是在第一次启动时,在dataset.py的291行,if neg值始终为True,这样的话current没有初始化,但是在298和299中使用到了未初始化的currents报错,这个有解决办法嘛

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

您好 你解决了这个问题吗

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

8 participants