Skip to content

Commit

Permalink
clean third-party dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
yysijie committed Jan 21, 2020
1 parent 5b60846 commit 883a927
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 23 deletions.
11 changes: 7 additions & 4 deletions doc/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ git clone https://github.com/open-mmlab/mmskeleton.git
cd mmskeleton
```

**Install** the mmskeleton:
**Install** mmskeleton:

``` shell
python setup.py develop
```

Sometimes `mmdet` may be not installed successfully. In that case, please install [mmdet](https://github.com/open-mmlab/mmdetection/blob/master/docs/INSTALL.md) manually.
Then run above command again.
[Option] **Install** mmdetection for person detection:
``` shell
python setup.py develop --mmdet
```
Sometimes `mmdetection` can not be installed successfully. In that case, please install [mmdet](https://github.com/open-mmlab/mmdetection/blob/master/docs/INSTALL.md) manually.

To **verify** that mmskeleton installed correctly, use:
To **verify** that mmskeleton and mmdetection installed correctly, use:
```shell
python mmskl.py pose_demo [--gpus $GPUS]
# or "python mmskl.py pose_demo_HD [--gpus $GPUS]" for a higher accuracy
Expand Down
1 change: 1 addition & 0 deletions mmskeleton/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import utils
from . import datasets, processor, models, ops, apis
from .datasets.skeleton import skeleton_process
10 changes: 5 additions & 5 deletions mmskeleton/apis/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np
import torch
import mmcv
import mmdet
from mmskeleton.datasets.utils.video_demo import VideoDemo
from mmskeleton.utils import get_mmskeleton_url
from mmdet.apis import init_detector, inference_detector
from mmskeleton.processor.apis import init_twodimestimator, inference_twodimestimator


Expand All @@ -13,9 +13,9 @@ def init_pose_estimator(detection_cfg, estimation_cfg, device=None):
detection_model_file = detection_cfg.model_cfg
detection_checkpoint_file = get_mmskeleton_url(
detection_cfg.checkpoint_file)
detection_model = init_detector(detection_model_file,
detection_checkpoint_file,
device='cpu')
detection_model = mmdet.apis.init_detector(detection_model_file,
detection_checkpoint_file,
device='cpu')

skeleton_model_file = estimation_cfg.model_cfg
skeletion_checkpoint_file = estimation_cfg.checkpoint_file
Expand All @@ -35,7 +35,7 @@ def init_pose_estimator(detection_cfg, estimation_cfg, device=None):

def inference_pose_estimator(pose_estimator, image):
detection_model, skeleton_model, detection_cfg, estimation_cfg = pose_estimator
bbox_result = inference_detector(detection_model, image)
bbox_result = mmdet.apis.inference_detector(detection_model, image)
person_bbox, labels = VideoDemo.bbox_filter(bbox_result,
detection_cfg.bbox_thre)
if len(person_bbox) > 0:
Expand Down
7 changes: 1 addition & 6 deletions mmskeleton/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
from collections import OrderedDict
import logging
import os

import lazy_import
COCO = lazy_import.lazy_module("pycocotools.coco")
COCOeval = lazy_import.lazy_module("pycocotools.cocoeval")
import json
import numpy as np

from .estimation import EstiamtionDataset
# oks_nms = lazy_import.lazy_module("mmskeleton.ops.nms.nms.oks_nms")
# soft_oks_nms = lazy_import.lazy_module("mmskeleton.ops.nms.nms.soft_oks_nms")
from ..ops.nms.nms import oks_nms
from ..ops.nms.nms import soft_oks_nms
from pycocotools import COCO, COCOeval

logger = logging.getLogger(__name__)

Expand Down
1 change: 0 additions & 1 deletion mmskeleton/processor/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from mmskeleton.datasets.utils.coco_transform import flip_back
from mmskeleton.datasets.utils.video_demo import VideoDemo
from mmskeleton.utils import get_mmskeleton_url
from mmdet.apis import init_detector, inference_detector

flip_pairs = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14],
[15, 16]]
Expand Down
8 changes: 7 additions & 1 deletion mmskeleton/processor/pose_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from mmskeleton.apis.estimation import init_pose_estimator, inference_pose_estimator
from multiprocessing import current_process, Process, Manager
from mmskeleton.utils import cache_checkpoint
from mmskeleton.utils import cache_checkpoint, third_party
from mmcv.utils import ProgressBar


Expand Down Expand Up @@ -62,6 +62,12 @@ def inference(detection_cfg,
worker_per_gpu=1,
save_dir=None):

if not third_party.is_exist('mmdet'):
print(
'\nERROR: This demo requires mmdet for detecting bounding boxes of person. Please install mmdet first.'
)
exit(1)

video_frames = mmcv.VideoReader(video_file)
all_result = []
print('\nPose estimation:')
Expand Down
12 changes: 10 additions & 2 deletions mmskeleton/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from . import third_party
from .importer import import_obj, call_obj, set_attr, get_attr
from .checkpoint import load_checkpoint, get_mmskeleton_url, cache_checkpoint
from .config import Config

__all__ = [
'import_obj', 'call_obj', 'set_attr', 'get_attr', 'load_checkpoint',
'get_mmskeleton_url', 'cache_checkpoint', 'Config'
'import_obj',
'call_obj',
'set_attr',
'get_attr',
'load_checkpoint',
'get_mmskeleton_url',
'cache_checkpoint',
'Config',
'third_party',
]
15 changes: 15 additions & 0 deletions mmskeleton/utils/third_party.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lazy_import

pycocotools = lazy_import.lazy_module("pycocotools")
COCO = lazy_import.lazy_module("pycocotools.COCO")
COCOeval = lazy_import.lazy_module("pycocotools.COCOeval")
mmdet = lazy_import.lazy_module("mmdet")


def is_exist(module_name):
module = __import__(module_name)
try:
lazy_import._load_module(module)
return True
except ImportError:
return False
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pillow
mmcv
torch>=1.1
torchvision
lazy_import
14 changes: 11 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def make_cuda_ext(name, module, sources, include_dirs=[]):


if __name__ == '__main__':

install_requires = get_requirements()
if "--mmdet" in sys.argv:
sys.argv.remove("--mmdet")
install_requires += ['mmdet']

write_version_py()
setup(
name='mmskeleton',
Expand All @@ -164,9 +170,9 @@ def make_cuda_ext(name, module, sources, include_dirs=[]):
setup_requires=['pytest-runner'],
tests_require=['pytest'],
dependency_links=[
'git+https://github.com/open-mmlab/mmdetection/tarball/master/#egg=mmdet'
'https://github.com/open-mmlab/mmdetection/tarball/master/#egg=mmdet'
],
install_requires=get_requirements() + ['mmdet'],
install_requires=install_requires,
ext_modules=[
make_cython_ext(name='cpu_nms',
module='mmskeleton.ops.nms',
Expand All @@ -176,5 +182,7 @@ def make_cuda_ext(name, module, sources, include_dirs=[]):
sources=['nms_kernel.cu', 'gpu_nms.pyx'],
include_dirs=[np.get_include()]),
],
cmdclass={'build_ext': BuildExtension},
cmdclass={
'build_ext': BuildExtension,
},
zip_safe=False)

0 comments on commit 883a927

Please sign in to comment.