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

'Beziers' object has no attribute '__len__' #455

Open
rzamarefat opened this issue Oct 10, 2021 · 14 comments
Open

'Beziers' object has no attribute '__len__' #455

rzamarefat opened this issue Oct 10, 2021 · 14 comments

Comments

@rzamarefat
Copy link

Hi. Thank you for the great repo. I have followed instructions to installation and usage of ABCNet and everything have gone well. But the problem is when I run the demo I got the following error:
'Beziers' object has no attribute 'len'

This problem lies on 86th line of poolers.py module of detectron2. How can I solve this?

@Eric-Zhang1990
Copy link

Same problem,please give some advise.

@Eric-Zhang1990
Copy link

I add following code under class Beziers:, but another error occured.
def len(self):
self.tensor.len()

The another error is :
Traceback (most recent call last):
File "demo/demo.py", line 88, in
predictions, visualized_output = demo.run_on_image(img)
File "/mnt/datadisk0/zsf/AdelaiDet/demo/predictor.py", line 54, in run_on_image
predictions = self.predictor(image)
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 316, in call
predictions = self.model([inputs])[0]
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/one_stage_detector.py", line 100, in forward
return self.inference(batched_inputs)
File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/one_stage_detector.py", line 164, in inference
results, _ = self.roi_heads(images, features, proposals, None)
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/roi_heads/text_head.py", line 208, in forward
bezier_features = self.pooler(features, beziers)
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/poolers.py", line 135, in forward
pooler_fmt_boxes = convert_boxes_to_pooler_format(box_lists)
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/modeling/poolers.py", line 86, in convert_boxes_to_pooler_format
sizes = shapes_to_tensor([x.len() for x in box_lists], device=boxes.device)
File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/layers/wrappers.py", line 35, in shapes_to_tensor
return torch.as_tensor(x, device=device)
RuntimeError: Could not infer dtype of NoneType

anyone can give some advise?

@Eric-Zhang1990
Copy link

安装文档中找到相应解决方案,在readme的Installation里。
First install Detectron2 following the official guide: INSTALL.md.
Please use Detectron2 with commit id 9eb4831 if you have any issues related to Detectron2.

@ku21fan
Copy link

ku21fan commented Oct 20, 2021

I met the same problem and solved it by reinstalling AdelaiDet with prebuilt detectron2.
I don't know if this is the right way, but at least I can use demo.py with pre-trained model (ctw1500_attn_R_50.pth).

In my case, when I installed detection2 by following "Build Detectron2 from Source" with the below command

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

and then try to run demo.py, I got "AttributeError: 'Beziers' object has no attribute 'len'"

After I reinstalled AdelaiDet with prebuilt detectron2 by following command,
(I use Pytorch 1.9.1 and cuda 11.1, check your pytorch and cuda version and change /cu111/torch1.9/ part)

cd AdelaiDet/
rm -r build/
pip uninstall detectron2
python -m pip install detectron2 -f \
  https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html   
python setup.py build develop

now I can run demo.py without the error.
Hope it helps :D

@Yuliang-Liu
Copy link
Contributor

Thanks. I have tested using Detectron2 with commit id 9eb4831, and the error does not occur. You may find the link here https://github.com/aim-uofa/AdelaiDet#Installation

@ushio20
Copy link

ushio20 commented Nov 3, 2021

I met the same problem and solved it by reinstalling AdelaiDet with prebuilt detectron2. I don't know if this is the right way, but at least I can use demo.py with pre-trained model (ctw1500_attn_R_50.pth).

In my case, when I installed detection2 by following "Build Detectron2 from Source" with the below command

python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

and then try to run demo.py, I got "AttributeError: 'Beziers' object has no attribute 'len'"

After I reinstalled AdelaiDet with prebuilt detectron2 by following command, (I use Pytorch 1.9.1 and cuda 11.1, check your pytorch and cuda version and change /cu111/torch1.9/ part)

cd AdelaiDet/
rm -r build/
pip uninstall detectron2
python -m pip install detectron2 -f \
  https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html   
python setup.py build develop

now I can run demo.py without the error. Hope it helps :D

My Rocm to compile with commit id 9eb4831 will error,do you know the reason?how to solve it,please?

