Skip to content

Commit

Permalink
personal preference
Browse files Browse the repository at this point in the history
  • Loading branch information
Little-Podi committed Jul 1, 2023
1 parent 9cc0fd1 commit c0bdde2
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ If any parts of our paper and code help your research, please consider citing us
## Contact
If you have any questions or concerns, feel free to open issues or directly contact me through the ways on my GitHub homepage. Suggestions and collaborations are also highly welcome!
If you have any questions or concerns, feel free to open issues or directly contact me through the ways on my GitHub [homepage](https://github.com/Little-Podi). Suggestions and collaborations are also highly welcome!
3 changes: 0 additions & 3 deletions external/PreciseRoIPooling/pytorch/prroi_pool/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def _import_prroi_pooling():
)
except ImportError:
raise ImportError('Can not compile Precise RoI Pooling library.')

return _prroi_pooling


Expand Down Expand Up @@ -60,7 +59,6 @@ def forward(ctx, features, rois, pooled_height, pooled_width, spatial_scale):
ctx.save_for_backward(features, rois, output)
else:
raise NotImplementedError('Precise RoI Pooling only supports GPU (cuda) implememtations.')

return output

@staticmethod
Expand All @@ -77,7 +75,6 @@ def backward(ctx, grad_output):
grad_output = grad_output.contiguous()
grad_coor = _prroi_pooling.prroi_pooling_coor_backward_cuda(features, rois, output, grad_output,
*ctx.params)

return grad_input, grad_coor, None, None, None


Expand Down
4 changes: 2 additions & 2 deletions lib/config/aiatrack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def _edict2dict(dest_dict, src_edict):
if not isinstance(v, edict):
dest_dict[k] = v
else:
dest_dict[k] = {}
dest_dict[k] = dict()
_edict2dict(dest_dict[k], v)
else:
return


def gen_config(config_file):
cfg_dict = {}
cfg_dict = dict()
_edict2dict(cfg_dict, cfg)
with open(config_file, 'w') as f:
yaml.dump(cfg_dict, f, default_flow_style=False)
Expand Down
12 changes: 4 additions & 8 deletions lib/models/aiatrack/aiatrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def forward_transformer(self, search_dic, refer_dic_list=None, refer_reg_list=No
bs, 1, 1)

if refer_mem_list is None:
refer_mem_list = []
refer_emb_list = []
refer_pos_list = []
refer_msk_list = []
refer_mem_list = list()
refer_emb_list = list()
refer_pos_list = list()
refer_msk_list = list()
for i in range(len(refer_dic_list)):
refer_mem = self.transformer.run_encoder(refer_dic_list[i]['feat'], refer_dic_list[i]['mask'],
refer_dic_list[i]['pos'], refer_dic_list[i]['inr'])
Expand All @@ -128,7 +128,6 @@ def forward_transformer(self, search_dic, refer_dic_list=None, refer_reg_list=No

output_embed = self.transformer.run_decoder(search_mem, refer_mem_list, refer_emb_list, refer_pos_list,
refer_msk_list)

return output_embed, search_mem, search_dic['inr'], search_dic['mask']

def forward_box_head(self, hs):
Expand Down Expand Up @@ -162,7 +161,6 @@ def forward_iou_head(self, hs, proposals):
pred_iou = self.iou_head(opt_feat, proposals)

out = {'pred_iou': pred_iou}

return out

def forward_heads(self, hs, proposals):
Expand All @@ -181,7 +179,6 @@ def forward_heads(self, hs, proposals):
outputs_coord_new = outputs_coord.view(bs, Nq, 4)

out = {'pred_iou': pred_iou, 'pred_boxes': outputs_coord_new}

return out

def adjust(self, output_back: list, pos_embed: list, inr_embed: list):
Expand Down Expand Up @@ -211,5 +208,4 @@ def build_aiatrack(cfg):
head_type=cfg.MODEL.HEAD_TYPE,
iou_head=iou_head
)

return model
9 changes: 4 additions & 5 deletions lib/models/aiatrack/backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, backbone: nn.Module, train_backbone: bool, num_channels: int,

def forward(self, tensor_list: NestedTensor):
xs = self.body(tensor_list.tensors)
out: Dict[str, NestedTensor] = {}
out: Dict[str, NestedTensor] = dict()
for name, x in xs.items():
m = tensor_list.mask
assert m is not None
Expand Down Expand Up @@ -104,15 +104,14 @@ def __init__(self, backbone, position_embedding, learned_embedding):

def forward(self, tensor_list: NestedTensor, mode=None):
xs = self[0](tensor_list)
out: List[NestedTensor] = []
pos: List[NestedTensor] = []
inr: List[NestedTensor] = []
out: List[NestedTensor] = list()
pos: List[NestedTensor] = list()
inr: List[NestedTensor] = list()
for name, x in xs.items():
out.append(x)
# Position encoding
pos.append(self[1](x).to(x.tensors.dtype))
inr.append(self[2](x).to(x.tensors.dtype))

