MVIG-SJTU / AlphaPose

Real-Time and Accurate Full-Body Multi-Person Pose Estimation&Tracking System
http://mvig.org/research/alphapose.html
Other
8.02k stars 1.97k forks source link

mportError: cannot import name 'nms_cpu' from partially initialized module 'detector.nms' (most likely due to a circular import) (/home/u1218800/Downloads/AlphaPose-master/detector/nms/__init__.py) #1060

Open arakis92 opened 2 years ago

arakis92 commented 2 years ago

Running in cpu set up by following installation set up. Tried with/without commenting the mentioned line in setup.py In both the cases, the error is same.

File "/home/u1218800/Downloads/AlphaPose-master/detector/nms/nms_wrapper.py", line 4, in from . import nms_cpu, nms_cuda

mportError: cannot import name 'nms_cpu' from partially initialized module 'detector.nms' (most likely due to a circular import) (/home/u1218800/Downloads/AlphaPose-master/detector/nms/init.py)

Fang-Haoshu commented 2 years ago

Hi, what command are you running?

taledv commented 1 year ago

Hello, @Fang-Haoshu I'm joining this issue, I run the following command: ython3 scripts/demo_inference.py --cfg configs/coco/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/simple_res50_256x192.pth --video uw_video.mp4 --outdir output_directory/ --gpus -1

I get the following error:

2023-10-09 06:25:14 [DEBUG]: Loaded backend agg version v2.2. /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") Traceback (most recent call last): File "/home/ec2-user/SageMaker/data-science/AlphaPose/scripts/demo_inference.py", line 178, in det_loader = DetectionLoader(input_source, get_detector(args), cfg, args, batchSize=args.detbatch, mode=mode, queueSize=args.qsize) File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/apis.py", line 12, in get_detector from detector.yolo_api import YOLODetector File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/yolo_api.py", line 27, in from detector.nms import nms_wrapper File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/nms/init.py", line 1, in from .nms_wrapper import nms, soft_nms File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/nms/nms_wrapper.py", line 13, in from . import nms_cpu, nms_cuda ImportError: cannot import name 'nms_cpu' from partially initialized module 'detector.nms' (most likely due to a circular import) (/home/ec2-user/SageMaker/data-science/AlphaPose/detector/nms/init.py)

I read somewhere that if I replace in nms_wrapper.py this: from . import nms_cpu, nms_cuda from .soft_nms_cpu import soft_nms_cpu By: from . import * It solves this "circular import" issue, but instead, it gives the next following error:

(Keep in mind the in I have the src folder inside nms, that contains the following files: nms_cpu.cpp, nms_cuda.cpp, nms_kernel.cu, soft_nms_cpu.cpp, soft_nms_cpu.pyx). So the names nms_cpu, nms_cuda and soft_nms_cpu are the names of the three .cpp files inside the src folder)

2023-10-09 06:29:35 [DEBUG]: Loaded backend agg version v2.2. /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead. warnings.warn( /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or None for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing weights=ResNet50_Weights.IMAGENET1K_V1. You can also use weights=ResNet50_Weights.DEFAULT to get the most up-to-date weights. warnings.warn(msg) 2023-10-09 06:29:39 [DEBUG]: Loaded backend agg version v2.2. 2023-10-09 06:29:39 [DEBUG]: Loaded backend agg version v2.2. 2023-10-09 06:29:39 [DEBUG]: Loaded backend agg version v2.2. Loading pose model from pretrained_models/simple_res50_256x192.pth... /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") 0%| | 0/74133 [00:00<?, ?it/s]Loading YOLO model.. 2023-10-09 06:29:44 [DEBUG]: Loaded backend agg version v2.2. /home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/site-packages/torch/cuda/init.py:546: UserWarning: Can't initialize NVML warnings.warn("Can't initialize NVML") is_numpy is: False dets type is: <class 'torch.Tensor'> dets_th type is: <class 'torch.Tensor'> Process Process-2: Traceback (most recent call last): File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap self.run() File "/home/ec2-user/anaconda3/envs/JupyterSystemEnv/lib/python3.10/multiprocessing/process.py", line 108, in run self._target(*self._args, **self._kwargs) File "/home/ec2-user/SageMaker/data-science/AlphaPose/alphapose/utils/detector.py", line 243, in image_detection dets = self.detector.images_detection(imgs, im_dim_list) File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/yolo_api.py", line 96, in images_detection dets = self.dynamic_write_results(prediction, self.confidence, File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/yolo_api.py", line 116, in dynamic_write_results dets = self.write_results(prediction.clone(), confidence, num_classes, nms, nms_conf) File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/yolo_api.py", line 199, in writeresults , inds = nms_op(image_pred_class[:,:5], nms_conf) File "/home/ec2-user/SageMaker/data-science/AlphaPose/detector/nms/nms_wrapper.py", line 66, in nms inds = nms_cpu.nms(dets_th, iou_thr) NameError: name 'nms_cpu' is not defined

In summary, I'm trying to use the demo_inference.py script with a sample of a 5 seconds video, WITHOUT NIVIDIA/CUDA, only CPU use (as mentioned by the --gpus -1 argument). When I replace both lines by "from . import *" it doesn't even recognise the nms_cpu argument. As I understand I can use AlphaPose WITHOUT GPU's. If someone can help me resolve this issue it would be amazing! Thank you!

vuxminhan commented 10 months ago

Any update on this ?

OliviaNocentini commented 9 months ago

Anyone solved this problem?

JIshanRandika commented 3 months ago

Hey, any update?

JIshanRandika commented 3 months ago

@arakis92 did you find the solution?

good-epic commented 2 months ago

I solved this using importlib, a loader function, and a global variable in the init file as to whether the library was loaded yet (so I only had to lazy load once, though had to add the function call at each use). Let me know if you'd like details. I had to do this also for nms_cuda, soft_nms_cpu, and roi_align_cuda.

libinae commented 1 month ago

I solved this using importlib, a loader function, and a global variable in the init file as to whether the library was loaded yet (so I only had to lazy load once, though had to add the function call at each use). Let me know if you'd like details. I had to do this also for nms_cuda, soft_nms_cpu, and roi_align_cuda.

Could you please provide details of your solution?

jackkolb commented 1 month ago

This is an issue with their YOLOv3 detector. Using yolox works fine once you have the yolox weights in the correct folders (will tell you when you run this demo script).

python scripts/demo_inference.py --cfg configs/halpe_26/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/halpe26_fast_res50_256x192.pth --indir examples/demo/ --save_img --detector yolox