Skip to content

Commit

Permalink
implementation without docs and tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglianghua committed Nov 30, 2018
0 parents commit ccdb20a
Show file tree
Hide file tree
Showing 28 changed files with 2,350 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.*
*.pyc
__pycache__/
data
data/
cache/
results/
reports/
venv/
!.gitignore
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added README.md
Empty file.
Empty file added examples/quick_examples.ipynb
Empty file.
Empty file added examples/quick_examples.py
Empty file.
Empty file added got10k/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions got10k/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import absolute_import

from .got10k import GOT10k
from .otb import OTB
from .vot import VOT
from .vid import ImageNetVID
108 changes: 108 additions & 0 deletions got10k/datasets/got10k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from __future__ import absolute_import, print_function

import os
import glob
import numpy as np
import six


class GOT10k(object):
r"""`GOT-10K <https://got-10k.github.io/>`_ Dataset.
Publication:
``GOT-10k: A Large High-Diversity Benchmark for Generic Object
Tracking in the Wild``, L. Huang, X. Zhao and K. Huang, ArXiv 2018.
Args:
root_dir (string): Root directory of dataset where ``train``,
``val`` and ``test`` folders exist.
subset (string, optional): Specify ``train``, ``val`` or ``test``
subset of GOT-10k.
return_meta (string, optional): If True, returns ``meta``
of each sequence in ``__getitem__`` function, otherwise
only returns ``img_files`` and ``anno``.
"""

def __init__(self, root_dir, subset='test', return_meta=False):
super(GOT10k, self).__init__()
assert subset in ['train', 'val', 'test'], 'Unknown subset.'

self.root_dir = root_dir
self.subset = subset
self.return_meta = False if subset == 'test' else return_meta
self._check_integrity(root_dir, subset)

list_file = os.path.join(root_dir, subset, 'list.txt')
with open(list_file, 'r') as f:
self.seq_names = f.read().strip().split('\n')
self.seq_dirs = [os.path.join(root_dir, subset, s)
for s in self.seq_names]
self.anno_files = [os.path.join(d, 'groundtruth.txt')
for d in self.seq_dirs]

def __getitem__(self, index):
r"""
Args:
index (integer or string): Index or name of a sequence.
Returns:
tuple: (img_files, anno) if ``return_meta`` is False, otherwise
(img_files, anno, meta), where ``img_files`` is a list of
file names, ``anno`` is a N x 4 (rectangles) numpy array, while
``meta`` is a dict contains meta information about the sequence.
"""
if isinstance(index, six.string_types):
if not index in self.seq_names:
raise Exception('Sequence {} not found.'.format(index))
index = self.seq_names.index(index)

img_files = sorted(glob.glob(os.path.join(
self.seq_dirs[index], '*.jpg')))
anno = np.loadtxt(self.anno_files[index], delimiter=',')

if self.subset == 'test':
assert anno.ndim == 1
anno = anno[np.newaxis, :]
else:
assert len(img_files) == len(anno)

if self.return_meta:
meta = self._fetch_meta(self.seq_dirs[index])
return img_files, anno, meta
else:
return img_files, anno

def __len__(self):
return len(self.seq_names)

def _check_integrity(self, root_dir, subset):
assert subset in ['train', 'val', 'test']
list_file = os.path.join(root_dir, subset, 'list.txt')

if os.path.isfile(list_file):
with open(list_file, 'r') as f:
seq_names = f.read().strip().split('\n')

# check each sequence folder
for seq_name in seq_names:
seq_dir = os.path.join(root_dir, subset, seq_name)
if not os.path.isdir(seq_dir):
print('Warning: sequence %s not exist.' % seq_name)
else:
# dataset not exist
raise Exception('Dataset not found or corrupted.')

def _fetch_meta(self, seq_dir):
# meta information
meta_file = os.path.join(seq_dir, 'meta_info.ini')
with open(meta_file) as f:
meta = f.read().strip().split('\n')[1:]
meta = [line.split(': ') for line in meta]
meta = {line[0]: line[1] for line in meta}

