代码拉取完成,页面将自动刷新
同步操作将从 lrwin/YOLOX_OBB 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
# Copyright (c) Megvii, Inc. and its affiliates. All Rights Reserved
import re
import setuptools
import glob
import os
from os import path
import torch
from torch.utils.cpp_extension import (CppExtension, CUDAExtension)
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__))
extensions_dir = path.join(this_dir, "yolox", "layers", "csrc")
main_source = path.join(extensions_dir, "vision.cpp")
sources = glob.glob(path.join(extensions_dir, "**", "*.cpp"))
sources = [main_source] + sources
extension = CppExtension
extra_compile_args = {"cxx": ["-O3"]}
define_macros = []
include_dirs = [extensions_dir]
ext_modules = [
extension(
"yolox._C",
sources,
include_dirs=include_dirs,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
),
make_cuda_ext(
name = 'box_iou_rotated_ext',
module = 'yolox.ops.pytorch.box_iou_rotated',
sources = [
'src/box_iou_rotated_cpu.cpp',
'src/box_iou_rotated_ext.cpp'
],
sources_cuda = ['src/box_iou_rotated_cuda.cu']
),
make_cuda_ext(
name = 'convex_ext',
module = 'yolox.ops.pytorch.convex',
sources = [
'src/convex_cpu.cpp',
'src/convex_ext.cpp'
],
sources_cuda = ['src/convex_cuda.cu']
),
make_cuda_ext(
name = 'nms_rotated_ext',
module = 'yolox.ops.pytorch.nms_rotated',
sources = [
'src/nms_rotated_cpu.cpp',
'src/nms_rotated_ext.cpp',
],
sources_cuda = [
'src/nms_rotated_cuda.cu',
'src/poly_nms_cuda.cu']
),
make_onnxruntime_ext(
name="ort_ext",
module="yolox.ops.onnxruntime",
with_cuda=False
)
]
return ext_modules
def make_cuda_ext(name, module, sources, sources_cuda=[], with_cuda=True):
define_macros = []
extra_compile_args = {'cxx': ["-O2", "-std=c++14", "-Wall"]}
if torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1' and with_cuda:
define_macros += [('WITH_CUDA', None)] # 宏定义的声明,#define WITH_CUDA None
extension = CUDAExtension
extra_compile_args['nvcc'] = [
'-O2',
'-D__CUDA_NO_HALF_OPERATORS__',
'-D__CUDA_NO_HALF_CONVERSIONS__',
'-D__CUDA_NO_HALF2_OPERATORS__',
]
sources += sources_cuda
else:
print(f"Compiling {name} without CUAD")
extension = CppExtension
return extension(
name=f"{module}.{name}",
sources=[os.path.join(*module.split('.'), p) for p in sources],
define_macros=define_macros,
extra_compilr_args=extra_compile_args
)
def make_onnxruntime_ext(name, module, with_cuda=True):
source_type = ("cpp", "c", "cc")
include_type = ("hpp", "h", "cuh")
source_files = []
include_dirs = []
define_macros = []
module_path = os.path.join(*module.split("."))
extra_compile_args = {'cxx': ["-O2", "-std=c++14", "-Wall"]}
for t in source_type:
for p in glob.glob(module_path + "/**/*." + t, recursive=True):
source_files.append(p)
for t in include_type:
for p in glob.glob(module_path + "/**/*." + t, recursive=True):
include_dirs.append(os.path.abspath(os.path.dirname(p)))
include_dirs = list(set(include_dirs))
if (torch.cuda.is_available() or os.getenv('FORCE_CUDA', '0') == '1') and with_cuda:
define_macros += [('WITH_CUDA', None)] # 宏定义的声明,#define WITH_CUDA None
raise NotImplementedError
else:
ort_path = os.path.abspath(os.getenv("ONNXRUNTIME_DIR", "0"))
libraries = ["onnxruntime"]
library_dirs = [os.path.join(ort_path, "lib")]
include_dirs.append(os.path.join(ort_path, "include"))
extension = CppExtension
return extension(
name=f"{module}.{name}",
sources=source_files,
define_macros=define_macros,
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,
libraries=libraries,
library_dirs=library_dirs)
with open("yolox/__init__.py", "r") as f:
version = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
f.read(), re.MULTILINE
).group(1)
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
setuptools.setup(
name="yolox",
version=version,
author="basedet team",
python_requires=">=3.6",
long_description=long_description,
ext_modules=get_extensions(),
classifiers=["Programming Language :: Python :: 3", "Operating System :: OS Independent"],
cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
packages=setuptools.find_packages(),
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。