return out, pos, inr


Expand Down
2 changes: 0 additions & 2 deletions lib/models/aiatrack/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def predict_iou(self, feat, proposals):
fc_feat = self.fc(roi_feat)

iou_pred = self.iou_predictor(fc_feat).reshape(batch_size, num_proposals_per_batch)

return iou_pred

def get_iou_feat(self, feat):
Expand All @@ -219,7 +218,6 @@ def get_iou_feat(self, feat):

feat = feat.reshape(-1, *feat.shape[-3:]) if feat.dim() == 5 else feat
iou_feat = self.conv3(self.conv2(self.conv1(feat)))

return iou_feat


Expand Down
1 change: 0 additions & 1 deletion lib/models/aiatrack/position_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,4 @@ def build_position_encoding(cfg):
raise ValueError(f'ERROR: not supported {cfg.MODEL.POSITION_EMBEDDING}')

inner_position_embedding = PositionEmbeddingSine(cfg.MODEL.AIA.MATCH_DIM // 2, normalize=True)

return position_embedding, inner_position_embedding
5 changes: 1 addition & 4 deletions lib/models/aiatrack/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class ResNet(nn.Module):

def __init__(self, block, layers, num_classes=1000, zero_init_residual=False,
groups=1, width_per_group=64, replace_stride_with_dilation=None,
norm_layer=None, last_layer=None):
Expand Down Expand Up @@ -92,15 +91,14 @@ def _make_layer(self, block, planes, blocks, stride=1, dilate=False):
norm_layer(planes * block.expansion),
)