# attributes
attributes = ['cover', 'absence', 'cut_by_image']
for att in attributes:
meta[att] = np.loadtxt(os.path.join(seq_dir, att + '.label'))

return meta
197 changes: 197 additions & 0 deletions got10k/datasets/otb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
from __future__ import absolute_import, print_function

import os
import glob
import numpy as np
import io
import six
from itertools import chain

from ..utils.ioutils import download, extract


class OTB(object):
r"""`OTB <http://cvlab.hanyang.ac.kr/tracker_benchmark/>`_ Datasets.
Publication:
``Object Tracking Benchmark``, Y. Wu, J. Lim and M.-H. Yang, IEEE TPAMI 2015.
Args:
root_dir (string): Root directory of dataset where sequence
folders exist.
version (integer or string): Specify the benchmark version, specify as one of
``2013``, ``2015``, ``tb50`` and ``tb100``.
download (boolean, optional): If True, downloads the dataset from the internet
and puts it in root directory. If dataset is downloaded, it is not
downloaded again.
"""

__otb13_seqs = ['Basketball', 'Bolt', 'Boy', 'Car4', 'CarDark',
'CarScale', 'Coke', 'Couple', 'Crossing', 'David',
'David2', 'David3', 'Deer', 'Dog1', 'Doll', 'Dudek',
'FaceOcc1', 'FaceOcc2', 'Fish', 'FleetFace',
'Football', 'Football1', 'Freeman1', 'Freeman3',
'Freeman4', 'Girl', 'Ironman', 'Jogging', 'Jumping',
'Lemming', 'Liquor', 'Matrix', 'Mhyang', 'MotorRolling',
'MountainBike', 'Shaking', 'Singer1', 'Singer2',
'Skating1', 'Skiing', 'Soccer', 'Subway', 'Suv',
'Sylvester', 'Tiger1', 'Tiger2', 'Trellis', 'Walking',
'Walking2', 'Woman']

__tb50_seqs = ['Basketball', 'Biker', 'Bird1', 'BlurBody', 'BlurCar2',
'BlurFace', 'BlurOwl', 'Bolt', 'Box', 'Car1', 'Car4',
'CarDark', 'CarScale', 'ClifBar', 'Couple', 'Crowds',
'David', 'Deer', 'Diving', 'DragonBaby', 'Dudek',
'Football', 'Freeman4', 'Girl', 'Human3', 'Human4',
'Human6', 'Human9', 'Ironman', 'Jump', 'Jumping',
'Liquor', 'Matrix', 'MotorRolling', 'Panda', 'RedTeam',
'Shaking', 'Singer2', 'Skating1', 'Skating2', 'Skiing',
'Soccer', 'Surfer', 'Sylvester', 'Tiger2', 'Trellis',
'Walking', 'Walking2', 'Woman']

__tb100_seqs = ['Bird2', 'BlurCar1', 'BlurCar3', 'BlurCar4', 'Board',
'Bolt2', 'Boy', 'Car2', 'Car24', 'Coke', 'Coupon',
'Crossing', 'Dancer', 'Dancer2', 'David2', 'David3',
'Dog', 'Dog1', 'Doll', 'FaceOcc1', 'FaceOcc2', 'Fish',
'FleetFace', 'Football1', 'Freeman1', 'Freeman3',
'Girl2', 'Gym', 'Human2', 'Human5', 'Human7', 'Human8',
'Jogging', 'KiteSurf', 'Lemming', 'Man', 'Mhyang',
'MountainBike', 'Rubik', 'Singer1', 'Skater',
'Skater2', 'Subway', 'Suv', 'Tiger1', 'Toy', 'Trans',
'Twinnings', 'Vase'] + __tb50_seqs

__otb15_seqs = __tb100_seqs

__version_dict = {
2013: __otb13_seqs,
2015: __otb15_seqs,
'otb2013': __otb13_seqs,
'otb2015': __otb15_seqs,
'tb50': __tb50_seqs,
'tb100': __tb100_seqs}

def __init__(self, root_dir, version=2015, download=True):
super(OTB, self).__init__()
assert version in self.__version_dict

self.root_dir = root_dir
self.version = version
if download:
self._download(root_dir, version)
self._check_integrity(root_dir, version)

