forked from longcw/MOTDT
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2026e71
Showing
50 changed files
with
3,223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### Python template | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
.static_storage/ | ||
.media/ | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
*.o | ||
data | ||
.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# -------------------------------------------------------- | ||
# Fast R-CNN | ||
# Copyright (c) 2015 Microsoft | ||
# Licensed under The MIT License [see LICENSE for details] | ||
# Written by Ross Girshick | ||
# -------------------------------------------------------- | ||
|
||
import os | ||
from os.path import join as pjoin | ||
import numpy as np | ||
from distutils.core import setup | ||
from distutils.extension import Extension | ||
from Cython.Distutils import build_ext | ||
|
||
|
||
def find_in_path(name, path): | ||
"Find a file in a search path" | ||
# adapted fom http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/ | ||
for dir in path.split(os.pathsep): | ||
binpath = pjoin(dir, name) | ||
if os.path.exists(binpath): | ||
return os.path.abspath(binpath) | ||
return None | ||
|
||
|
||
def locate_cuda(): | ||
"""Locate the CUDA environment on the system | ||
Returns a dict with keys 'home', 'nvcc', 'include', and 'lib64' | ||
and values giving the absolute path to each directory. | ||
Starts by looking for the CUDAHOME env variable. If not found, everything | ||
is based on finding 'nvcc' in the PATH. | ||
""" | ||
|
||
# first check if the CUDAHOME env variable is in use | ||
if 'CUDAHOME' in os.environ: | ||
home = os.environ['CUDAHOME'] | ||
nvcc = pjoin(home, 'bin', 'nvcc') | ||
else: | ||
# otherwise, search the PATH for NVCC | ||
default_path = pjoin(os.sep, 'usr', 'local', 'cuda', 'bin') | ||
nvcc = find_in_path('nvcc', os.environ['PATH'] + os.pathsep + default_path) | ||
if nvcc is None: | ||
raise EnvironmentError('The nvcc binary could not be ' | ||
'located in your $PATH. Either add it to your path, or set $CUDAHOME') | ||
home = os.path.dirname(os.path.dirname(nvcc)) | ||
|
||
cudaconfig = {'home': home, 'nvcc': nvcc, | ||
'include': pjoin(home, 'include'), | ||
'lib64': pjoin(home, 'lib64')} | ||
for k, v in cudaconfig.items(): | ||
if not os.path.exists(v): | ||
raise EnvironmentError('The CUDA %s path could not be located in %s' % (k, v)) | ||
|
||
return cudaconfig | ||
|
||
|
||
CUDA = locate_cuda() | ||
|
||
# Obtain the numpy include directory. This logic works across numpy versions. | ||
try: | ||
numpy_include = np.get_include() | ||
except AttributeError: | ||
numpy_include = np.get_numpy_include() | ||
|
||
|
||
def customize_compiler_for_nvcc(self): | ||
"""inject deep into distutils to customize how the dispatch | ||
to gcc/nvcc works. | ||
If you subclass UnixCCompiler, it's not trivial to get your subclass | ||
injected in, and still have the right customizations (i.e. | ||
distutils.sysconfig.customize_compiler) run on it. So instead of going | ||
the OO route, I have this. Note, it's kindof like a wierd functional | ||
subclassing going on.""" | ||
|
||
# tell the compiler it can processes .cu | ||
self.src_extensions.append('.cu') | ||
|
||
# save references to the default compiler_so and _comple methods | ||
default_compiler_so = self.compiler_so | ||
super = self._compile | ||
|
||
# now redefine the _compile method. This gets executed for each | ||
# object but distutils doesn't have the ability to change compilers | ||
# based on source extension: we add it. | ||
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts): | ||
print(extra_postargs) | ||
if os.path.splitext(src)[1] == '.cu': | ||
# use the cuda for .cu files | ||
self.set_executable('compiler_so', CUDA['nvcc']) | ||
# use only a subset of the extra_postargs, which are 1-1 translated | ||
# from the extra_compile_args in the Extension class | ||
postargs = extra_postargs['nvcc'] | ||
else: | ||
postargs = extra_postargs['gcc'] | ||
|
||
super(obj, src, ext, cc_args, postargs, pp_opts) | ||
# reset the default compiler_so, which we might have changed for cuda | ||
self.compiler_so = default_compiler_so | ||
|
||
# inject our redefined _compile method into the class | ||
self._compile = _compile | ||
|
||
|
||
# run the customize_compiler | ||
class custom_build_ext(build_ext): | ||
def build_extensions(self): | ||
customize_compiler_for_nvcc(self.compiler) | ||
build_ext.build_extensions(self) | ||
|
||
|
||
thisdir = os.path.dirname(os.path.abspath(__file__)) | ||
source_dir = os.path.join(thisdir, 'utils') | ||
ext_modules = [ | ||
Extension( | ||
"utils.cython_bbox", | ||
[os.path.join(source_dir, "bbox.pyx")], | ||
extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]}, | ||
include_dirs=[numpy_include] | ||
), | ||
|
||
Extension( | ||
"utils.nms.cpu_nms", | ||
[os.path.join(source_dir, "nms", 'cpu_nms.pyx')], | ||
extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]}, | ||
include_dirs=[numpy_include] | ||
), | ||
Extension('utils.nms.gpu_nms', | ||
[os.path.join(source_dir, "nms", 'gpu_nms.pyx'), os.path.join(source_dir, "nms", 'nms_kernel.cu')], | ||
library_dirs=[CUDA['lib64']], | ||
libraries=['cudart'], | ||
language='c++', | ||
runtime_library_dirs=[CUDA['lib64']], | ||
# this syntax is specific to this build system | ||
# we're only going to use certain compiler args with nvcc and not with gcc | ||
# the implementation of this trick is in customize_compiler() below | ||
extra_compile_args={'gcc': ["-Wno-unused-function"], | ||
'nvcc': ['-arch=sm_35', | ||
'--ptxas-options=-v', | ||
'-c', | ||
'--compiler-options', | ||
"'-fPIC'"]}, | ||
include_dirs=[numpy_include, CUDA['include']] | ||
), | ||
] | ||
|
||
|
||
if __name__ == '__main__': | ||
setup( | ||
name='utils', | ||
ext_modules=ext_modules, | ||
# inject our custom trigger | ||
cmdclass={'build_ext': custom_build_ext}, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import numpy as np | ||
import os | ||
import torch.utils.data as data | ||
from scipy.misc import imread | ||
|
||
|
||
""" | ||
labels={'ped', ... % 1 | ||
'person_on_vhcl', ... % 2 | ||
'car', ... % 3 | ||
'bicycle', ... % 4 | ||
'mbike', ... % 5 | ||
'non_mot_vhcl', ... % 6 | ||
'static_person', ... % 7 | ||
'distractor', ... % 8 | ||
'occluder', ... % 9 | ||
'occluder_on_grnd', ... %10 | ||
'occluder_full', ... % 11 | ||
'reflection', ... % 12 | ||
'crowd' ... % 13 | ||
}; | ||
""" | ||
|
||
|
||
def read_mot_results(filename, is_gt=False): | ||
labels = {1, 7, -1} | ||
targets = dict() | ||
if os.path.isfile(filename): | ||
with open(filename, 'r') as f: | ||
for line in f.readlines(): | ||
linelist = line.split(',') | ||
if len(linelist) < 7: | ||
continue | ||
fid = int(linelist[0]) | ||
targets.setdefault(fid, list()) | ||
|
||
if is_gt and ('MOT16-' in filename or 'MOT17-' in filename): | ||
label = int(float(linelist[-2])) if len(linelist) > 7 else -1 | ||
if label not in labels: | ||
continue | ||
tlwh = tuple(map(float, linelist[2:7])) | ||
target_id = int(linelist[1]) | ||
|
||
targets[fid].append((tlwh, target_id)) | ||
|
||
return targets | ||
|
||
|
||
class MOTSeq(data.Dataset): | ||
def __init__(self, root, det_root, seq_name, min_height, min_det_score): | ||
self.root = root | ||
self.seq_name = seq_name | ||
self.min_height = min_height | ||
self.min_det_score = min_det_score | ||
|
||
self.im_root = os.path.join(self.root, self.seq_name, 'img1') | ||
self.im_names = sorted([name for name in os.listdir(self.im_root) if os.path.splitext(name)[-1] == '.jpg']) | ||
|
||
if det_root is None: | ||
self.det_file = os.path.join(self.root, self.seq_name, 'det', 'det.txt') | ||
else: | ||
self.det_file = os.path.join(det_root, '{}.txt'.format(self.seq_name)) | ||
self.dets = read_mot_results(self.det_file, is_gt=False) | ||
|
||
self.gt_file = os.path.join(self.root, self.seq_name, 'gt', 'gt.txt') | ||
if os.path.isfile(self.gt_file): | ||
self.gts = read_mot_results(self.gt_file, is_gt=True) | ||
else: | ||
self.gts = None | ||
|
||
def __len__(self): | ||
return len(self.im_names) | ||
|
||
def __getitem__(self, i): | ||
im_name = os.path.join(self.im_root, self.im_names[i]) | ||
# im = cv2.imread(im_name) | ||
im = imread(im_name) # rgb | ||
im = im[:, :, ::-1] # bgr | ||
|
||
|
||
frame = i + 1 | ||
dets = self.dets.get(frame, []) | ||
dets, track_ids = zip(*self.dets[frame]) if len(dets) > 0 else (np.empty([0, 5]), np.empty([0, 1])) | ||
dets = np.asarray(dets) | ||
tlwhs = dets[:, 0:4] | ||
scores = dets[:, 4] | ||
|
||
keep = (tlwhs[:, 3] >= self.min_height) & (scores > self.min_det_score) | ||
tlwhs = tlwhs[keep] | ||
scores = scores[keep] | ||
track_ids = np.asarray(track_ids, dtype=np.int)[keep] | ||
|
||
if self.gts is not None: | ||
gts = self.gts.get(frame, []) | ||
gt_tlwhs, gt_ids = zip(*self.gts[frame]) if len(gts) > 0 else (np.empty([0, 5]), np.empty([0, 1])) | ||
gt_tlwhs = np.asarray(gt_tlwhs) | ||
gt_tlwhs = gt_tlwhs[:, 0:4] | ||
else: | ||
gt_tlwhs, gt_ids = None, None | ||
|
||
return im, tlwhs, scores, gt_tlwhs, gt_ids | ||
|
||
|
||
def collate_fn(data): | ||
return data[0] | ||
|
||
|
||
def get_loader(root, det_root, name, min_height=0, min_det_score=-np.inf, num_workers=3): | ||
dataset = MOTSeq(root, det_root, name, min_height, min_det_score) | ||
|
||
data_loader = data.DataLoader(dataset, 1, False, num_workers=num_workers, collate_fn=collate_fn) | ||
|
||
return data_loader |
Oops, something went wrong.