Skip to content
Open
4 changes: 1 addition & 3 deletions classifier/tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def train_model_type(model, cfg, csv_path: str, json_path: str, box_dir: str, up
lr_scheduler = optim.lr_scheduler.ReduceLROnPlateau(
optimizer, mode='max', factor=0.1, patience=5, min_lr=1e-07, eps=1e-07, verbose=True)

dataloaders = {}
dataloaders['train'] = train_dataloader
dataloaders['val'] = val_dataloader
dataloaders = {'train': train_dataloader, 'val': val_dataloader}

save_path = osp.join(cfg['save_path'], cfg['date'], cfg['type'])
os.makedirs(save_path, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion classifier/tools/visualize_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main_veh():
print(f'Visualize predictions to {save_dir}')

for key, val in cfg_veh["class_map"].items():
if (type(val) == int):
if type(val) == int:
continue
os.makedirs(osp.join(save_dir, val), exist_ok=True)

Expand Down
4 changes: 1 addition & 3 deletions classifier/train_jeepsuv.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def train_model_type(model, cfg, csv_path: str, json_path: str, box_dir: str):
lr_scheduler = optim.lr_scheduler.ReduceLROnPlateau(
optimizer, mode='min', factor=0.1, patience=10, min_lr=1e-07, eps=1e-07, verbose=True)

dataloaders = {}
dataloaders['train'] = train_dataloader
dataloaders['val'] = val_dataloader
dataloaders = {'train': train_dataloader, 'val': val_dataloader}

save_path = osp.join(cfg['save_path'], cfg['date'], cfg['type'])
os.makedirs(save_path, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion detector/stop_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def process(self, track_data: dict):
print(f'mean distance: {mean_distance}')
print(distances)
for i in range(N-self.skip_frame):
if (distances[i] < mean_distance*self.alpha):
if distances[i] < mean_distance*self.alpha:
return True

return False
Expand Down
4 changes: 2 additions & 2 deletions object_tracking/deepsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np


class deepsort_rbc():
class deepsort_rbc:
def __init__(self):
self.metric = nn_matching.NearestNeighborDistanceMetric("cosine",.5 , 70)
self.tracker= Tracker(self.metric)
Expand All @@ -17,7 +17,7 @@ def reset_tracker(self):
self.tracker= Tracker(self.metric, max_age=12, n_init=1)

def run_deep_sort(self, out_scores, out_boxes, features):
if out_boxes==[]:
if not out_boxes:
self.tracker.predict()
print('No detections')
trackers = self.tracker.tracks
Expand Down
4 changes: 2 additions & 2 deletions object_tracking/deepsort_feat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np


class deepsort_rbc():
class deepsort_rbc:
def __init__(self):
self.metric = nn_matching.NearestNeighborDistanceMetric("cosine",.4 , 70)
self.tracker= Tracker(self.metric)
Expand All @@ -18,7 +18,7 @@ def reset_tracker(self):
self.tracker= Tracker(self.metric, max_age=12, n_init=1)

def run_deep_sort(self, out_scores, out_boxes, features):
if out_boxes==[]:
if not out_boxes:
self.tracker.predict()
print('No detections')
trackers = self.tracker.tracks
Expand Down
10 changes: 5 additions & 5 deletions object_tracking/reid/tools/parse_test_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def parse_file(filepath, regex_mAP, regex_r1, regex_r5, regex_r10, regex_r20):


def main(args):
regex_mAP = re.compile(r'mAP: ([\.\deE+-]+)%')
regex_r1 = re.compile(r'Rank-1 : ([\.\deE+-]+)%')
regex_r5 = re.compile(r'Rank-5 : ([\.\deE+-]+)%')
regex_r10 = re.compile(r'Rank-10 : ([\.\deE+-]+)%')
regex_r20 = re.compile(r'Rank-20 : ([\.\deE+-]+)%')
regex_mAP = re.compile(r'mAP: ([.\deE+-]+)%')
regex_r1 = re.compile(r'Rank-1 {2}: ([.\deE+-]+)%')
regex_r5 = re.compile(r'Rank-5 {2}: ([.\deE+-]+)%')
regex_r10 = re.compile(r'Rank-10 : ([.\deE+-]+)%')
regex_r20 = re.compile(r'Rank-20 : ([.\deE+-]+)%')

final_res = defaultdict(list)

Expand Down
12 changes: 9 additions & 3 deletions object_tracking/reid/torchreid/data/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def __init__(
sl=0.02,
sh=0.4,
r1=0.3,
mean=[0.4914, 0.4822, 0.4465]
mean=None
):
if mean is None:
mean = [0.4914, 0.4822, 0.4465]
self.probability = probability
self.mean = mean
self.sl = sl
Expand Down Expand Up @@ -234,8 +236,8 @@ def build_transforms(
height,
width,
transforms='random_flip',
norm_mean=[0.485, 0.456, 0.406],
norm_std=[0.229, 0.224, 0.225],
norm_mean=None,
norm_std=None,
**kwargs
):
"""Builds train and test transform functions.
Expand All @@ -249,6 +251,10 @@ def build_transforms(
norm_std (list or None, optional): normalization standard deviation values. Default is
ImageNet standard deviation values.
"""
if norm_mean is None:
norm_mean = [0.485, 0.456, 0.406]
if norm_std is None:
norm_std = [0.229, 0.224, 0.225]
if transforms is None:
transforms = []

Expand Down
12 changes: 9 additions & 3 deletions object_tracking/reid/torchreid/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def run(
visrank=False,
visrank_topk=10,
use_metric_cuhk03=False,
ranks=[1, 5, 10, 20],
ranks=None,
rerank=False
):
r"""A unified pipeline for training and evaluating a model.
Expand Down Expand Up @@ -160,6 +160,8 @@ def run(
Default is False. This is only enabled when test_only=True.
"""

if ranks is None:
ranks = [1, 5, 10, 20]
if visrank and not test_only:
raise ValueError(
'visrank can be set to True only if test_only=True'
Expand Down Expand Up @@ -297,7 +299,7 @@ def test(
visrank_topk=10,
save_dir='',
use_metric_cuhk03=False,
ranks=[1, 5, 10, 20],
ranks=None,
rerank=False
):
r"""Tests model on target datasets.
Expand All @@ -313,6 +315,8 @@ def test(
``extract_features()`` and ``parse_data_for_eval()`` (most of the time),
but not a must. Please refer to the source code for more details.
"""
if ranks is None:
ranks = [1, 5, 10, 20]
self.set_model_mode('eval')
targets = list(self.test_loader.keys())

Expand Down Expand Up @@ -353,9 +357,11 @@ def _evaluate(
visrank_topk=10,
save_dir='',
use_metric_cuhk03=False,
ranks=[1, 5, 10, 20],
ranks=None,
rerank=False
):
if ranks is None:
ranks = [1, 5, 10, 20]
batch_time = AverageMeter()

def _feature_extraction(data_loader):
Expand Down
2 changes: 1 addition & 1 deletion object_tracking/reid/torchreid/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def init_pretrained_weights(model, model_url):
# They are also in the checkpoints in model_urls. This pattern is used
# to find such keys.
pattern = re.compile(
r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$'
r'^(.*denselayer\d+\.(?:norm|relu|conv))\.([12]\.(?:weight|bias|running_mean|running_var))$'
)
for key in list(pretrain_dict.keys()):
res = pattern.match(key)
Expand Down
6 changes: 4 additions & 2 deletions object_tracking/reid/torchreid/models/hacnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ def __init__(
self,
num_classes,
loss='softmax',
nchannels=[128, 256, 384],
nchannels=None,
feat_dim=512,
learn_region=True,
use_gpu=True,
**kwargs
):
super(HACNN, self).__init__()
if nchannels is None:
nchannels = [128, 256, 384]
self.loss = loss
self.learn_region = learn_region
self.use_gpu = use_gpu
Expand Down Expand Up @@ -400,7 +402,7 @@ def forward(self, x):

if self.loss == 'softmax':
if self.learn_region:
return (prelogits_global, prelogits_local)
return prelogits_global, prelogits_local
else:
return prelogits_global

Expand Down
4 changes: 3 additions & 1 deletion object_tracking/reid/torchreid/models/mlfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ def __init__(
num_classes,
loss='softmax',
groups=32,
channels=[64, 256, 512, 1024, 2048],
channels=None,
embed_dim=1024,
**kwargs
):
super(MLFN, self).__init__()
if channels is None:
channels = [64, 256, 512, 1024, 2048]
self.loss = loss
self.groups = groups

Expand Down
3 changes: 1 addition & 2 deletions object_tracking/reid/torchreid/models/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def _make_layer(self, block, t, c, n, s):
# c: output channels
# n: number of blocks
# s: stride for first layer
layers = []
layers.append(block(self.in_channels, c, t, s))
layers = [block(self.in_channels, c, t, s)]
self.in_channels = c
for i in range(1, n):
layers.append(block(self.in_channels, c, t))
Expand Down
3 changes: 1 addition & 2 deletions object_tracking/reid/torchreid/models/osnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ def _make_layer(
reduce_spatial_size,
IN=False
):
layers = []
layers = [block(in_channels, out_channels, IN=IN)]

layers.append(block(in_channels, out_channels, IN=IN))
for i in range(1, layer):
layers.append(block(out_channels, out_channels, IN=IN))

Expand Down
13 changes: 4 additions & 9 deletions object_tracking/reid/torchreid/models/pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ class DimReduceLayer(nn.Module):

def __init__(self, in_channels, out_channels, nonlinear):
super(DimReduceLayer, self).__init__()
layers = []
layers.append(
nn.Conv2d(
in_channels, out_channels, 1, stride=1, padding=0, bias=False
)
)
layers.append(nn.BatchNorm2d(out_channels))
layers = [nn.Conv2d(
in_channels, out_channels, 1, stride=1, padding=0, bias=False
), nn.BatchNorm2d(out_channels)]

if nonlinear == 'relu':
layers.append(nn.ReLU(inplace=True))
Expand Down Expand Up @@ -199,8 +195,7 @@ def _make_layer(self, block, planes, blocks, stride=1):
nn.BatchNorm2d(planes * block.expansion),
)

layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
layers = [block(self.inplanes, planes, stride, downsample)]
self.inplanes = planes * block.expansion
for i in range(1, blocks):
layers.append(block(self.inplanes, planes))
Expand Down
11 changes: 4 additions & 7 deletions object_tracking/reid/torchreid/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,10 @@ def _make_layer(self, block, planes, blocks, stride=1, dilate=False):
norm_layer(planes * block.expansion),
)

layers = []
layers.append(
block(
self.inplanes, planes, stride, downsample, self.groups,
self.base_width, previous_dilation, norm_layer
)
)
layers = [block(
self.inplanes, planes, stride, downsample, self.groups,
self.base_width, previous_dilation, norm_layer
)]
self.inplanes = planes * block.expansion
for _ in range(1, blocks):
layers.append(
Expand Down
3 changes: 1 addition & 2 deletions object_tracking/reid/torchreid/models/resnet_ibn_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ def _make_layer(self, block, planes, blocks, stride=1, IN=False):
nn.BatchNorm2d(planes * block.expansion),
)

layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
layers = [block(self.inplanes, planes, stride, downsample)]
self.inplanes = planes * block.expansion
for i in range(1, blocks - 1):
layers.append(block(self.inplanes, planes))
Expand Down
3 changes: 1 addition & 2 deletions object_tracking/reid/torchreid/models/resnetmid.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def _make_layer(self, block, planes, blocks, stride=1):
nn.BatchNorm2d(planes * block.expansion),
)

layers = []
layers.append(block(self.inplanes, planes, stride, downsample))
layers = [block(self.inplanes, planes, stride, downsample)]
self.inplanes = planes * block.expansion
for i in range(1, blocks):
layers.append(block(self.inplanes, planes))
Expand Down
9 changes: 3 additions & 6 deletions object_tracking/reid/torchreid/models/senet.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,9 @@ def _make_layer(
nn.BatchNorm2d(planes * block.expansion),
)

layers = []
layers.append(
block(
self.inplanes, planes, groups, reduction, stride, downsample
)
)
layers = [block(
self.inplanes, planes, groups, reduction, stride, downsample
)]
self.inplanes = planes * block.expansion
for i in range(1, blocks):
layers.append(block(self.inplanes, planes, groups, reduction))
Expand Down
8 changes: 6 additions & 2 deletions object_tracking/reid/torchreid/utils/feature_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ def __init__(
model_name='',
model_path='',
image_size=(256, 128),
pixel_mean=[0.485, 0.456, 0.406],
pixel_std=[0.229, 0.224, 0.225],
pixel_mean=None,
pixel_std=None,
pixel_norm=True,
device='cuda',
verbose=True
):
# Build model
if pixel_mean is None:
pixel_mean = [0.485, 0.456, 0.406]
if pixel_std is None:
pixel_std = [0.229, 0.224, 0.225]
model = build_model(
model_name,
num_classes=1,
Expand Down
3 changes: 1 addition & 2 deletions object_tracking/test/deepsort_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def tracking(config: dict, json_save_dir: str, vis_save_dir: str, verbose=True):
id_num = str(track.track_id) #Get the ID for the particular track.
features = track.features #Get the feature vector corresponding to the detection.

track_dict = {}
track_dict["id"] = id_num
track_dict = {"id": id_num}

ans_box = get_closest_box(detections_class, bbox)
bbox = ans_box
Expand Down
3 changes: 1 addition & 2 deletions object_tracking/test/deepsort_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def tracking(config: dict, json_save_dir: str, vis_save_dir: str, verbose=False)
bbox = track.to_tlbr() #Get the corrected/predicted bounding box
id_num = str(track.track_id) #Get the ID for the particular track.
feature = track.last_feature #Get the feature vector corresponding to the detection.
track_dict = {}
track_dict["id"] = id_num
track_dict = {"id": id_num}

ans_box = get_closest_box(detections_class, bbox)
bbox = ans_box
Expand Down
4 changes: 2 additions & 2 deletions object_tracking/test/evaluate_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def evaluate(gt_boxes: list, cand_tracks: list):
gt_box = gt_boxes[frame_idx]
inside = is_box_in_box(gt_box, track_box)

if inside == True:
if inside:
iou = 1.0
else:
iou = calculate_iou(gt_box, track_box)

# if track.track_id == '400':
dist = calculate_distance(gt_box, track_box)

if (iou > ACCEPT_IOU_THRES): #or (inside == True):
if iou > ACCEPT_IOU_THRES: #or (inside == True):
if start_frame == -1:
start_frame = frame_idx
end_frame = frame_idx
Expand Down
2 changes: 1 addition & 1 deletion object_tracking/test/refine_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def get_center_point(box: list):
# xyxy
return ((box[0]+box[1])/2, (box[2]+box[3])/2)
return (box[0] + box[1]) / 2, (box[2] + box[3]) / 2

def check_wrong_boxes(track_data: TrackResult):
dist_meter = AverageMeter()
Expand Down
Loading