aim-uofa / AdelaiDet

AdelaiDet is an open source toolbox for multiple instance-level detection and recognition tasks.
https://git.io/AdelaiDet
Other
3.36k stars 643 forks source link

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

Open rzamarefat opened 2 years ago

rzamarefat commented 2 years ago

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 commented 2 years ago

Same problem,please give some advise.

Eric-Zhang1990 commented 2 years ago

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_stagedetector.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 commented 2 years ago

安装文档中找到相应解决方案,在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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

blue-zircon commented 2 years ago

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 commented 2 years ago

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

def __len__(self):
    return self.tensor.shape[0]
CarlBhy commented 2 years ago

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

Thanks for your valuable comment which truly helps me.

CarlBhy commented 2 years ago

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

Thanks for your valuable comment which truly helps me.

MinNamgung commented 2 years ago

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 commented 2 years ago

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_stagedetector.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