layers = []
layers = list()
layers.append(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(block(self.inplanes, planes, groups=self.groups,
base_width=self.base_width, dilation=self.dilation,
norm_layer=norm_layer))

return nn.Sequential(*layers)

def _forward_impl(self, x):
Expand All @@ -121,7 +119,6 @@ def _forward_impl(self, x):
x = self.avgpool(x)
x = torch.flatten(x, 1)
x = self.fc(x)

return x

def forward(self, x):
Expand Down
2 changes: 0 additions & 2 deletions lib/models/aiatrack/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def forward(self, src,

if self.norm is not None:
output = self.norm(output)

return output


Expand All @@ -133,7 +132,6 @@ def forward(self, tgt, refer_mem_list, refer_emb_list, refer_pos_list, refer_msk

if self.norm is not None:
output = self.norm(output)

return output.unsqueeze(0)


Expand Down
20 changes: 9 additions & 11 deletions lib/test/analysis/plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def check_eval_data_is_valid(eval_data, trackers, dataset):


def merge_multiple_runs(eval_data):
new_tracker_names = []
ave_success_rate_plot_overlap_merged = []
ave_success_rate_plot_center_merged = []
ave_success_rate_plot_center_norm_merged = []
avg_overlap_all_merged = []
new_tracker_names = list()
ave_success_rate_plot_overlap_merged = list()
ave_success_rate_plot_center_merged = list()
ave_success_rate_plot_center_norm_merged = list()
avg_overlap_all_merged = list()

ave_success_rate_plot_overlap = torch.tensor(eval_data['ave_success_rate_plot_overlap'])
ave_success_rate_plot_center = torch.tensor(eval_data['ave_success_rate_plot_center'])
Expand Down Expand Up @@ -126,8 +126,8 @@ def plot_draw_save(y, x, scores, trackers, plot_draw_styles, result_plot_path, p

index_sort = scores.argsort(descending=False)

plotted_lines = []
legend_text = []
plotted_lines = list()
legend_text = list()

for id, id_sort in enumerate(index_sort):
line = ax.plot(x.tolist(), y[id_sort, :].tolist(),
Expand Down Expand Up @@ -198,7 +198,6 @@ def get_prec_curve(ave_success_rate_plot_center, valid_sequence):
ave_success_rate_plot_center = ave_success_rate_plot_center[valid_sequence, :, :]
prec_curve = ave_success_rate_plot_center.mean(0) * 100.0
prec_score = prec_curve[:, 20]

return prec_curve, prec_score


Expand Down Expand Up @@ -304,7 +303,6 @@ def generate_formatted_report(row_labels, scores, table_name=''):
score='{:0.2f}'.format(score_value[trk_id].item()),
width=s_w)
report_text = '{prev}\n'.format(prev=report_text)

return report_text


Expand Down Expand Up @@ -335,7 +333,7 @@ def print_results(trackers, dataset, report_name, merge_results=False,
print('reporting results over {} / {} sequences'.format(valid_sequence.long().sum().item(),
valid_sequence.shape[0]))

scores = {}
scores = dict()

# Success plot
if 'success' in plot_types:
Expand Down Expand Up @@ -395,7 +393,7 @@ def plot_got_success(trackers, report_name):
scores = torch.zeros(len(trackers))

# Load results
tracker_names = []
tracker_names = list()
for trk_id, trk in enumerate(trackers):
json_path = '{}/{}.json'.format(settings.got_reports_path, trk.name)

Expand Down
1 change: 0 additions & 1 deletion lib/test/evaluation/got10kdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ def __len__(self):
def _get_sequence_list(self):
with open('{}/list.txt'.format(self.base_path)) as f:
sequence_list = f.read().splitlines()

return sequence_list
2 changes: 1 addition & 1 deletion lib/test/evaluation/lasotdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, subset):
self.clean_list = self.clean_seq_list()

def clean_seq_list(self):
clean_lst = []
clean_lst = list()
for i in range(len(self.sequence_list)):
cls, _ = self.sequence_list[i].split('-')
clean_lst.append(cls)
Expand Down
1 change: 0 additions & 1 deletion lib/test/evaluation/otbdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,4 @@ def _get_sequence_info_list(self):
'anno_path': 'Woman/groundtruth_rect.txt',
'object_class': 'person'}
]

return sequence_info_list
2 changes: 1 addition & 1 deletion lib/test/evaluation/running.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def save_score(file, data):
np.savetxt(file, scores, delimiter=',', fmt='%.2f')

def _convert_dict(input_dict):
data_dict = {}
data_dict = dict()
for elem in input_dict:
for k, v in elem.items():
if k in data_dict.keys():
Expand Down
11 changes: 5 additions & 6 deletions lib/test/evaluation/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def _track_sequence(self, tracker, seq, init_info):
'time': []}

if tracker.params.save_all_boxes:
output['all_boxes'] = []
output['all_scores'] = []
output['all_boxes'] = list()
output['all_scores'] = list()

def _store_outputs(tracker_out: dict, defaults=None):
defaults = {} if defaults is None else defaults
defaults = dict() if defaults is None else defaults
for key in output.keys():
val = tracker_out.get(key, defaults.get(key, None))
if key in tracker_out or val is not None:
Expand All @@ -128,7 +128,7 @@ def _store_outputs(tracker_out: dict, defaults=None):
start_time = time.time()
out = tracker.initialize(image, init_info, seq.name)
if out is None:
out = {}
out = dict()

prev_output = OrderedDict(out)

Expand Down Expand Up @@ -169,7 +169,6 @@ def _store_outputs(tracker_out: dict, defaults=None):
for key in ['target_bbox', 'all_boxes', 'all_scores']:
if key in output and len(output[key]) <= 1:
output.pop(key)

return output

def run_video(self, videofilepath, optional_box=None, debug=None, visdom_info=None, save_results=False):
Expand Down Expand Up @@ -202,7 +201,7 @@ def run_video(self, videofilepath, optional_box=None, debug=None, visdom_info=No
assert os.path.isfile(videofilepath), 'invalid param {}, video file path must be a valid video file'.format(
videofilepath)

output_boxes = []
output_boxes = list()

cap = cv.VideoCapture(videofilepath)
display_name = 'Display: ' + tracker.params.tracker_name
Expand Down
2 changes: 1 addition & 1 deletion lib/test/evaluation/trackingnetdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __len__(self):
return len(self.sequence_list)

def _list_sequences(self, root, set_ids):
sequence_list = []
sequence_list = list()

for s in set_ids:
anno_dir = os.path.join(root, s, 'anno')
Expand Down
1 change: 0 additions & 1 deletion lib/test/evaluation/uavdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,4 @@ def _get_sequence_info_list(self):
{'name': 'uav_wakeboard9', 'path': 'data_seq/UAV123/wakeboard9', 'startFrame': 1, 'endFrame': 355, 'nz': 6,
'ext': 'jpg', 'anno_path': 'anno/UAV123/wakeboard9.txt', 'object_class': 'person'}
]

return sequence_info_list
1 change: 0 additions & 1 deletion lib/test/parameter/aiatrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ def parameters(yaml_name: str):

# Whether to save boxes from all queries
params.save_all_boxes = False

return params
8 changes: 4 additions & 4 deletions lib/test/tracker/aiatrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ def initialize(self, image, info: dict, seq_name: str = None):
self.refer_emb_cache = [torch.bmm(refer_region, embed_bank).transpose(0, 1)]
self.refer_pos_cache = [refer_dict['inr']]
self.refer_msk_cache = [refer_dict['mask']]
self.refer_mem_list = []
self.refer_mem_list = list()
for _ in range(self.refer_cap):
self.refer_mem_list.append(self.refer_mem_cache[0])
self.refer_emb_list = []
self.refer_emb_list = list()
for _ in range(self.refer_cap):
self.refer_emb_list.append(self.refer_emb_cache[0])
self.refer_pos_list = []
self.refer_pos_list = list()
for _ in range(self.refer_cap):
self.refer_pos_list.append(self.refer_pos_cache[0])
self.refer_msk_list = []
self.refer_msk_list = list()
for _ in range(self.refer_cap):
self.refer_msk_list.append(self.refer_msk_cache[0])
# Save states
Expand Down
Loading

0 comments on commit c0bdde2

Please sign in to comment.