Browse Source

on tracking now gives device erro on some videos, but those who dont, give good results

master
Mahdi Abdollah Pour 2 years ago
parent
commit
724124f6af

+ 1
- 0
.gitignore View File

events.out.tfevents* events.out.tfevents*
pretrained pretrained
YOLOX_outputs YOLOX_outputs

.idea/* .idea/*



+ 20
- 0
experiments/meta_gpu_resume_fake.sh View File

#PBS -N meta_bytetrack_resume_fake
#PBS -m abe
#PBS -M [email protected]
#PBS -l nodes=1:ppn=1:gpus=1
#PBS -q DP
#PBS -l mem=15GB

export LD_LIBRARY_PATH=/share/apps/cuda/cuda-10.1/lib64:$LD_LIBRARY_PATH
export PATH=/share/apps/cuda/cuda-10.1/bin/:$PATH


source /share/apps/Anaconda/anaconda3.6/bin/activate abdollahpour.ce.sharif
conda activate abd_env


cd /home/abdollahpour.ce.sharif/ByteTrack



python tools/train.py -t metamot -f exps/example/metamot/yolox_x_mot17_on_mot20.py -d 1 -b 1 --fp16 -o --resume --start_epoch 80 -c /home/abdollahpour.ce.sharif/ByteTrack/meta_experiments/train_17_on_20_resume2/best_ckpt.pth.tar --local_rank 0 -expn train_17_on_20_resume_fake

+ 18
- 0
experiments/track_on_20_no_adapt.sh View File

#PBS -N track_17_on_20_no_adapt
#PBS -m abe
#PBS -M [email protected]
#PBS -l nodes=1:ppn=1:gpus=1
#PBS -q cuda9


export LD_LIBRARY_PATH=/share/apps/cuda/cuda-10.1/lib64:$LD_LIBRARY_PATH
export PATH=/share/apps/cuda/cuda-10.1/bin/:$PATH
source /share/apps/Anaconda/anaconda3.6/bin/activate abdollahpour.ce.sharif
conda activate abd_env


cd /home/abdollahpour.ce.sharif/ByteTrack



python tools/track.py -t metamot -f exps/example/metamot/yolox_x_mot17_on_mot20.py -d 1 -b 1 -c /home/abdollahpour.ce.sharif/ByteTrack/meta_experiments/train_17_on_20_resume2/best_ckpt.pth.tar --local_rank 0 -expn track_17_on_20_no_adapt --mot20

+ 16
- 0
experiments/track_on_20_with_gt.sh View File

#PBS -N track_17_on_20_ada_4_with_GT
#PBS -m abe
#PBS -M [email protected]
#PBS -l nodes=1:ppn=1:gpus=1
#PBS -q cuda9


export LD_LIBRARY_PATH=/share/apps/cuda/cuda-10.1/lib64:$LD_LIBRARY_PATH
export PATH=/share/apps/cuda/cuda-10.1/bin/:$PATH
source /share/apps/Anaconda/anaconda3.6/bin/activate abdollahpour.ce.sharif
conda activate abd_env
cd /home/abdollahpour.ce.sharif/ByteTrack



python tools/track.py -t metamot -f exps/example/metamot/yolox_x_mot17_on_mot20.py -d 1 -b 1 -c /home/abdollahpour.ce.sharif/ByteTrack/meta_experiments/train_17_on_20_resume2/best_ckpt.pth.tar --local_rank 0 -expn track_17_on_20_ada_4_with_GT --mot20 --adaptation_period 4 --fp16 --use_existing_files

+ 9
- 6
exps/example/metamot/yolox_x_mot17_on_mot20.py View File

print('train_anns', self.train_anns) print('train_anns', self.train_anns)
print('val_anns', self.val_anns) print('val_anns', self.val_anns)
self.input_size = (800, 1440) self.input_size = (800, 1440)
self.test_size = (896, 1600)
# TODO: try this
self.test_size = (800, 1440)
# self.test_size = (896, 1600)
# self.test_size = (736, 1920) # self.test_size = (736, 1920)
self.random_size = (20, 36) self.random_size = (20, 36)
self.max_epoch = 80 self.max_epoch = 80
self.print_interval = 250 self.print_interval = 250
self.eval_interval = 5
self.eval_interval = 10
self.test_conf = 0.001 self.test_conf = 0.001
self.nmsthre = 0.7 self.nmsthre = 0.7
self.no_aug_epochs = 10 self.no_aug_epochs = 10
return train_loaders return train_loaders


def get_eval_loaders(self, batch_size, is_distributed, testdev=False): def get_eval_loaders(self, batch_size, is_distributed, testdev=False):
from yolox.data import MOTDataset, ValTransform, ValTransformWithPseudo
from yolox.data import MOTDataset, ValTransform, ValTransformWithPseudo, TrainTransform
val_loaders = [] val_loaders = []
for val_ann in self.val_anns: for val_ann in self.val_anns:
valdataset = MOTDataset( valdataset = MOTDataset(
name='train', # change to train when running on training set name='train', # change to train when running on training set
preproc=ValTransformWithPseudo( preproc=ValTransformWithPseudo(
rgb_means=(0.485, 0.456, 0.406), rgb_means=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225),
std=(0.229, 0.224, 0.225), max_labels=500,
), ),
load_weak=True

load_weak=False
) )


if is_distributed: if is_distributed:
val_loaders.append(val_loader) val_loaders.append(val_loader)
return val_loaders return val_loaders


def get_evaluator(self, batch_size, is_distributed, testdev=False):
def get_evaluators(self, batch_size, is_distributed, testdev=False):
from yolox.evaluators import COCOEvaluator from yolox.evaluators import COCOEvaluator


val_loaders = self.get_eval_loaders(batch_size, is_distributed, testdev=testdev) val_loaders = self.get_eval_loaders(batch_size, is_distributed, testdev=testdev)

+ 6
- 6
tools/track.py View File

return accs, names return accs, names




def process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder, val_ann):
def process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder):
file_name = os.path.join(exp.output_dir, args.experiment_name) file_name = os.path.join(exp.output_dir, args.experiment_name)
rank = args.local_rank rank = args.local_rank
if rank == 0: if rank == 0:
# start evaluate # start evaluate
*_, summary = evaluator.evaluate( *_, summary = evaluator.evaluate(
model, is_distributed, args.fp16, trt_file, decoder, exp.test_size, results_folder, model, is_distributed, args.fp16, trt_file, decoder, exp.test_size, results_folder,
adaptation_period=adaptation_period,
adaptation_period=adaptation_period, eval_det=False
) )
logger.info("\n" + summary) logger.info("\n" + summary)


exp.test_size = (args.tsize, args.tsize) exp.test_size = (args.tsize, args.tsize)


if args.task == "metamot": if args.task == "metamot":
model = l2l.algorithms.MAML(model, lr=exp.inner_lr, first_order=exp.first_order, allow_nograd=True)
model = l2l.algorithms.MAML(model, lr=exp.inner_lr, first_order=exp.first_order)
torch.cuda.set_device(rank) torch.cuda.set_device(rank)
model.cuda(rank) model.cuda(rank)
model.eval() model.eval()
if args.task == 'metamot': if args.task == 'metamot':
val_loaders = exp.get_eval_loaders(args.batch_size, is_distributed, args.test) val_loaders = exp.get_eval_loaders(args.batch_size, is_distributed, args.test)
if not args.use_existing_files: if not args.use_existing_files:
for val_loader, val_ann in zip(val_loaders, exp.val_anns):
for val_loader in val_loaders:
logger.info('processing loader...') logger.info('processing loader...')
process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder, val_ann)
process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder)
eval_MOT(args, exp) eval_MOT(args, exp)
else: else:
if not args.use_existing_files: if not args.use_existing_files:
val_loader = exp.get_eval_loader(args.batch_size, is_distributed, args.test) val_loader = exp.get_eval_loader(args.batch_size, is_distributed, args.test)
process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder, exp.val_ann)
process_loader(args, exp, val_loader, model, is_distributed, trt_file, decoder)
eval_MOT(args, exp, exp.val_ann) eval_MOT(args, exp, exp.val_ann)





+ 6
- 1
yolox/core/meta_trainer.py View File

p.grad.data.mul_(1.0 / self.args.batch_size) p.grad.data.mul_(1.0 / self.args.batch_size)


self.optimizer.zero_grad() self.optimizer.zero_grad()
self.scaler.scale(loss).backward()

logger.info("loss Norm: {} , scale {}".format(torch.norm(loss), self.scaler.get_scale()))
loss = self.scaler.scale(loss)
logger.info("loss Norm: {} , scale {}".format(torch.norm(loss), self.scaler.get_scale()))
# self.scaler.scale(loss).backward()
loss.backward()
self.scaler.step(self.optimizer) self.scaler.step(self.optimizer)
self.scaler.update() self.scaler.update()



+ 1
- 1
yolox/data/__init__.py View File

# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
# Copyright (c) Megvii, Inc. and its affiliates. # Copyright (c) Megvii, Inc. and its affiliates.


from .data_augment import TrainTransform, ValTransform,ValTransformWithPseudo
from .data_augment import TrainTransform, ValTransform, ValTransformWithPseudo
from .data_prefetcher import DataPrefetcher from .data_prefetcher import DataPrefetcher
from .dataloading import DataLoader, get_yolox_datadir from .dataloading import DataLoader, get_yolox_datadir
from .datasets import * from .datasets import *

+ 3
- 1
yolox/data/data_augment.py View File

data data
""" """


def __init__(self, rgb_means=None, std=None, swap=(2, 0, 1), max_labels=100):
def __init__(self, rgb_means=None, std=None, swap=(2, 0, 1), max_labels=150):
self.means = rgb_means self.means = rgb_means
self.swap = swap self.swap = swap
self.std = std self.std = std
labels = targets[:, 4].copy() labels = targets[:, 4].copy()
ids = targets[:, 5].copy() ids = targets[:, 5].copy()
if len(boxes) == 0: if len(boxes) == 0:
print('inside if 1')
targets = np.zeros((self.max_labels, 6), dtype=np.float32) targets = np.zeros((self.max_labels, 6), dtype=np.float32)
image, r_o = preproc(image, input_dim, self.means, self.std) image, r_o = preproc(image, input_dim, self.means, self.std)
image = np.ascontiguousarray(image, dtype=np.float32) image = np.ascontiguousarray(image, dtype=np.float32)
ids_t = ids[mask_b] ids_t = ids[mask_b]


if len(boxes_t) == 0: if len(boxes_t) == 0:
print('inside if 2')
image_t, r_o = preproc(image_o, input_dim, self.means, self.std) image_t, r_o = preproc(image_o, input_dim, self.means, self.std)
boxes_o *= r_o boxes_o *= r_o
boxes_t = boxes_o boxes_t = boxes_o

+ 17
- 11
yolox/data/datasets/mot.py View File



from ..dataloading import get_yolox_datadir from ..dataloading import get_yolox_datadir
from .datasets_wrapper import Dataset from .datasets_wrapper import Dataset
import sys




class MOTDataset(Dataset): class MOTDataset(Dataset):
) )
head_tail = os.path.split(img_file) head_tail = os.path.split(img_file)
# label_path = os.path.join(head_tail[0], head_tail[1].replace('.jpg','.txt')) # label_path = os.path.join(head_tail[0], head_tail[1].replace('.jpg','.txt'))
# sys.stderr.write('original shape' + str(res.shape) + '\n values \n' + str(res))
if self.load_weak: if self.load_weak:
weak_label_path = os.path.join(head_tail[0], head_tail[1] + '_weak_yolox-x.txt') weak_label_path = os.path.join(head_tail[0], head_tail[1] + '_weak_yolox-x.txt')
# load weak labels from weak_label_path # load weak labels from weak_label_path
width = img_info[1] width = img_info[1]
height = img_info[0] height = img_info[0]
labels = np.loadtxt(weak_label_path)
res = np.ones_like(labels)
labels[2, :] *= width
labels[4, :] *= width
labels[3, :] *= height
labels[5, :] *= height
labels[4, :] += labels[2, :]
labels[5, :] += labels[3, :]


labels = np.loadtxt(weak_label_path)
# print('weak loaded', labels[:3, 2:])
labels[:, 2] = labels[:, 2] * width
labels[:, 4] = labels[:, 4] * width
labels[:, 3] = labels[:, 3] * height
labels[:, 5] = labels[:, 5] * height
labels[:, 4] += labels[:, 2]
labels[:, 5] += labels[:, 3]
# print('weak', labels[:3, 2:])

res = np.zeros_like(labels)
res[:, 0:4] = labels[:, -4:] res[:, 0:4] = labels[:, -4:]
res[:, 5] = labels[:, 1] res[:, 5] = labels[:, 1]
# all are from class one
# res[:, 4] = labels[:, 0]
# sys.stderr.write('weak shape ' + str(res.shape) + '\n values \n' + str(res))

# all are from class one
# res[:, 4] = labels[:, 0]


img = cv2.imread(img_file) img = cv2.imread(img_file)
if img is None: if img is None:

+ 25
- 9
yolox/evaluators/mot_evaluator.py View File

test_size=None, test_size=None,
result_folder=None, result_folder=None,
adaptation_period=None, adaptation_period=None,
eval_det=True,
): ):
""" """
COCO average precision (AP) Evaluation. Iterate inference on the test dataset COCO average precision (AP) Evaluation. Iterate inference on the test dataset
ap50 (float) : COCO AP of IoU=50 ap50 (float) : COCO AP of IoU=50
summary (sr): summary info of evaluation. summary (sr): summary info of evaluation.
""" """

tensor_type = torch.cuda.HalfTensor if half else torch.cuda.FloatTensor
model = model.type(tensor_type)
if adaptation_period is not None: if adaptation_period is not None:
logger.info('cloning model...') logger.info('cloning model...')
learner = model.clone() learner = model.clone()
else: else:
learner = model learner = model
# TODO half to amp_test # TODO half to amp_test
tensor_type = torch.cuda.HalfTensor if half else torch.cuda.FloatTensor
self.scaler = torch.cuda.amp.GradScaler(enabled=half,init_scale=8192)

learner = learner.eval() learner = learner.eval()
self.amp_training = False
if half: if half:
logger.info('half...')
learner = learner.half() learner = learner.half()
self.amp_training = True
ids = [] ids = []
data_list = [] data_list = []
results = [] results = []
if is_time_record: if is_time_record:
start = time.time() start = time.time()
if adaptation_period is not None and cur_iter % adaptation_period == 0: if adaptation_period is not None and cur_iter % adaptation_period == 0:
learner.train()
targets = targets.type(tensor_type)
targets.requires_grad = False
outputs = learner(imgs, targets)
loss = outputs["total_loss"]
with torch.cuda.amp.autocast(enabled=self.amp_training):
learner.train()
targets = targets.type(tensor_type)
targets.requires_grad = False
outputs = learner(imgs, targets)
loss = outputs["total_loss"]
# loss = outputs["iou_loss"]
# logger.info("loss Norm: {} , scale {}".format(torch.norm(loss), self.scaler.get_scale()))
loss = self.scaler.scale(loss)
# logger.info("loss Norm: {} , scale {}".format(torch.norm(loss), self.scaler.get_scale()))
learner.adapt(loss) learner.adapt(loss)
# self.scaler.update()
# learner.adapt(self.scaler.scale(loss))
learner.eval() learner.eval()
learner.half()


with torch.no_grad(): with torch.no_grad():
outputs = learner(imgs) outputs = learner(imgs)
data_list = gather(data_list, dst=0) data_list = gather(data_list, dst=0)
data_list = list(itertools.chain(*data_list)) data_list = list(itertools.chain(*data_list))
torch.distributed.reduce(statistics, dst=0) torch.distributed.reduce(statistics, dst=0)

eval_results = self.evaluate_prediction(data_list, statistics)
if eval_det:
eval_results = self.evaluate_prediction(data_list, statistics)
else:
eval_results = 0, 0, 'skipped'
synchronize() synchronize()
return eval_results return eval_results



+ 1
- 1
yolox/exp/base_meta_exp.py View File

pass pass


@abstractmethod @abstractmethod
def get_evaluator(self):
def get_evaluators(self):
pass pass


@abstractmethod @abstractmethod

+ 1
- 0
yolox/exp/meta_yolox_base.py View File

# ----------------- Meta-learning ------------------ # # ----------------- Meta-learning ------------------ #
self.first_order = True self.first_order = True
self.inner_lr = 1e-6 self.inner_lr = 1e-6
# self.inner_lr = 1e-10


def get_model(self): def get_model(self):
from yolox.models import YOLOPAFPN, YOLOX, YOLOXHead from yolox.models import YOLOPAFPN, YOLOX, YOLOXHead

+ 1
- 1
yolox/layers/fast_coco_eval_api.py View File



import numpy as np import numpy as np
from pycocotools.cocoeval import COCOeval from pycocotools.cocoeval import COCOeval
##TODO: check this
# import torch first to make yolox._C work without ImportError of libc10.so # import torch first to make yolox._C work without ImportError of libc10.so
# in YOLOX, env is already set in __init__.py. # in YOLOX, env is already set in __init__.py.
from yolox import _C from yolox import _C

+ 5
- 0
yolox/statics.py View File

# Mahdi Abdollahpour, 16/12/2021, 10:22 AM, PyCharm, ByteTrack



DATA_PATH = '/home/abdollahpour.ce.sharif/ByteTrackData'

Loading…
Cancel
Save