Skip to content

Commit

Permalink
PEP8 standard
Browse files Browse the repository at this point in the history
  • Loading branch information
nrupatunga committed Apr 12, 2018
1 parent 79b6d6e commit dfc35f2
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 126 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# PY-GOTURN

### News
I'm back on working on this codebase again, can expect the following
changes on the development branch (goturn-dev).

- [] Code clean up

- [] Try to add much better interface for easy debugging, to understand different parts of
the code

- [] Documentation or blog on the code.

**NOTE:** If you wish to contribute, please ping me

This is the **python** implementation of **GOTURN: Generic Object Tracking Using Regression Networks.**

**[Learning to Track at 100 FPS with Deep Regression Networks](http://davheld.github.io/GOTURN/GOTURN.html)**,
Expand Down
13 changes: 6 additions & 7 deletions goturn/helper/BoundingBox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ..helper.helper import sample_exp_two_sides, sample_rand_uniform


class BoundingBox:
"""Docstring for BoundingBox. """

Expand All @@ -24,14 +25,14 @@ def get_center_x(self):
:returns: TODO
"""
return (self.x1 + self.x2)/2.
return (self.x1 + self.x2) / 2.

def get_center_y(self):
"""TODO: Docstring for get_center_y.
:returns: TODO
"""
return (self.y1 + self.y2)/2.
return (self.y1 + self.y2) / 2.

def compute_output_height(self):
"""TODO: Docstring for compute_output_height.
Expand All @@ -40,7 +41,7 @@ def compute_output_height(self):
"""
bbox_height = self.y2 - self.y1
output_height = self.kContextFactor * bbox_height

return max(1.0, output_height)

def compute_output_width(self):
Expand All @@ -50,7 +51,7 @@ def compute_output_width(self):
"""
bbox_width = self.x2 - self.x1
output_width = self.kContextFactor * bbox_width

return max(1.0, output_width)

def edge_spacing_x(self):
Expand Down Expand Up @@ -171,7 +172,6 @@ def shift(self, image, lambda_scale_frac, lambda_shift_frac, min_scale, max_scal
new_width = max(1.0, min((image.shape[1] - 1), new_width))
num_tries_width = num_tries_width + 1


new_height = -1
num_tries_height = 0
while ((new_height < 0) or (new_height > image.shape[0] - 1)) and (num_tries_height < kMaxNumTries):
Expand All @@ -181,11 +181,10 @@ def shift(self, image, lambda_scale_frac, lambda_shift_frac, min_scale, max_scal
rand_num = sample_rand_uniform()
height_scale_factor = rand_num * (max_scale - min_scale) + min_scale

new_height = height * ( 1 + height_scale_factor )
new_height = height * (1 + height_scale_factor)
new_height = max(1.0, min((image.shape[0] - 1), new_height))
num_tries_height = num_tries_height + 1


first_time_x = True
new_center_x = -1
num_tries_x = 0
Expand Down
6 changes: 4 additions & 2 deletions goturn/helper/config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Date: Saturday 29 July 2017
# Date: Saturday 29 July 2017
# Email: [email protected]
# Name: Nrupatunga
# Description: bounding box class

import sys

CAFFE_PATH = '/usr/local/caffe/python'
sys.path.insert(0, CAFFE_PATH)
DEBUG = False
OPENCV_VERSION=2
OPENCV_VERSION = 2
2 changes: 2 additions & 0 deletions goturn/helper/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

RAND_MAX = 2147483647


def sample_rand_uniform():
"""TODO: Docstring for sample_rand_uniform.
Expand All @@ -17,6 +18,7 @@ def sample_rand_uniform():
"""
return (random.randint(0, RAND_MAX) + 1) * 1.0 / (RAND_MAX + 2)


def sample_exp_two_sides(lambda_):
"""TODO: Docstring for sample_exp_two_sides.
:returns: TODO
Expand Down
13 changes: 6 additions & 7 deletions goturn/helper/image_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Description: Image processing functions

import math
import cv2
import numpy as np
from ..helper.BoundingBox import BoundingBox

Expand All @@ -20,7 +19,7 @@ def cropPadImage(bbox_tight, image):
roi_width = min(image.shape[1], max(1.0, math.ceil(pad_image_location.x2 - pad_image_location.x1)))
roi_height = min(image.shape[0], max(1.0, math.ceil(pad_image_location.y2 - pad_image_location.y1)))

err = 0.000000001 # To take care of floating point arithmetic errors
err = 0.000000001 # To take care of floating point arithmetic errors
cropped_image = image[int(roi_bottom + err):int(roi_bottom + roi_height), int(roi_left + err):int(roi_left + roi_width)]
output_width = max(math.ceil(bbox_tight.compute_output_width()), roi_width)
output_height = max(math.ceil(bbox_tight.compute_output_height()), roi_height)
Expand All @@ -31,11 +30,11 @@ def cropPadImage(bbox_tight, image):

edge_spacing_x = min(bbox_tight.edge_spacing_x(), (image.shape[1] - 1))
edge_spacing_y = min(bbox_tight.edge_spacing_y(), (image.shape[0] - 1))

# if output_image[int(edge_spacing_y):int(edge_spacing_y) + cropped_image.shape[0], int(edge_spacing_x):int(edge_spacing_x) + cropped_image.shape[1]].shape != cropped_image.shape :
# import pdb
# pdb.set_trace()
# print('debug')
# import pdb
# pdb.set_trace()
# print('debug')

# rounding should be done to match the width and height
output_image[int(edge_spacing_y):int(edge_spacing_y) + cropped_image.shape[0], int(edge_spacing_x):int(edge_spacing_x) + cropped_image.shape[1]] = cropped_image
Expand Down Expand Up @@ -74,5 +73,5 @@ def computeCropPadImageLocation(bbox_tight, image):

# Padded image location in the original image
objPadImageLocation = BoundingBox(roi_left, roi_bottom, roi_left + roi_width, roi_bottom + roi_height)

return objPadImageLocation
4 changes: 2 additions & 2 deletions goturn/loader/annotation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Date: Nrupatunga: Tuesday 04 July 2017
# Date: Nrupatunga: Tuesday 04 July 2017
# Email: [email protected]
# Name: Nrupatunga
# Description: annotations

import sys
from ..helper.BoundingBox import BoundingBox


class annotation:

"""Docstring for annotation. """
Expand Down
15 changes: 3 additions & 12 deletions goturn/loader/loader_alov.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
# Name: Nrupatunga
# Description: loading Alov dataset

import sys
# sys.path.append('../logger/')
# sys.path.append('../helper/')
import os
import glob
from annotation import annotation
from video import video
from video import frame
import xml.etree.ElementTree as ET
from ..logger.logger import setup_logger
from ..helper.BoundingBox import BoundingBox

Expand All @@ -37,14 +32,11 @@ def loaderAlov(self):
"""
logger = self.logger
alov_folder = self.alov_folder
alov_subdirs = sorted(self.find_subfolders(self.annotations_folder))
num_annotations = 0
dict_list_of_annotations = {}

for i, alov_sub_folder in enumerate(alov_subdirs):
annotations_files = sorted(glob.glob(os.path.join(self.annotations_folder, alov_sub_folder, '*.ann')))
logger.info('Loading {:>3} of {:>3} - annotation file from folder = {:>4}'.format(i+1, len(alov_subdirs), alov_sub_folder))
logger.info('Loading {:>3} of {:>3} - annotation file from folder = {:>4}'.format(i + 1, len(alov_subdirs), alov_sub_folder))

for ann in annotations_files:
self.load_annotation_file(alov_sub_folder, ann)
Expand All @@ -68,7 +60,7 @@ def load_annotation_file(self, alov_sub_folder, annotation_file):

with open(annotation_file, 'r') as f:
data = f.read().rstrip().split('\n')
for bb in data:
for bb in data:
frame_num, ax, ay, bx, by, cx, cy, dx, dy = bb.split()
frame_num, ax, ay, bx, by, cx, cy, dx, dy = int(frame_num), float(ax), float(ay), float(bx), float(by), float(cx), float(cy), float(dx), float(dy)

Expand Down Expand Up @@ -98,7 +90,6 @@ def get_videos(self, isTrain=True, val_ratio=0.2):
num_categories = len(self.category)
category = self.category
keys = sorted(category.keys())
count = 0
for i in range(num_categories):
category_video = category[keys[i]]
num_videos = len(category_video)
Expand All @@ -124,7 +115,7 @@ def get_videos(self, isTrain=True, val_ratio=0.2):

return videos


if '__main__' == __name__:
logger = setup_logger(logfile=None)
objLoaderAlov = loader_alov('/media/nrupatunga/data/datasets/VOT-extract/images/', '/media/nrupatunga/data/datasets/VOT-extract/gt/', logger)
Expand Down
9 changes: 2 additions & 7 deletions goturn/loader/loader_imagenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Description: loading Imagenet dataset

from __future__ import print_function
import sys
import os
import cv2
import glob
Expand All @@ -13,9 +12,9 @@
from ..logger.logger import setup_logger
from ..helper import config


kMaxRatio = 0.66


class loader_imagenet:

"""Docstring for loader_imagenetdet. """
Expand All @@ -35,14 +34,13 @@ def loaderImageNetDet(self):
"""
logger = self.logger
imagenet_folder = self.imagenet_folder
imagenet_subdirs = sorted(self.find_subfolders(self.annotations_folder))
num_annotations = 0
list_of_annotations_out = []

for i, imgnet_sub_folder in enumerate(imagenet_subdirs):
annotations_files = sorted(glob.glob(os.path.join(self.annotations_folder, imgnet_sub_folder, '*.xml')))
logger.info('Loading {}/{} - annotation file from folder = {}'.format(i+1, len(imagenet_subdirs), imgnet_sub_folder))
logger.info('Loading {}/{} - annotation file from folder = {}'.format(i + 1, len(imagenet_subdirs), imgnet_sub_folder))
for ann in annotations_files:
list_of_annotations, num_ann_curr = self.load_annotation_file(ann)
num_annotations = num_annotations + num_ann_curr
Expand All @@ -57,7 +55,6 @@ def loaderImageNetDet(self):
self.num_annotations = num_annotations

return list_of_annotations_out


def find_subfolders(self, imagenet_folder):
"""TODO: Docstring for find_subfolders.
Expand Down Expand Up @@ -118,7 +115,6 @@ def load_annotation(self, image_num, annotation_num):
list_annotations = images[image_num]
random_ann = list_annotations[annotation_num]


img_path = os.path.join(self.imagenet_folder, random_ann.image_path + '.JPEG')

if config.DEBUG:
Expand All @@ -130,7 +126,6 @@ def load_annotation(self, image_num, annotation_num):
random_ann.disp_height = 375
random_ann.disp_width = 500


image = cv2.imread(img_path)

img_height = image.shape[0]
Expand Down
7 changes: 4 additions & 3 deletions goturn/loader/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import cv2


class frame:

"""Docstring for frame. """

def __init__(self, frame_num, bbox):
"""TODO: to be defined1. """
self.frame_num = frame_num
Expand All @@ -33,12 +35,11 @@ def load_annotation(self, annotation_index):
frame_num = ann_frame.frame_num
bbox = ann_frame.bbox

video_path = self.video_path
image_files = self.all_frames
image_files = self.all_frames

assert(len(image_files) > 0)
assert(frame_num < len(image_files))

image = cv2.imread(image_files[frame_num])
return frame_num, image, bbox

Expand Down
34 changes: 0 additions & 34 deletions goturn/loader/video_loader.py

This file was deleted.

Empty file modified goturn/logger/__init__.py
100755 → 100644
Empty file.
Empty file modified goturn/logger/logger.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion goturn/network/regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ def estimate(self, curr_search_region, target_region):
net.forward()
bbox_estimate = net.blobs['fc8'].data

return bbox_estimate
return bbox_estimate
5 changes: 3 additions & 2 deletions goturn/network/regressor_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from ..helper import config
sys.path.insert(0, config.CAFFE_PATH)
import caffe
from visdom import Visdom
viz = Visdom()
# __import__('pdb').set_trace()
# from visdom import Visdom
# viz = Visdom()

class regressor_train:

Expand Down
11 changes: 5 additions & 6 deletions goturn/test/show_tracker_vot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
from ..loader.loader_vot import loader_vot
from ..tracker.tracker import tracker
from ..tracker.tracker_manager import tracker_manager
from ..loader.video import video

setproctitle.setproctitle('SHOW_TRACKER_VOT')
logger = setup_logger(logfile=None)

ap = argparse.ArgumentParser()
ap.add_argument("-p", "--prototxt", required = True, help = "Path to the prototxt")
ap.add_argument("-m", "--model", required = True, help = "Path to the model")
ap.add_argument("-v", "--input", required = True, help = "Path to the vot directory")
ap.add_argument("-g", "--gpuID", required = True, help = "gpu to use")
ap.add_argument("-p", "--prototxt", required=True, help="Path to the prototxt")
ap.add_argument("-m", "--model", required=True, help="Path to the model")
ap.add_argument("-v", "--input", required=True, help="Path to the vot directory")
ap.add_argument("-g", "--gpuID", required=True, help="gpu to use")
args = vars(ap.parse_args())

do_train = False
objRegressor = regressor(args['prototxt'], args['model'], args['gpuID'], 1, do_train, logger)
objTracker = tracker(False, logger) # Currently no idea why this class is needed, eventually we shall figure it out
objTracker = tracker(False, logger) # Currently no idea why this class is needed, eventually we shall figure it out
objLoaderVot = loader_vot(args['input'], logger)
videos = objLoaderVot.get_videos()
objTrackerVis = tracker_manager(videos, objRegressor, objTracker, logger)
Expand Down
Loading

0 comments on commit dfc35f2

Please sign in to comment.