@Chang-shuaishuai
Copy link

Same problem,Try the above methods will not work,and display in pycharm :

Arguments: Namespace(confidence_threshold=0.3, config_file='configs/BAText/ReCTS/v2_chn_attn_R_50.yaml', input='datasets/ReCTS_test_images/', opts=['MODEL.WEIGHTS weight/model_v2_rects.pth'], output=None, video_input=None, webcam=False) Traceback (most recent call last):
 File "/home/jsj/AdelaiDet-master/AdelaiDet-master/demo/demo.py", line 78, in <module> cfg = setup_cfg(args) 
File "/home/jsj/AdelaiDet-master/AdelaiDet-master/demo/demo.py", line 23, in setup_cfg cfg.merge_from_file(args.config_file) 
File "/home/jsj/detectron2/detectron2/config/config.py", line 45, in merge_from_file assert PathManager.isfile(cfg_filename), f"Config file '{cfg_filename}' does not exist!"
 AssertionError: Config file 'configs/BAText/ReCTS/v2_chn_attn_R_50.yaml' does not exist!

But the file exists and the path is correct.how to solve it,please?

@BradXiao
Copy link

The same problem encountered.
Solved by re-installing detectron at version 0.5. (https://github.com/facebookresearch/detectron2/releases)

@blue-zircon
Copy link

Installing detectron version 0.5 - Didn't work for me

  1. Installed pytorch 1.9 (conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 -c pytorch)
  2. Install detectron 0.5 cpu version (https://github.com/facebookresearch/detectron2/releases/tag/v0.5)
    ERROR: Could not find a version that satisfies the requirement detectron2==0.5 (from versions: none) ERROR: No matching distribution found for detectron2==0.5

Installing the detectron with commit id 9eb4831 - Worked
https://github.com/facebookresearch/detectron2.git@9eb4831f742ae6a13b8edb61d07b619392fb6543
(I had pytorch 1.9, not sure if it makes any difference)

@wuzhenyusjtu
Copy link

wuzhenyusjtu commented Feb 9, 2022

In adet/structures/beziers.py add the following magic method:

def __len__(self):
    return self.tensor.shape[0]

@CarlBhy
Copy link

CarlBhy commented Mar 23, 2022

def len(self):
return self.tensor.shape[0]

Thanks for your valuable comment which truly helps me.

1 similar comment
@CarlBhy
Copy link

CarlBhy commented Mar 23, 2022

def len(self):
return self.tensor.shape[0]

Thanks for your valuable comment which truly helps me.

@MinNamgung
Copy link

A newer version of CUDA and PyTorch should be matched.
Here is the link: https://github.com/facebookresearch/detectron2/releases

I had the same issue. But once I downgrade the PyTorch it worked.

@fairydaisy
Copy link

I add following code under class Beziers:, but another error occured. def len(self): self.tensor.len()

The another error is : Traceback (most recent call last): File "demo/demo.py", line 88, in predictions, visualized_output = demo.run_on_image(img) File "/mnt/datadisk0/zsf/AdelaiDet/demo/predictor.py", line 54, in run_on_image predictions = self.predictor(image) File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/engine/defaults.py", line 316, in call predictions = self.model([inputs])[0] File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/one_stage_detector.py", line 100, in forward return self.inference(batched_inputs) File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/one_stage_detector.py", line 164, in inference results, _ = self.roi_heads(images, features, proposals, None) File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/roi_heads/text_head.py", line 208, in forward bezier_features = self.pooler(features, beziers) File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, **kwargs) File "/mnt/datadisk0/zsf/AdelaiDet/adet/modeling/poolers.py", line 135, in forward pooler_fmt_boxes = convert_boxes_to_pooler_format(box_lists) File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/modeling/poolers.py", line 86, in convert_boxes_to_pooler_format sizes = shapes_to_tensor([x.len() for x in box_lists], device=boxes.device) File "/home/ubuntu/miniconda3/envs/torch/lib/python3.8/site-packages/detectron2/layers/wrappers.py", line 35, in shapes_to_tensor return torch.as_tensor(x, device=device) RuntimeError: Could not infer dtype of NoneType

anyone can give some advise?

it just work for me without any error,thx a lot

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