AlphaPose icon indicating copy to clipboard operation
AlphaPose copied to clipboard

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)

Open arakis92 opened this issue 2 years ago • 9 comments

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)

arakis92 avatar Jul 29 '22 09:07 arakis92

Hi, what command are you running?

Fang-Haoshu avatar Jul 31 '22 03:07 Fang-Haoshu

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 write_results _, 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!

taledv avatar Oct 09 '23 06:10 taledv

Any update on this ?

vuxminhan avatar Dec 25 '23 16:12 vuxminhan

Anyone solved this problem?

OliviaNocentini avatar Feb 05 '24 16:02 OliviaNocentini