in scripts/attr_prep_tag_NP.py [0:0]
def extract_attr(database, splits):
split_dict = {}
for split in splits:
split_dict.update({s:s for s in split})
print('Object classes defined on {} videos, freq threshold is {}'.format(len(split_dict), args.freq_thresh))
attr_all = [] # all the attributes
for vid_id, vid in database.items():
if split_dict.get(vid_id, -1) != -1:
for seg_id, seg in vid['segments'].items():
for obj in seg['objects']:
assert(len(obj['frame_ind']) == 1)
for box_id, box in obj['frame_ind'].items():
tmp = []
attr_lst = []
sorted_attr = sorted(box['attributes'], key=lambda x:x[0]) # the attributes are unordered
for ind, attr in enumerate(sorted_attr):
assert(attr[0] >= 0)
if len(tmp) == 0:
tmp.append(attr[1].lower()) # convert to lowercase
else:
if attr[0] == (sorted_attr[ind-1][0]+1):
tmp.append(attr[1].lower())
else:
attr_lst.append(tmp)
tmp = [attr[1].lower()]
if len(tmp) > 0: # the last one
attr_lst.append(tmp)
# exclude empty box (no attribute)
# crowd boxes are ok for now
if len(attr_lst) == 0: # or box['crowds'] == 1
pass
# print('empty attribute at video {}, segment {}, box {}'.format(vid_id, seg_id, box_id))
else:
attr_all.extend([' '.join(i) for i in attr_lst])
return attr_all