From dfc35f2ec615b9dab675abc3bd4e1839cf675546 Mon Sep 17 00:00:00 2001 From: nrupatunga Date: Thu, 12 Apr 2018 13:07:31 +0530 Subject: [PATCH] PEP8 standard --- README.md | 13 ++++++++++++ goturn/helper/BoundingBox.py | 13 ++++++------ goturn/helper/config.py | 6 ++++-- goturn/helper/helper.py | 2 ++ goturn/helper/image_proc.py | 13 ++++++------ goturn/loader/annotation.py | 4 ++-- goturn/loader/loader_alov.py | 15 +++----------- goturn/loader/loader_imagenet.py | 9 ++------ goturn/loader/video.py | 7 ++++--- goturn/loader/video_loader.py | 34 ------------------------------- goturn/logger/__init__.py | 0 goturn/logger/logger.py | 0 goturn/network/regressor.py | 2 +- goturn/network/regressor_train.py | 5 +++-- goturn/test/show_tracker_vot.py | 11 +++++----- goturn/tracker/tracker.py | 4 +--- goturn/tracker/tracker_manager.py | 7 +++---- goturn/tracker/tracker_trainer.py | 5 ++--- goturn/train/example_generator.py | 17 ++++++++-------- goturn/train/tracker_trainer.py | 4 +--- goturn/train/train.py | 32 ++++++++++++++--------------- nets/solver.prototxt | 2 +- show_tracker_vot.sh | 4 ++-- train_tracker.sh | 4 ++-- 24 files changed, 87 insertions(+), 126 deletions(-) delete mode 100755 goturn/loader/video_loader.py mode change 100755 => 100644 goturn/logger/__init__.py mode change 100755 => 100644 goturn/logger/logger.py diff --git a/README.md b/README.md index e43fe40..3891739 100755 --- a/README.md +++ b/README.md @@ -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)**, diff --git a/goturn/helper/BoundingBox.py b/goturn/helper/BoundingBox.py index 27ea28c..8a9b029 100755 --- a/goturn/helper/BoundingBox.py +++ b/goturn/helper/BoundingBox.py @@ -5,6 +5,7 @@ from ..helper.helper import sample_exp_two_sides, sample_rand_uniform + class BoundingBox: """Docstring for BoundingBox. """ @@ -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. @@ -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): @@ -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): @@ -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): @@ -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 diff --git a/goturn/helper/config.py b/goturn/helper/config.py index c6d485c..e2dbd43 100644 --- a/goturn/helper/config.py +++ b/goturn/helper/config.py @@ -1,9 +1,11 @@ -# Date: Saturday 29 July 2017 +# Date: Saturday 29 July 2017 # Email: nrupatunga@whodat.com # 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 diff --git a/goturn/helper/helper.py b/goturn/helper/helper.py index b095dd5..274d8e6 100644 --- a/goturn/helper/helper.py +++ b/goturn/helper/helper.py @@ -8,6 +8,7 @@ RAND_MAX = 2147483647 + def sample_rand_uniform(): """TODO: Docstring for sample_rand_uniform. @@ -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 diff --git a/goturn/helper/image_proc.py b/goturn/helper/image_proc.py index 15e0faa..84c94dd 100755 --- a/goturn/helper/image_proc.py +++ b/goturn/helper/image_proc.py @@ -4,7 +4,6 @@ # Description: Image processing functions import math -import cv2 import numpy as np from ..helper.BoundingBox import BoundingBox @@ -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) @@ -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 @@ -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 diff --git a/goturn/loader/annotation.py b/goturn/loader/annotation.py index 5db1a7d..1159307 100755 --- a/goturn/loader/annotation.py +++ b/goturn/loader/annotation.py @@ -1,11 +1,11 @@ -# Date: Nrupatunga: Tuesday 04 July 2017 +# Date: Nrupatunga: Tuesday 04 July 2017 # Email: nrupatunga@whodat.com # Name: Nrupatunga # Description: annotations -import sys from ..helper.BoundingBox import BoundingBox + class annotation: """Docstring for annotation. """ diff --git a/goturn/loader/loader_alov.py b/goturn/loader/loader_alov.py index 571851c..01173b4 100755 --- a/goturn/loader/loader_alov.py +++ b/goturn/loader/loader_alov.py @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/goturn/loader/loader_imagenet.py b/goturn/loader/loader_imagenet.py index b2d819d..b6dadd1 100755 --- a/goturn/loader/loader_imagenet.py +++ b/goturn/loader/loader_imagenet.py @@ -4,7 +4,6 @@ # Description: loading Imagenet dataset from __future__ import print_function -import sys import os import cv2 import glob @@ -13,9 +12,9 @@ from ..logger.logger import setup_logger from ..helper import config - kMaxRatio = 0.66 + class loader_imagenet: """Docstring for loader_imagenetdet. """ @@ -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 @@ -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. @@ -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: @@ -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] diff --git a/goturn/loader/video.py b/goturn/loader/video.py index 078bb45..8cea8a1 100755 --- a/goturn/loader/video.py +++ b/goturn/loader/video.py @@ -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 @@ -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 diff --git a/goturn/loader/video_loader.py b/goturn/loader/video_loader.py deleted file mode 100755 index 87079ae..0000000 --- a/goturn/loader/video_loader.py +++ /dev/null @@ -1,34 +0,0 @@ -# Date: Tuesday 13 June 2017 02:46:21 PM IST -# Email: nrupatunga@whodat.com -# Name: Nrupatunga -# Description: video loader class - - -class videoLoader: - - """Docstring for videoLoader. """ - - def __init__(self): - """TODO: to be defined1. """ - self.videos_ = {} - - def showVideos(self): - """TODO: Docstring for showVideos. - :arg1: TODO - :returns: TODO - """ - pass - - def showVideosShift(self): - """TODO: Docstring for showVideosShift. - :returns: TODO - - """ - pass - - def get_videos(self): - """TODO: Docstring for get_videos. - :returns: TODO - - """ - return self.videos_ diff --git a/goturn/logger/__init__.py b/goturn/logger/__init__.py old mode 100755 new mode 100644 diff --git a/goturn/logger/logger.py b/goturn/logger/logger.py old mode 100755 new mode 100644 diff --git a/goturn/network/regressor.py b/goturn/network/regressor.py index 902d1a1..d30bc2f 100755 --- a/goturn/network/regressor.py +++ b/goturn/network/regressor.py @@ -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 \ No newline at end of file diff --git a/goturn/network/regressor_train.py b/goturn/network/regressor_train.py index 0a7473e..a5f72d2 100755 --- a/goturn/network/regressor_train.py +++ b/goturn/network/regressor_train.py @@ -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: diff --git a/goturn/test/show_tracker_vot.py b/goturn/test/show_tracker_vot.py index 57f77fc..dae4536 100755 --- a/goturn/test/show_tracker_vot.py +++ b/goturn/test/show_tracker_vot.py @@ -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) diff --git a/goturn/tracker/tracker.py b/goturn/tracker/tracker.py index d113b33..b747c74 100755 --- a/goturn/tracker/tracker.py +++ b/goturn/tracker/tracker.py @@ -1,4 +1,4 @@ -# Date: Friday 02 June 2017 05:04:00 PM IST +# Date: Friday 02 June 2017 05:04:00 PM IST # Email: nrupatunga@whodat.com # Name: Nrupatunga # Description: Basic regressor function implemented @@ -6,8 +6,6 @@ from __future__ import print_function from ..helper.image_proc import cropPadImage from ..helper.BoundingBox import BoundingBox -import os -import numpy as np class tracker: diff --git a/goturn/tracker/tracker_manager.py b/goturn/tracker/tracker_manager.py index 5920296..dd6fb47 100755 --- a/goturn/tracker/tracker_manager.py +++ b/goturn/tracker/tracker_manager.py @@ -3,10 +3,11 @@ # Name: Nrupatunga # Description: tracker manager -import cv2 +import cv2 opencv_version = cv2.__version__.split('.')[0] + class tracker_manager: """Docstring for tracker_manager. """ @@ -26,7 +27,6 @@ def __init__(self, videos, regressor, tracker, logger): self.tracker = tracker self.logger = logger - def trackAll(self, start_video_num, pause_val): """Track the objects in the video """ @@ -34,7 +34,6 @@ def trackAll(self, start_video_num, pause_val): videos = self.videos objRegressor = self.regressor objTracker = self.tracker - logger = self.logger video_keys = videos.keys() for i in range(start_video_num, len(videos)): @@ -53,7 +52,7 @@ def trackAll(self, start_video_num, pause_val): sMatImage = cv2.imread(frame) sMatImageDraw = sMatImage.copy() bbox = annot_frames[i] - + if opencv_version == '2': cv2.rectangle(sMatImageDraw, (int(bbox.x1), int(bbox.y1)), (int(bbox.x2), int(bbox.y2)), (255, 255, 255), 2) else: diff --git a/goturn/tracker/tracker_trainer.py b/goturn/tracker/tracker_trainer.py index b7dc141..d4dd313 100644 --- a/goturn/tracker/tracker_trainer.py +++ b/goturn/tracker/tracker_trainer.py @@ -3,9 +3,9 @@ # Name: Nrupatunga # Description: tracker trainer -from ..train.example_generator import example_generator from ..helper import config + class tracker_trainer: """tracker trainer class""" @@ -38,7 +38,7 @@ def process_batch(self): """ self.regressor_train_.train(self.images_batch_, self.targets_batch_, - self.bbox_gt_scaled_batch_) + self.bbox_gt_scaled_batch_) def make_training_examples(self): """TODO: Docstring for make_training_examples. @@ -71,7 +71,6 @@ def train(self, img_prev, img_curr, bbox_prev, bbox_curr): if num_use < 0: logger.error('Error: num_use = {}', num_use) - self.images_batch_.extend(self.images[0:num_use]) self.targets_batch_.extend(self.targets[0:num_use]) self.bbox_gt_scaled_batch_.extend(self.bbox_gt_scaled[0:num_use]) diff --git a/goturn/train/example_generator.py b/goturn/train/example_generator.py index 69e6d22..e03571a 100755 --- a/goturn/train/example_generator.py +++ b/goturn/train/example_generator.py @@ -11,6 +11,7 @@ viz = Visdom() + class bbParams: """Docstring for bbParams. """ @@ -21,7 +22,7 @@ def __init__(self, lamda_shift, lamda_scale, min_scale, max_scale): self.lamda_scale = lamda_scale self.min_scale = min_scale self.max_scale = max_scale - + class example_generator: @@ -32,7 +33,7 @@ def __init__(self, lamda_shift, lamda_scale, min_scale, max_scale, logger): self.lamda_shift = lamda_shift self.lamda_scale = lamda_scale self.min_scale = min_scale - self.max_scale= max_scale + self.max_scale = max_scale self.logger = logger def make_true_example(self): @@ -77,8 +78,8 @@ def visualize(self, image, target, bbox, idx): bbox.unscale(image) bbox.x1, bbox.x2, bbox.y1, bbox.y2 = int(bbox.x1), int(bbox.x2), int(bbox.y1), int(bbox.y2) - image = cv2.rectangle(image, (bbox.x1, bbox.y1),(bbox.x2, bbox.y2), (0,255,0),2) - out = np.concatenate((target[np.newaxis, ...], image[np.newaxis,...]), axis=0) + image = cv2.rectangle(image, (bbox.x1, bbox.y1), (bbox.x2, bbox.y2), (0, 255, 0), 2) + out = np.concatenate((target[np.newaxis, ...], image[np.newaxis, ...]), axis=0) viz.images(np.transpose(out, [0, 3, 1, 2]), opts=dict(title='image' + str(idx), caption='How random.')) def get_default_bb_params(self): @@ -88,7 +89,7 @@ def get_default_bb_params(self): """ default_params = bbParams(self.lamda_shift, self.lamda_scale, self.min_scale, self.max_scale) return default_params - + def make_training_example_BBShift_(self, bbParams, visualize_example=False): """TODO: Docstring for make_training_example_BBShift_. :returns: TODO @@ -97,13 +98,12 @@ def make_training_example_BBShift_(self, bbParams, visualize_example=False): bbox_curr_gt = self.bbox_curr_gt_ bbox_curr_shift = BoundingBox(0, 0, 0, 0) bbox_curr_shift = bbox_curr_gt.shift(self.img_curr_, bbParams.lamda_scale, bbParams.lamda_shift, bbParams.min_scale, bbParams.max_scale, True, bbox_curr_shift) - rand_search_region, rand_search_location , edge_spacing_x, edge_spacing_y = cropPadImage(bbox_curr_shift, self.img_curr_) + rand_search_region, rand_search_location, edge_spacing_x, edge_spacing_y = cropPadImage(bbox_curr_shift, self.img_curr_) bbox_curr_gt = self.bbox_curr_gt_ bbox_gt_recentered = BoundingBox(0, 0, 0, 0) bbox_gt_recentered = bbox_curr_gt.recenter(rand_search_location, edge_spacing_x, edge_spacing_y, bbox_gt_recentered) bbox_gt_recentered.scale(rand_search_region) - bbox_gt_scaled = bbox_gt_recentered return rand_search_region, self.target_pad_, bbox_gt_scaled @@ -118,11 +118,10 @@ def make_training_example_BBShift(self): return image_rand_focus, target_pad, bbox_gt_scaled - def reset(self, bbox_curr, bbox_prev, img_curr, img_prev): """TODO: to be defined1. """ - target_pad, _, _, _ = cropPadImage(bbox_prev, img_prev) + target_pad, _, _, _ = cropPadImage(bbox_prev, img_prev) self.img_curr_ = img_curr self.bbox_curr_gt_ = bbox_curr self.bbox_prev_gt_ = bbox_prev diff --git a/goturn/train/tracker_trainer.py b/goturn/train/tracker_trainer.py index 1491dcf..b77b3d8 100755 --- a/goturn/train/tracker_trainer.py +++ b/goturn/train/tracker_trainer.py @@ -12,7 +12,5 @@ def __init__(self, example_generator, regressor_train): """TODO: to be defined1. """ self.example_generator_ = example_generator - self.regressor_train_= regressor_train + self.regressor_train_ = regressor_train self.num_batches_ = 0 - - diff --git a/goturn/train/train.py b/goturn/train/train.py index 84e28f8..1d8868f 100755 --- a/goturn/train/train.py +++ b/goturn/train/train.py @@ -3,7 +3,8 @@ # Name: Nrupatunga # Description: Training the tracker - +from ..helper import config +import caffe import argparse import setproctitle from ..logger.logger import setup_logger @@ -12,27 +13,24 @@ from ..train.example_generator import example_generator from ..network.regressor_train import regressor_train from ..tracker.tracker_trainer import tracker_trainer -import sys -sys.path.insert(0, '/usr/local/caffe/python') import os -import caffe import numpy as np - setproctitle.setproctitle('TRAIN_TRACKER_IMAGENET_ALOV') logger = setup_logger(logfile=None) +logger.info('Caffe path = {}'.format(config.CAFFE_PATH)) ap = argparse.ArgumentParser() -ap.add_argument("-imagenet", "--imagenet", required = True, help = "Path to ImageNet folder") -ap.add_argument("-alov", "--alov", required = True, help = "Path to Alov folder") -ap.add_argument("-init_caffemodel", "--init_caffemodel", required = True, help = "Path to caffe Init model") -ap.add_argument("-train_prototxt", "--train_prototxt", required = True, help = "train prototxt") -ap.add_argument("-solver_prototxt", "--solver_prototxt", required = True, help = "solver prototxt") -ap.add_argument("-lamda_shift", "--lamda_shift", required = True, help = "lamda shift") -ap.add_argument("-lamda_scale", "--lamda_scale", required = True, help = "lamda scale ") -ap.add_argument("-min_scale", "--min_scale", required = True, help = "min scale") -ap.add_argument("-max_scale", "--max_scale", required = True, help = "max scale") -ap.add_argument("-gpu_id", "--gpu_id", required = True, help = "gpu id") +ap.add_argument("-imagenet", "--imagenet", required=True, help="Path to ImageNet folder") +ap.add_argument("-alov", "--alov", required=True, help="Path to Alov folder") +ap.add_argument("-init_caffemodel", "--init_caffemodel", required=True, help="Path to caffe Init model") +ap.add_argument("-train_prototxt", "--train_prototxt", required=True, help="train prototxt") +ap.add_argument("-solver_prototxt", "--solver_prototxt", required=True, help="solver prototxt") +ap.add_argument("-lamda_shift", "--lamda_shift", required=True, help="lamda shift") +ap.add_argument("-lamda_scale", "--lamda_scale", required=True, help="lamda scale ") +ap.add_argument("-min_scale", "--min_scale", required=True, help="min scale") +ap.add_argument("-max_scale", "--max_scale", required=True, help="max scale") +ap.add_argument("-gpu_id", "--gpu_id", required=True, help="gpu id") RANDOM_SEED = 800 @@ -50,6 +48,7 @@ def train_image(image_loader, images, tracker_trainer): image, bbox = image_loader.load_annotation(curr_image, curr_ann) tracker_trainer.train(image, image, bbox, bbox) + def train_video(videos, tracker_trainer): """TODO: Docstring for train_video. """ @@ -67,6 +66,7 @@ def train_video(videos, tracker_trainer): frame_num_curr, image_curr, bbox_curr = video.load_annotation(ann_index + 1) tracker_trainer.train(image_prev, image_curr, bbox_prev, bbox_curr) + def main(args): """TODO: Docstring for main. """ @@ -97,7 +97,7 @@ def main(args): # create example generator and setup the network objExampleGen = example_generator(float(args['lamda_shift']), float(args['lamda_scale']), float(args['min_scale']), float(args['max_scale']), logger) - objRegTrain = regressor_train(args['train_prototxt'], args['init_caffemodel'], int(args['gpu_id']), args['solver_prototxt'], logger) + objRegTrain = regressor_train(args['train_prototxt'], args['init_caffemodel'], int(args['gpu_id']), args['solver_prototxt'], logger) objTrackTrainer = tracker_trainer(objExampleGen, objRegTrain, logger) while objTrackTrainer.num_batches_ < kNumBatches: diff --git a/nets/solver.prototxt b/nets/solver.prototxt index 1f30ad5..01cff2d 100644 --- a/nets/solver.prototxt +++ b/nets/solver.prototxt @@ -1,4 +1,4 @@ -net:'/home/nrupatunga/NThere/DL-Workspace/CAFFE/PY-GOTURN/nets/tracker.prototxt' +net:'/home/nrupatunga/Work-2017/DeepLearning/Code/PY-GOTURN/nets/tracker.prototxt' base_lr: 0.000001 lr_policy: "step" gamma: 0.1 diff --git a/show_tracker_vot.sh b/show_tracker_vot.sh index 4356bcd..97d098c 100755 --- a/show_tracker_vot.sh +++ b/show_tracker_vot.sh @@ -1,6 +1,6 @@ DEPLOY_PROTO='./nets/tracker.prototxt' -CAFFE_MODEL='./nets/_iter_100000.caffemodel' -TEST_DATA_PATH='/media/nrupatunga/STUDIES&SOFTWARES/Work-2017/DeepLearning/Datasets/VOT/vot2014' +CAFFE_MODEL='./nets/tracker.caffemodel' +TEST_DATA_PATH='/media/nrupatunga/data/datasets/VOT/VOT2014/vot2014/' python -m goturn.test.show_tracker_vot \ --p $DEPLOY_PROTO \ diff --git a/train_tracker.sh b/train_tracker.sh index 11840a8..c6799c8 100755 --- a/train_tracker.sh +++ b/train_tracker.sh @@ -1,5 +1,5 @@ -IMAGENET_FOLDER='/media/nrupatunga/LAPTOP_BACKUP/Datasets/ILSVRC2014' -ALOV_FOLDER='/media/nrupatunga/LAPTOP_BACKUP/Datasets/ALOV' +IMAGENET_FOLDER='/media/nrupatunga/data/datasets/ILSVRC2014/' +ALOV_FOLDER='/media/nrupatunga/data/datasets/VOT-extract/' INIT_CAFFEMODEL='./nets/tracker_init.caffemodel' TRACKER_PROTO='./nets/tracker.prototxt' SOLVER_PROTO='./nets/solver.prototxt'