valid_seqs = self.__version_dict[version]
self.anno_files = sorted(list(chain.from_iterable(glob.glob(
os.path.join(root_dir, s, 'groundtruth*.txt')) for s in valid_seqs)))
# remove empty annotation files
# (e.g., groundtruth_rect.1.txt of Human4)
self.anno_files = self._filter_files(self.anno_files)
self.seq_dirs = [os.path.dirname(f) for f in self.anno_files]
self.seq_names = [os.path.basename(d) for d in self.seq_dirs]
# rename repeated sequence names
# (e.g., Jogging and Skating2)
self.seq_names = self._rename_seqs(self.seq_names)

def __getitem__(self, index):
r"""
Args:
index (integer or string): Index or name of a sequence.
Returns:
tuple: (img_files, anno), where ``img_files`` is a list of
file names and ``anno`` is a N x 4 (rectangles) numpy array.
"""
if isinstance(index, six.string_types):
if not index in self.seq_names:
raise Exception('Sequence {} not found.'.format(index))
index = self.seq_names.index(index)

img_files = sorted(glob.glob(
os.path.join(self.seq_dirs[index], 'img/*.jpg')))

# special sequences
# (visit http://cvlab.hanyang.ac.kr/tracker_benchmark/index.html for detail)
seq_name = self.seq_names[index]
if seq_name.lower() == 'david':
img_files = img_files[300-1:770]
elif seq_name.lower() == 'football1':
img_files = img_files[:74]
elif seq_name.lower() == 'freeman3':
img_files = img_files[:460]
elif seq_name.lower() == 'freeman4':
img_files = img_files[:283]
elif seq_name.lower() == 'diving':
img_files = img_files[:215]

# to deal with different delimeters
with open(self.anno_files[index], 'r') as f:
anno = np.loadtxt(io.StringIO(f.read().replace(',', ' ')))
assert len(img_files) == len(anno)
assert anno.shape[1] == 4

return img_files, anno

def __len__(self):
return len(self.seq_names)

def _filter_files(self, filenames):
filtered_files = []
for filename in filenames:
with open(filename, 'r') as f:
if f.read().strip() == '':
print('Warning: %s is empty.' % filename)
else:
filtered_files.append(filename)

return filtered_files

def _rename_seqs(self, seq_names):
# in case some sequences may have multiple targets
renamed_seqs = []
for i, seq_name in enumerate(seq_names):
if seq_names.count(seq_name) == 1:
renamed_seqs.append(seq_name)
else:
ind = seq_names[:i + 1].count(seq_name)
renamed_seqs.append('%s.%d' % (seq_name, ind))

return renamed_seqs

def _download(self, root_dir, version):
assert version in self.__version_dict
seq_names = self.__version_dict[version]

if not os.path.isdir(root_dir):
os.makedirs(root_dir)
elif all([os.path.isdir(os.path.join(root_dir, s)) for s in seq_names]):
print('Files already downloaded.')
return

url_fmt = 'http://cvlab.hanyang.ac.kr/tracker_benchmark/seq/%s.zip'
for seq_name in seq_names:
seq_dir = os.path.join(root_dir, seq_name)
if os.path.isdir(seq_dir):
continue
url = url_fmt % seq_name
zip_file = os.path.join(root_dir, seq_name + '.zip')
print('Downloading to %s...' % zip_file)
download(url, zip_file)
print('\nExtracting to %s...' % root_dir)
extract(zip_file, root_dir)

return root_dir

def _check_integrity(self, root_dir, version):
assert version in self.__version_dict
seq_names = self.__version_dict[version]

if os.path.isdir(root_dir) and len(os.listdir(root_dir)) > 0:
# check each sequence folder
for seq_name in seq_names:
seq_dir = os.path.join(root_dir, seq_name)
if not os.path.isdir(seq_dir):
print('Warning: sequence %s not exist.' % seq_name)
else:
# dataset not exist
raise Exception('Dataset not found or corrupted. ' +
'You can use download=True to download it.')
Loading

0 comments on commit ccdb20a

Please sign in to comment.