AlphaPose alphapose使用

install

run

  • python scripts/demo_inference.py --cfg configs/coco/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/fast_res50_256x192.pth --indir examples/demo/

  • python scripts/demo_inference.py --cfg configs/coco/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/fast_res50_256x192.pth --indir examples/demo/

(DiffuseIT) pdd@pdd-Dell-G15-5511:~/Downloads/MYUPOSE/AlphaPose$ python scripts/demo_inference.py --cfg configs/coco/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/fast_res50_256x192.pth --indir examples/demo/
2023-06-03 01:23:28 [DEBUG]: Loaded backend agg version v2.2.
/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/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/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/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)
Downloading: "https://download.pytorch.org/models/resnet50-0676ba61.pth" to /home/pdd/.cache/torch/hub/checkpoints/resnet50-0676ba61.pth
  1%|▉                                                                                                                                                                                                  | 512k/97.8M [00:00<00:53, 1.90MB/s]2023-06-03 01:23:30 [DEBUG]: Loaded backend agg version v2.2.
2023-06-03 01:23:30 [DEBUG]: Loaded backend agg version v2.2.
2023-06-03 01:23:30 [DEBUG]: Loaded backend agg version v2.2.
  8%|████████████████                                                                                                                                                                                  | 8.12M/97.8M [00:00<00:05, 17.3MB/s]Loading YOLO model..
 15%|█████████████████████████████▎                                                                                                                                                                    | 14.8M/97.8M [00:01<00:04, 21.4MB/s]Process Process-2:
