Created
January 28, 2018 23:21
-
-
Save mjdietzx/4d74bcb11f36e624b829784a2a2e7dd0 to your computer and use it in GitHub Desktop.
code to help debug this AWS Rekognition issue: https://forums.aws.amazon.com/thread.jspa?threadID=271815&tstart=0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
import json | |
def duplicates(): | |
# | |
# organize raw Rekognition `boto3.client('rekognition').get_face_search()` response for debugging this issue | |
# | |
with open('duplicated_index_bug.json', 'r') as f: # https://s3.us-east-2.amazonaws.com/brayniac-waya-ai/duplicated_index_bug.json | |
# list of all `PersonMatch` objects returned by Rekognition | |
person_match_objects = json.loads(f.read()) | |
# `indices` maps `Index` of `Person` tracked throughout video, to a set of their `PersonMatch` objects | |
indices = collections.defaultdict(set) | |
for person_match_object in person_match_objects: | |
index = person_match_object['Person'].pop('Index') # `Index` popped off b/c this is the only thing that differs | |
if person_match_object['Person'].get('Face'): | |
indices[index].add(json.dumps(person_match_object)) # use sets instead of lists of `PersonMatch` objects | |
# `merged` maps `Index` to the other indices it overlaps with | |
merged = collections.defaultdict(set) | |
# | |
# just see how much overlap we actually have b/w indexes | |
# | |
for i, (k, v) in enumerate(indices.items()): # `i`, `j` used to avoid iterating over same combo multiple times.. | |
for j, (_k, _v) in enumerate(indices.items()): | |
if i >= j or k in [i for v in merged.values() for i in v]: | |
continue | |
if len(v & _v): # if there is any overlap at all b/w `Index` print this info and add to `merged` | |
print(k, _k, len(v), len(_v), len(v & _v), len(v & _v) / len(v)) | |
merged[k].add(_k) | |
print(merged) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
running this code outputs (download json file required here):
and this describes each of those person
Index
in the video we are analyzing with boto3.get_face_searchthis video shows the problem described here and tracks indices
21, 22, 23, 240
throughout the original video analyzed by Rekognition. The interesting thing is that240
actually gets it correctly (only tracking frank villain) and could possibly be used to workaround the issue linked above ^.