windows下安装cocoApi和CrowdPoseApi

2021/6/17 7:27:58

本文主要是介绍windows下安装cocoApi和CrowdPoseApi,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1. 安装COCOAPI

1.首先git clone下载:
使用国内镜像会更快些:

git clone https://github.com.cnpmjs.org/cocodataset/cocoapi.git 

2.然后cd cocoapi/PythonAPI/

3.修改setup.py文件,将extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'] 替换为extra_compile_args=[]
如下:

from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
import numpy as np

# To install and compile to your anaconda/python site-packages, simply run:
# $ pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
# Note that the original compile flags below are GCC flags unsupported by the Visual C++ 2015 build tools.
# They can safely be removed.

ext_modules = [
    Extension(
        'pycocotools._mask',
        sources=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
        include_dirs = [np.get_include(), '../common'],
        extra_compile_args=[] # originally was ['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
    )
]

setup(name='pycocotools',
      packages=['pycocotools'],
      package_dir = {'pycocotools': 'pycocotools'},
      version='2.0',
      ext_modules=
          cythonize(ext_modules)
      )

4.运行文件

python setup.py build_ext --inplace

python setup.py build_ext install

5.若出现报错:

TypeError: 'numpy.float64' object cannot be interpreted as an integer

解决方案:
修改文件:cocoapi/PythonAPI/pycocotools/cocoeval.py,如下:

class Params:
    '''
    Params for coco evaluation api
    '''
    def setDetParams(self):
        self.imgIds = []
        self.catIds = []
        # np.arange causes trouble.  the data point on arange is slightly larger than the true value
        # @Author pei @Data:2020.12.18 @Content: TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.
        self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
        #self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
        self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
        self.maxDets = [1, 10, 100]
        self.areaRng = [[0 ** 2, 1e5 ** 2], [0 ** 2, 32 ** 2], [32 ** 2, 96 ** 2], [96 ** 2, 1e5 ** 2]]
        self.areaRngLbl = ['all', 'small', 'medium', 'large']
        self.useCats = 1

    def setKpParams(self):
        self.imgIds = []
        self.catIds = []
        # @Author pei @Data:2020.12.18 @Content: TypeError: 'numpy.float64' object cannot be interpreted as an integer
        self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
        self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
        self.maxDets = [20]
        self.areaRng = [[0 ** 2, 1e5 ** 2], [32 ** 2, 96 ** 2], [96 ** 2, 1e5 ** 2]]
        self.areaRngLbl = ['all', 'medium', 'large']
        self.useCats = 1

    def __init__(self, iouType='segm'):
        if iouType == 'segm' or iouType == 'bbox':
            self.setDetParams()
        elif iouType == 'keypoints':
            self.setKpParams()
        else:
            raise Exception('iouType not supported')
        self.iouType = iouType
        # useSegm is deprecated
        self.useSegm = None

然后重新安装cocoApi

2. 安装CrowdposeAPI

1.首先git clone下载:
使用国内镜像会更快些:

git clone https://github.com.cnpmjs.org/Jeff-sjtu/CrowdPose.git 

2.然后cd CrowdPose/crowdpose-api/PythonAPI/

3.修改setup.py文件,将extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'] 替换为extra_compile_args=['-std=c99'],如下:

from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
import numpy as np

# To compile and install locally run "python setup.py build_ext --inplace"
# To install library to Python site-packages run "python setup.py build_ext install"

ext_modules = [
    Extension(
        'crowdposetools._mask',
        sources=['../common/maskApi.c', 'crowdposetools/_mask.pyx'],
        include_dirs=[np.get_include(), '../common'],
        # @Pei Hongwei
        # @2020.11.16 
        # originally was extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
        extra_compile_args=['-std=c99']
    )
]

setup(name='crowdposetools',
      packages=['crowdposetools'],
      package_dir={'crowdposetools': 'crowdposetools'},
      version='2.0',
      ext_modules=cythonize(ext_modules)
      )

4.运行文件

python setup.py build_ext --inplace

python setup.py build_ext install



这篇关于windows下安装cocoApi和CrowdPoseApi的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程