Traceback (most recent call last):
  File "/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pdd/Downloads/MYUPOSE/AlphaPose/alphapose/utils/detector.py", line 243, in image_detection
    dets = self.detector.images_detection(imgs, im_dim_list)
  File "/home/pdd/Downloads/MYUPOSE/AlphaPose/detector/yolo_api.py", line 91, in images_detection
    self.load_model()
  File "/home/pdd/Downloads/MYUPOSE/AlphaPose/detector/yolo_api.py", line 49, in load_model
    self.model.load_weights(self.model_weights)
  File "/home/pdd/Downloads/MYUPOSE/AlphaPose/detector/yolo/darknet.py", line 407, in load_weights
    fp = open(weightfile, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'detector/yolo/data/yolov3-spp.weights'
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 97.8M/97.8M [00:04<00:00, 21.1MB/s]
Loading pose model from pretrained_models/fast_res50_256x192.pth...
Traceback (most recent call last):
  File "/home/pdd/Downloads/MYUPOSE/AlphaPose/scripts/demo_inference.py", line 183, in <module>
    pose_model.load_state_dict(torch.load(args.checkpoint, map_location=args.device))
  File "/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/site-packages/torch/serialization.py", line 771, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/site-packages/torch/serialization.py", line 270, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/pdd/anaconda3/envs/DiffuseIT/lib/python3.9/site-packages/torch/serialization.py", line 251, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'pretrained_models/fast_res50_256x192.pth'

  • fast_res50_256x192.pth https://drive.google.com/file/d/1kQhnMRURFiy7NsdS8EFL-8vtqEXOgECn/view
  • cp ./fast_res50_256x192.pth ./MYUPOSE/AlphaPose/pretrained_models/
  • Download the object detection model manually: yolov3-spp.weights(Google Drive | Baidu pan). Place it into detector/yolo/data.

run in lower resources

重点关注一下:

  • psize参数
  • sp 参数
// /home/pdd/Downloads/MYUPOSE/AlphaPose/alphapose/utils/detector.py
    def start_worker(self, target):
        p = Thread(target=target, args=())
        # if self.opt.sp: # TODO
        #     p = Thread(target=target, args=())
        # else:
        #     p = mp.Process(target=target, args=())
        
        # p.daemon = True
        p.start()
        return p

TRACK

  • https://musetransfer.com/s/shtu6pvtl 请点击链接获取《无主题 - osnet_ain_x1_0_msmt17_256x128_amsgrad_ep5…》, 有效期至7月21日

将AlphaPose json结果按照图像名称汇总

import os  
import json

# 读取 AlphaPose JSON 结果文件  
with open("alphapose_result.json", "r") as f:  
    results = json.load(f)

# 获取图像文件的名称  
image_names = [n for n in os.listdir("images")]

# 将结果分组并根据图像名称存储  
result_grouped_by_image_name = {}  
for i, result in enumerate(results["results"]):  
    image_name = result["image_name"]  
    if image_name not in result_grouped_by_image_name:  
        result_grouped_by_image_name[image_name] = []  
    result_grouped_by_image_name[image_name].append(result)

# 输出结果  
for image_name, results in result_grouped_by_image_name.items():  
    print(f"{image_name} results:")  
    for result in results:  
        print(f"{result['Poses'][0]['positions']}")  

import os  
import json

# 读取 JSON 文件  
with open("alphapose_result.json", "r") as f:  
    results = json.load(f)

# 获取图像文件的名称  
image_names = [n for n in os.listdir("images")]

# 将结果分组并根据图像名称存储  
result_grouped_by_image_id = {}  
for i, result in enumerate(results["results"]):  
    image_name = result["image_name"]  
    if image_name not in result_grouped_by_image_id:  
        result_grouped_by_image_id[image_name] = []  
    result_grouped_by_image_id[image_name].append(result)

# 合并相同 image_id 的项目之间的 keypoints  
merged_keypoints = []  
for image_name, results in result_grouped_by_image_id.items():  
    results_by_id = {}  
    for result in results:  
        if result["image_id"] == image_name:  
            results_by_id[result["category_id"]] = result["keypoints"]  
        else:  
            results_by_id[result["category_id"]] = merged_keypoints  
    merged_keypoints = results_by_id["keypoints"]  
    merged_keypoints.sort()  
    result_grouped_by_image_id[image_name] = merged_keypoints

# 输出结果  
for image_name, results in result_grouped_by_image_id.items():  
    print(f"{image_name} results:")  
    for result in results:  
        print(f"{result['Poses'][0]['positions']}")  

RUN IN DOCKER

FROM pytorchlightning/pytorch_lightning:base-cuda-py3.7-torch1.12-cuda11.3.1
# FROM nvidia/cuda:11.6.0-devel-ubuntu20.04
# https://github.com/nianjingfeng/AlphaPose_Docker/blob/main/Dockerfile_alphapose

RUN apt clean

RUN DEBIAN_FRONTEND=noninteractive apt update && DEBIAN_FRONTEND=noninteractive apt install -y --allow-change-held-packages \
    ffmpeg \
    git \
    build-essential \
    ninja-build \
    cuda-libraries-11-6 \
    mesa-common-dev \
    libosmesa6 libosmesa6-dev \
    libgles2-mesa-dev \
    libglu1-mesa-dev \
    libgles2-mesa-dev \
    libcublas-11-6 \
    libcublas-dev-11-6 \
    libcusparse-dev-11-6 \
    cuda-nvcc-11-6 \
    libcusolver-dev-11-6 \
    cuda-nvrtc-dev-11-6 \
    libcurand-dev-11-6 \
    cuda-nvml-dev-11-6 \
    libcufft-dev-11-6 \
    cuda-toolkit-11-6 \
    nvidia-cuda-toolkit \
    libyaml-dev

ENV CUDA_HOME='/usr/local/cuda'

RUN DEBIAN_FRONTEND=noninteractive apt -y install python3 python3-pip python3-tk

RUN pip install "torch==1.12.1+cu116" "torchvision==0.13.1" "torchaudio==0.12.1" --extra-index-url https://download.pytorch.org/whl/cu116
RUN pip install opencv-contrib-python-headless -i https://pypi.douban.com/simple/
# RUN pip install pip --upgrade

RUN pip install cython pycocotools -i https://pypi.douban.com/simple/

RUN python3 -c "import torch; print(torch.version.cuda)" 

RUN mkdir /build
RUN cd /build && git clone https://github.com/HaoyiZhu/HalpeCOCOAPI.git
RUN cd /build && git clone https://github.com/MVIG-SJTU/AlphaPose.git


RUN cd /build/HalpeCOCOAPI/PythonAPI && python3 setup.py build develop --user

WORKDIR /build/AlphaPose

RUN TORCH_CUDA_ARCH_LIST="6.1;7.5;8.6" \
    PATH=/usr/local/cuda/bin/:$PATH \
    LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH  \
    python3 setup.py build develop --user

# Fix compatibility issue with numpy >= 1.20
RUN pip install git+https://github.com/H4dr1en/cython_bbox.git@patch-1

RUN apt install bc -y && \
    pip install boto3 && \
    python3 -c "import torchvision.models as tm; tm.resnet152(pretrained=True)"

# Download weights, adapt to what you need
RUN pip install gdown  -i https://pypi.douban.com/simple/
RUN mkdir -p detector/yolo/data && \
    gdown 1D47msNOOiJKvPOXlnpyzdKA3k6E97NTC -O detector/yolo/data/yolov3-spp.weights && \
    gdown 1S-ROA28de-1zvLv-hVfPFJ5tFBYOSITb -O pretrained_models/halpe26_fast_res50_256x192.pth
  • docker run --rm --gpus all -it alphapose /bin/bash
  • python3 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

CG

json文件中的每个项目包含"image_id": "1.jpg", "category_id": 1, "keypoints": [ ** ],
"score": 3.1222591400146484, 
"box": [568.2610473632812, 41.407630920410156, 148.61181640625, 495.2166976928711],
"idx": [0.0]},
将image_id相同的项目的keypoints合并起来
  • Alphapose - Windows下Alphapose(Pytorch 1.1+)版本2021最新环境配置步骤以及踩坑说明
  • HAKE
  • 现有的基于图像的活动理解方法主要采用直接映射,即从图像到活动的概念,由于差距巨大,可能会遇到性能瓶颈。有鉴于此,我们提出了一种新的途径:首先推断人类的部分状态,然后基于部分级语义推理出活动。人体部分状态(PaSta)是细粒度的动作语义表征,如〈手,握,某事〉,它可以组成活动,帮助我们迈向人类活动知识引擎。为了充分利用PaSta的强大功能,我们构建了一个大规模的知识库PaStaNet,其中包含7M+PaSta注释。并提出了两个相应的模型:首先,我们设计了一个名为Activity2Vec的模型来提取PaSta特征,该模型旨在作为各种活动的通用表示。其次,我们使用基于PaSta的推理方法来推断活动。在PaStaNet的推动下,我们的方法实现了显著的改进,例如在全容量和单容量时分别为6.4和13.9毫安时
  • AlphaPose姿态估计 只输出骨架 源码修改 相关记录
  • https://github.com/oreo-lp/AlphaPose_TRT
