mmskeleton windows安装(mmdetection)及ST-GCN测试和训练

首先安装mmdetection:教程
环境:
OS: Win10
VS: 2015
mmdetection: 1.1.0
mmcv:0.6.0
torch=1.3.1
torchvision=0.4.2
python:3.7.9
cuda:10.1
查看cuda版本:nvcc -V

一、Pytorch环境安装

创建虚拟环境:

conda create -n mmd python=3.7
conda activate mmd
conda install pytorch=1.3 torchvision cudatoolkit=10.1 -c pytorch
pip install cython opencv-python pillow  matplotlib

二、torch源码修改

环境目录是指刚刚创建的mm2虚拟环境位置。

修改 环境目录下\Lib\site-packages\torch\include\c10\util\flat_hash_map.h
1> 删掉 #include <stdexcept>
2> 1379-1398行左右,注释或删掉:

// std::pair<typename Table::iterator, bool> emplace()
// {
//     return emplace(key_type(), convertible_to_value());
// }
// template<typename M>
// std::pair<typename Table::iterator, bool> insert_or_assign(const key_type & key, M && m)
// {
//     auto emplace_result = emplace(key, std::forward<M>(m));
//     if (!emplace_result.second)
//         emplace_result.first->second = std::forward<M>(m);
//     return emplace_result;
// }
// template<typename M>
// std::pair<typename Table::iterator, bool> insert_or_assign(key_type && key, M && m)
// {
//     auto emplace_result = emplace(std::move(key), std::forward<M>(m));
//     if (!emplace_result.second)
//         emplace_result.first->second = std::forward<M>(m);
//     return emplace_result;
// }    

1473-1493行左右,注释或删掉

// template<typename... Args>
// std::pair<typename Table::iterator, bool> emplace(Args &&... args)
// {
//     return Table::emplace(T(std::forward<Args>(args)...));
// }
// std::pair<typename Table::iterator, bool> emplace(const key_type & arg)
// {
//     return Table::emplace(arg);
// }
// std::pair<typename Table::iterator, bool> emplace(key_type & arg)
// {
//     return Table::emplace(arg);
// }
// std::pair<typename Table::iterator, bool> emplace(const key_type && arg)
// {
//     return Table::emplace(std::move(arg));
// }
// std::pair<typename Table::iterator, bool> emplace(key_type && arg)
// {
//     return Table::emplace(std::move(arg));
// }

2.修改 环境目录下\Lib\site-packages\torch\include\c10\util\order_preserving_flat_hash_map.h

注释或删除1499-1518行

//    std::pair<typename Table::iterator, bool> emplace()
//    {
//        return emplace(key_type(), convertible_to_value());
//    }
//    template<typename M>
//    std::pair<typename Table::iterator, bool> insert_or_assign(const key_type & key, M && m)
//    {
//        auto emplace_result = emplace(key, std::forward<M>(m));
//        if (!emplace_result.second)
//            emplace_result.first->second = std::forward<M>(m);
//        return emplace_result;
//    }
//    template<typename M>
//    std::pair<typename Table::iterator, bool> insert_or_assign(key_type && key, M && m)
//    {
//        auto emplace_result = emplace(std::move(key), std::forward<M>(m));
//        if (!emplace_result.second)
//            emplace_result.first->second = std::forward<M>(m);
//        return emplace_result;
//    }

注释或删除1593-1613行

//    template<typename... Args>
//    std::pair<typename Table::iterator, bool> emplace(Args &&... args)
//    {
//        return Table::emplace(T(std::forward<Args>(args)...));
//    }
//    std::pair<typename Table::iterator, bool> emplace(const key_type & arg)
//    {
//        return Table::emplace(arg);
//    }
//    std::pair<typename Table::iterator, bool> emplace(key_type & arg)
//    {
//        return Table::emplace(arg);
//    }
//    std::pair<typename Table::iterator, bool> emplace(const key_type && arg)
//    {
//        return Table::emplace(std::move(arg));
//    }
//    std::pair<typename Table::iterator, bool> emplace(key_type && arg)
//    {
//        return Table::emplace(std::move(arg));
//    }

3.修改 环境目录下\Lib\site-packages\torch\utils\cpp_extension.py

185行修改成:

match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode("utf8","ignore").strip())

4.修改 环境目录下\Lib\site-packages\torch\include\torch\csrc\jit\argument_spec.h

190行左右修改:

static conststr size_t DEPTH_LIMIT = 128;

替换成 static const size_t DEPTH_LIMIT = 128;

5.修改 环境目录下\Lib\site-packages\torch\include\pybind11\cast.h

1448行左右

explicit operator type&() { return *(this->value); }

替换成 explicit operator type& () { *((type*)(this->value)); }
三.pycocotools安装
https://github.com/philferriere/cocoapi下载源码,并进行解压。以管理员身份打开 CMD 终端,并切换到 cocoapi\PythonAPI目录。运行以下指令:

python setup.py build_ext --inplace
python setup.py build_ext install

三、mmdeteciton安装

1.mmcv安装
利用pip install mmcv==1.1.5

安装完成后,手动去

环境目录下\Lib\site-packages\mmcv\utils找到config.py文件

在100行左右新加:temp_config_file.close()

修改后如下所示:

with tempfile.TemporaryDirectory() as temp_config_dir:
    temp_config_file = tempfile.NamedTemporaryFile(
        dir=temp_config_dir, suffix='.py')
    # 新加的
    temp_config_file.close()
    temp_config_name = osp.basename(temp_config_file.name)
    shutil.copyfile(filename,
                    osp.join(temp_config_dir, temp_config_name))
    temp_module_name = osp.splitext(temp_config_name)[0]
    sys.path.insert(0, temp_config_dir)
    Config._validate_py_syntax(filename)
    mod = import_module(temp_module_name)

2.mmdetection安装:
注意优先安装mmdetection-1.1.0版本,2.1.0版本可能不兼容
2.1 mmdetection-1.1.0版本或其他版本:
官网:https://github.com/open-mmlab/mmdetection/tree/v1.0.0
进入mmdetection-1.1.0

pip install -r requirements.txt

修改setup.py文件中CUDAExtension中extra_compile_args相关代码,增加cxx的"-DMS_WIN64","-MD"

python setup.py develop

2.2 mmdetection-2.1.0版本:
官网下载https://link.zhihu.com/?target=https%3A//github.com/open-mmlab/mmdetection/tree/v2.1.0
执行安装步骤:

pip install -r requirements.txt
python setup.py develop (或者 python setup.py install)

四、安装mmskeleton:

源码地址:https://github.com/open-mmlab/mmskeleton
安装流程:https://github.com/open-mmlab/mmskeleton/blob/master/doc/GETTING_STARTED.md
(之前的配置已安装)

python setup.py develop

windows10下直接安装会报错:
问题一:安装lazy_import出现编码错误
解决办法:https://blog.csdn.net/u014437141/article/details/106161018
官网下载压缩包到某个路径。
解压,打开setup.py
将line5,6修改成如下代码

with open('README.rst', encoding='utf-8') as infile:
    readme = infile.read()

保存。 打开prompt 进入解压路径
执行“python setup.py install”进行安装即可。

问题二: No module named 'mmskeleton.ops.nms.cpu_nms’
解决方法:暴力解决(主要其他方法行不通)
修改mmskeleton.ops.nms下的nms.py文件
注释13,14行,增加cpu_nms函数:

def cpu_nms(dets, thresh):
 
    x1 = dets[:,0]
    y1 = dets[:,1]
    x2 = dets[:,2]
    y2 = dets[:,3]
    areas = (y2-y1+1) * (x2-x1+1)
    scores = dets[:,4]
    keep = []
    index = scores.argsort()[::-1]
    while index.size >0:
        i = index[0]       # every time the first is the biggst, and add it directly
        keep.append(i)
 
 
        x11 = np.maximum(x1[i], x1[index[1:]])    # calculate the points of overlap 
        y11 = np.maximum(y1[i], y1[index[1:]])
        x22 = np.minimum(x2[i], x2[index[1:]])
        y22 = np.minimum(y2[i], y2[index[1:]])
        
 
        w = np.maximum(0, x22-x11+1)    # the weights of overlap
        h = np.maximum(0, y22-y11+1)    # the height of overlap
       
        overlaps = w*h
        ious = overlaps / (areas[i]+areas[index[1:]] - overlaps)
 
        idx = np.where(ious<=thresh)[0]
        index = index[idx+1]   # because index start from 1
 
    return keep

