in lib/utils/metrics.py [0:0]
def merge_ava_3shift_score_files(shift_score_files, flip, scale):
"""Load score files of 3 spatial shifts and combine them."""
out_filename = shift_score_files[0].replace('_shift0', '_combined')
video_shapes = {}
logger.info("Combining scores of 3 spatial shifts:\n\t%s" %
'\n\t'.join(shift_score_files))
with open(shift_score_files[0], 'r') as fin0:
with open(shift_score_files[1], 'r') as fin1:
with open(shift_score_files[2], 'r') as fin2:
with open(out_filename, 'w') as fout:
for line0, line1, line2 in zip(fin0, fin1, fin2):
items0 = line0.split(',')
items1 = line1.split(',')
items2 = line2.split(',')
score0 = float(items0[-1])
score1 = float(items1[-1])
score2 = float(items2[-1])
box = map(float, items0[2:6])
video = items0[0]
assert items0[0] == items1[0]
assert items0[0] == items2[0]
if video not in video_shapes:
im = cv2.imread(os.path.join(
cfg.DATADIR, video, video + '_000001.jpg'))
video_shapes[video] = im.shape
height, width, _ = video_shapes[video]
height, width = scale, float(width * scale) / height
norm_crop_size = float(min(height, 256)) / width
center_left = 0.5 - norm_crop_size / 2.0
center_right = 0.5 + norm_crop_size / 2.0
lcrop_right = norm_crop_size
rcrop_left = 1.0 - norm_crop_size
if flip:
box[0], box[2] = 1.0 - box[2], 1.0 - box[0]
# Note that an object might fall completely out of a
# crop. When merging spatial shifts, we discard
# predictions of crops that do not overlap with
# the object.
valid_scores = []
if box[2] > center_left and box[0] < center_right:
valid_scores.append(score1)
if box[0] < lcrop_right:
valid_scores.append(score0)
if box[2] > rcrop_left:
valid_scores.append(score2)
combined = float(np.mean(map(sigmoid, valid_scores)))
new_line = line0.split(',')[:-1]
new_line.append(str(combined))
new_line = ','.join(new_line)
fout.write(new_line + '\n')
eval_ava_score_file(out_filename)
return out_filename