<think>好的,用户现在的问题是询问安装基础依赖库的位置。我需要根据之前的对话和提供的引用内容来给出准确的回答。首先,回顾之前的对话,用户之前遇到了ModuleNotFoundError: No module named 'cython_bbox'的问题,我提供了分步解决方案,包括安装基础依赖库如Cython和NumPy。现在用户想知道这些基础依赖库具体安装到了哪里。 根据用户提供的引用,特别是引用[2]中提到,通过pip安装的第三方库会放在Lib/site-packages目录下。同时,引用[3]也提到了依赖包安装的位置。因此,基础依赖库如Cython和NumPy通常会被安装到Python的site-packages目录中。 接下来需要考虑不同操作系统下的路径差异。比如,在Windows、Linux和macOS中,Python的安装路径可能不同,用户可能有多个Python版本或虚拟环境,这会影响安装位置。需要指导用户如何通过命令行查看具体路径,例如使用pip show命令或者Python的sys模块来定位。 此外,用户可能对虚拟环境中的安装位置不太清楚,需要说明在虚拟环境下,依赖库会被安装在虚拟环境的site-packages目录下,而不是全局目录。这也解释了为什么有时候用户安装了一个包,但在另一个环境中无法找到的原因。 另外,用户可能需要知道如何验证依赖库是否正确安装,可以通过导入模块并查看是否有错误来确认。同时,如果用户遇到路径问题,可能需要检查PYTHONPATH环境变量是否包含正确的路径。 需要确保回答清晰,分步骤说明不同情况下的安装位置,并提供验证方法。同时,结合之前的引用内容,引用[2]和引用[3]中的信息支持回答的准确性。最后,提醒用户注意虚拟环境和全局安装的区别,以及多版本Python共存时的路径问题。</think>### 分步解答:Python基础依赖库的安装位置解析 --- #### **步骤1:理解依赖库安装位置的基本规则** 1. **全局安装(默认位置)** - 使用系统级`pip`安装的库会存放在**Python安装目录的`Lib/site-packages`子目录**下 - 示例路径: - *Windows*: `C:\Python39\Lib\site-packages` - *Linux/macOS*: `/usr/local/lib/python3.9/site-packages` - 引用[2]验证:通过`pip install XX.whl`安装后,文件会出现在`Lib/site-packages`[^2] 2. **用户级安装** 添加`--user`参数时,库会安装到用户专属目录: - *Windows*: `%APPDATA%\Python\Python39\site-packages` - *Linux/macOS*: `~/.local/lib/python3.9/site-packages` --- #### **步骤2:定位具体安装路径** 1. **通过`pip show`命令查询** ```bash pip show cython numpy | grep "Location" ``` - 输出示例: ``` Location: /usr/local/lib/python3.9/site-packages ``` 2. **Python交互式查询** ```python import numpy, cython print(numpy.__file__) # 显示numpy安装路径 print(cython.__file__) # 显示cython安装路径 ``` --- #### **步骤3:特殊场景路径说明** 1. **虚拟环境安装** - 若使用`venv`或`conda`环境,依赖库存放在虚拟环境目录中: - *venv*: `your_project/venv/lib/python3.9/site-packages` - *conda*: `~/anaconda3/envs/env_name/lib/python3.9/site-packages` - 引用[3]关联:项目打包时需注意区分环境路径[^3] 2. **源码编译安装** 通过`python setup.py install`安装的库会存放到: ```bash python setup.py install --record files.txt # 记录安装路径 ``` --- #### **步骤4:系统级依赖库的特殊位置** 1. **通过系统包管理器安装** - *Ubuntu/Debian*使用`apt`安装时: ```bash dpkg -L python3-numpy # 查看deb包安装路径 ``` - 通常位于`/usr/lib/python3/dist-packages` 2. **WRF等科学计算依赖库** 如引用[1]所述,HDF5/NetCDF等库可能安装在`/usr/local`或自定义路径[^1] --- ### 关键原理说明 1. **`sys.path`搜索机制** Python解释器按`sys.path`列表顺序搜索依赖库,优先级: ```text 1. 当前目录 → 2. 环境变量PYTHONPATH → 3. 标准库目录 → 4. site-packages ``` 2. **多版本共存影响** 当系统存在多个Python版本时,需确认`pip`对应版本: ```bash python3.9 -m pip install numpy # 指定3.9版本安装 ``` --- ### 验证安装路径实操 ```bash # 检查Cython安装是否在预期路径 ls -l $(python -c "import cython; print(cython.__file__)") # 查看所有已安装包路径 pip list -v | grep -E "cython|numpy" ``` --- ### 相关问题 1. 如何将第三方库安装到自定义目录? 2. 虚拟环境和全局环境的依赖库冲突如何解决? 3. 为什么`import`能找到库但运行时提示缺失依赖? [^1]: WRF官方编译指南中的路径配置说明 [^2]: Python包安装路径验证方法 [^3]: 项目部署时的环境隔离要求
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值