修改后的nms.py文件内容如下:
在这里插入图片描述

安装完成后的配置:
在这里插入图片描述

五、mmskeleton测试:

python mmskl.py pose_demo

六、ST-GCN模型测试及问题:

st-gcn测试数据准备:

python deprecated/tools/data_processing/kinetics_gendata.py --data_path <path to kinetics-skeleton>

st-gcn模型测试:

python mmskl.py configs/recognition/st_gcn_aaai18/kinetics-skeleton/test.yaml

问题一:

D:\Anaconda3\envs\mmd\lib\site-packages\mmcv\utils\registry.py:64: UserWarning: The old API of register_module(module, force=False) is deprecated and will be removed, please use the new API register_module(name=None, force=False, module=None) instead.

解决方法:安装高版本的mmcv,如mmcv==1.1.5
问题二:

TypeError: __init__() got an unexpected keyword argument 'num_stages'

问题原因:mmdet版本不正确,安装mmdet 1.0rcl或其他版本
问题三:

(mmd) E:\mmskeleton-master>python mmskl.py configs/recognition/st_gcn_aaai18/kinetics-skeleton/test.yaml
D:\Anaconda3\envs\mmd\lib\site-packages\Cython\Distutils\old_build_ext.py:41: UserWarning: Cython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "
Load configuration information from configs/recognition/st_gcn_aaai18/kinetics-skeleton/test.yaml
{'type': 'processor.recognition.test', 'checkpoint': 'mmskeleton://st_gcn/kinetics-skeleton', 'model_cfg': {'type': 'models.backbones.ST_GCN_18', 'in_channels': 3, 'num_class': 400, 'edge_importance_weighting': True, 'graph_cfg': {'layout': 'openpose', 'strategy': 'spatial'}}, 'dataset_cfg': {'type': 'deprecated.datasets.skeleton_feeder.SkeletonFeeder', 'data_path': './data/Kinetics/kinetics-skeleton/val_data.npy', 'label_path': './data/Kinetics/kinetics-skeleton/val_label.pkl'}, 'batch_size': 4, 'gpu_batch_size': 4, 'gpus': -1}
[                                                  ] 0/19796, elapsed: 0s, ETA:D:\Anaconda3\envs\mmd\lib\site-packages\Cython\Distutils\old_build_ext.py:41: UserWarning: Cython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "
D:\Anaconda3\envs\mmd\lib\site-packages\Cython\Distutils\old_build_ext.py:41: UserWarning: Cython.Distutils.old_build_ext does not properly handle dependencies and is deprecated.
  "Cython.Distutils.old_build_ext does not properly handle dependencies "
Traceback (most recent call last):
  File "mmskl.py", line 127, in <module>
    main()
  File "mmskl.py", line 121, in main
    call_obj(**cfg.processor_cfg)
  File "E:\mmskeleton-master\mmskeleton\utils\importer.py", line 24, in call_obj
    return import_obj(type)(**kwargs)
  File "E:\mmskeleton-master\mmskeleton\processor\recognition.py", line 45, in test
    for data, label in data_loader:
  File "D:\Anaconda3\envs\mmd\lib\site-packages\torch\utils\data\dataloader.py", line 278, in __iter__
    return _MultiProcessingDataLoaderIter(self)
  File "D:\Anaconda3\envs\mmd\lib\site-packages\torch\utils\data\dataloader.py", line 682, in __init__
    w.start()
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
    reduction.dump(process_obj, to_child)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
OSError: [Errno 22] Invalid argument
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated

解决方法:修改/mmskeleton/processor/recognition.py文件中的test函数,将workers改为0。

def test(model_cfg,
         dataset_cfg,
         checkpoint,
         batch_size=None,
         gpu_batch_size=None,
         gpus=-1,
         workers=0):

七、ST-GCN模型训练:

python mmskl.py configs/recognition/st_gcn_aaai18/kinetics-skeleton/my_train.yaml

问题一:

INFO:mmcv.runner.runner:workflow: [('train', 5), ('val', 1)], max: 50 epochs
Traceback (most recent call last):
  File "mmskl.py", line 142, in <module>
    main()
  File "mmskl.py", line 122, in main
    call_obj(**cfg.processor_cfg)
  File "E:\mmskeleton-master\mmskeleton\utils\importer.py", line 25, in call_obj
    return import_obj(type)(**kwargs)
  File "E:\mmskeleton-master\mmskeleton\processor\recognition.py", line 120, in train
    runner.run(data_loaders, workflow, total_epochs, loss=loss)
  File "D:\Anaconda3\envs\mmd\lib\site-packages\mmcv\runner\runner.py", line 359, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "D:\Anaconda3\envs\mmd\lib\site-packages\mmcv\runner\runner.py", line 259, in train
    for i, data_batch in enumerate(data_loader):
  File "D:\Anaconda3\envs\mmd\lib\site-packages\torch\utils\data\dataloader.py", line 278, in __iter__
    return _MultiProcessingDataLoaderIter(self)
  File "D:\Anaconda3\envs\mmd\lib\site-packages\torch\utils\data\dataloader.py", line 682, in __init__
    w.start()
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
    reduction.dump(process_obj, to_child)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
OSError: [Errno 22] Invalid argument
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "D:\Anaconda3\envs\mmd\lib\multiprocessing\spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
_pickle.UnpicklingError: pickle data was truncated

解决方法:修改/mmskeleton/processor/recognition.py文件中的train函数,将workers改为0
问题二:

OSError: symbolic link privilege not held

解决方法:以管理员方式打开prompt(windows菜单栏右键搜索,搜索cmd,右键选择以管理员方式运行)
问题三:

TypeError: logger must be a logging.Logger object, but got <class 'int'>

解决方法:pip install mmcv==0.4.0

问题四:

Cannot find installation of real FFmpeg (which comes with ffprobe)

解决方法:conda install ffmpeg -c conda-forge
问题五:
loss不下降
解决办法:增加红色框里面缺少的内容
在这里插入图片描述

  • 5
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 47
    评论
对于使用COCO数据集训练ST-GCN(Spatio-Temporal Graph Convolutional Networks)模型,你需要完成以下步骤: 1. 数据准备:从COCO数据集中提取出包含人体姿势信息的图像。COCO数据集提供了标注了人体关键点的图像,你可以使用这些关键点来表示人体姿势。 2. 数据预处理:对于每个图像,你需要将关键点坐标转换为关节点的三维坐标表示。这可以通过将每个关节点的二维坐标映射到图像平面上来实现。 3. 构建图形:使用关节点的三维坐标来构建图形结构。ST-GCN使用图形结构来建模人体姿势的时空关系。你可以根据关节点之间的距离或连接关系来构建图形。 4. 特征提取:基于构建的图形结构,你可以使用ST-GCN模型提取人体姿势的时空特征。ST-GCN模型采用了时空图卷积操作,可以有效地捕捉动作序列中的时空信息。 5. 训练模型:使用预处理的数据和特征提取的结果,你可以将ST-GCN模型进行训练训练过程中,你可以使用COCO数据集中提供的标注信息来监督模型的学习。 6. 模型评估:训练完成后,你可以使用测试集数据对训练好的ST-GCN模型进行评估。评估指标可以包括准确率、召回率等。 请注意,以上步骤仅为一般步骤,具体实现可能因应用场景和需求而有所不同。此外,ST-GCN模型的训练可能需要较大的计算资源和时间,因此你可能需要考虑使用GPU加速和分布式训练等技术来加快训练过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 47
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值