Skip to content

Commit

Permalink
feat(setup): add pip package code (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
FateScript authored Jan 18, 2022
1 parent 25f116b commit ca9bc37
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 25 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ This repo is an implementation of PyTorch version YOLOX, there is also a [MegEng
<details>
<summary>Installation</summary>

Step1. Install YOLOX.
Step1. Install YOLOX from source.
```shell
git clone [email protected]:Megvii-BaseDetection/YOLOX.git
cd YOLOX
pip3 install -U pip && pip3 install -r requirements.txt
pip3 install -v -e . # or python3 setup.py develop
```

Step2. Install [pycocotools](https://github.com/cocodataset/cocoapi).

```shell
pip3 install cython; pip3 install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
```

</details>

<details>
Expand Down
3 changes: 3 additions & 0 deletions exps/default/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ tabulate
tensorboard

# verified versions
# pycocotools corresponds to https://github.com/ppwwyyxx/cocoapi
pycocotools>=2.0.2
onnx==1.8.1
onnxruntime==1.8.0
onnx-simplifier==0.3.5
onnx-simplifier==0.3.5
56 changes: 42 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import torch
from torch.utils.cpp_extension import CppExtension

torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
assert torch_ver >= [1, 7], "Requires PyTorch >= 1.7"


def get_extensions():
this_dir = path.dirname(path.abspath(__file__))
Expand Down Expand Up @@ -40,25 +37,56 @@ def get_extensions():
return ext_modules


with open("yolox/__init__.py", "r") as f:
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
f.read(), re.MULTILINE
).group(1)
def get_package_dir():
pkg_dir = {
"yolox.tools": "tools",
"yolox.exp.default": "exps/default",
}
return pkg_dir


def get_install_requirements():
with open("requirements.txt", "r", encoding="utf-8") as f:
reqs = [x.strip() for x in f.read().splitlines()]
reqs = [x for x in reqs if not x.startswith("#")]
return reqs


def get_yolox_version():
with open("yolox/__init__.py", "r") as f:
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
f.read(), re.MULTILINE
).group(1)
return version


with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
def get_long_description():
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
return long_description


setuptools.setup(
name="yolox",
version=version,
author="basedet team",
version=get_yolox_version(),
author="megvii basedet team",
url="https://github.com/Megvii-BaseDetection/YOLOX",
package_dir=get_package_dir(),
python_requires=">=3.6",
long_description=long_description,
install_requires=get_install_requirements(),
long_description=get_long_description(),
long_description_content_type="text/markdown",
ext_modules=get_extensions(),
classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
classifiers=[
"Programming Language :: Python :: 3", "Operating System :: OS Independent",
"License :: OSI Approved :: Apache Software License",
],
cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
packages=setuptools.find_packages(),
project_urls={
"Documentation": "https://yolox.readthedocs.io",
"Source": "https://github.com/Megvii-BaseDetection/YOLOX",
"Tracker": "https://github.com/Megvii-BaseDetection/YOLOX/issues",
},
)
3 changes: 3 additions & 0 deletions tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates.
2 changes: 1 addition & 1 deletion yolox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

configure_module()

__version__ = "0.1.0"
__version__ = "0.2.0"
4 changes: 3 additions & 1 deletion yolox/utils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ def get_local_rank() -> int:
Returns:
The rank of the current process within the local (per-machine) process group.
"""
if _LOCAL_PROCESS_GROUP is None:
return get_rank()

if not dist.is_available():
return 0
if not dist.is_initialized():
return 0
assert _LOCAL_PROCESS_GROUP is not None
return dist.get_rank(group=_LOCAL_PROCESS_GROUP)


Expand Down

0 comments on commit ca9bc37

Please sign in to comment.