Skip to content

Instantly share code, notes, and snippets.

@masouduut94
Created July 10, 2020 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masouduut94/4a7c44a7ff351cda79ab5f7c1490dae6 to your computer and use it in GitHub Desktop.
Save masouduut94/4a7c44a7ff351cda79ab5f7c1490dae6 to your computer and use it in GitHub Desktop.
def test_add_label_to_bbox(self):
# test if label exists in bbox
frame_one_id = 0
bbox_id = 1
bbox_xywh = (10, 20, 30, 40)
self.json_parser.add_frame(frame_one_id)
self.json_parser.add_bbox_to_frame(frame_one_id, bbox_id, *bbox_xywh)
categories = ['car', 'truck', 'bus']
confidences = [0.47, 0.85, 1]
top_k = 3
self.json_parser.set_top_k(value=top_k)
for cat, conf in zip(categories, confidences):
self.json_parser.add_label_to_bbox(frame_one_id, bbox_id, cat, conf)
out = self.json_parser.output()
inserted_labels = out['frames'][0]['bboxes'][0]['labels']
# Does output contain all labels that were inserted.
for label in inserted_labels:
self.assertTrue(label['category'] in categories)
self.assertTrue(label['confidence'] in confidences)
# Check if appending extra label (more than top_k) raises ValueError
with self.assertRaisesRegex(ValueError, 'labels in frame_id: (.*?), bbox_id: (.*?) is fulled'):
self.json_parser.add_label_to_bbox(frame_one_id, bbox_id, 'new_category', 0.12)
# Check if error raises when the number of inserted labels are less than top_k
self.json_parser.set_top_k(4)
with self.assertRaisesRegex(ValueError,
'labels in frame_id: (.*?), bbox_id: (.*?) is not fulled before outputting.'):
out = self.json_parser.output()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment