def customCheck(word, set2check, objs = False):
    og = word
    chars = set(word)
    if not word or len(word) == 1 or (objs and len(word) <= 2):
        return []
    if any(map(lambda x: x.isdigit(), chars)):
        return []
    bad = chars.intersection(PUNC)
    for b in bad:
        word = word.replace(b, "")
    try:
        spelling = SPELL(word)
        if type(spelling) is list:
            spelling = spelling[0]
        assert type(spelling) == str
    except Exception:
        spelling = "INVALID"
    word = spelling if word!= spelling else word
    if word in INVALID_NOUNS or (objs and word in relations):
        return []
    if word.count(" ") == 1:
        split = word.split(" ")
        if (split[0] in attributes \
                or split[0].isdigit()\
                or len(split[0]) ==1)\
                or split[0] in relations\
                and split[1] in set2check:
                    return [split[0]]
    if word in INVALID_NOUNS or (objs and word in relations):
        return []
    cands = word2alternatives(word)
    if og not in cands:
        cands.append(og)
    return cands
Пример #2
0
                    filter(lambda x: x in img_objs and x in question,
                           qid_objects))
                qid2normOverlap[qid] += overlap_objs
            else:
                overlap_objs = []

            #check objects in answer and layout
            matches = set()
            if answer not in "yes no" and\
                    answer not in relations and\
                    answer not in attributes and answer not in INVALID_NOUNS:
                matches.add(answer)
            for a in args:
                obj, a_type = find(a)
                if a_type == "INVALID":
                    for oa in word2alternatives(obj):
                        for oa in img_objs:
                            if oa in a:
                                obj = oa
                                break
                if obj and obj in img_objs:
                    add = True
                    for oa in word2alternatives(obj):
                        if oa in matches:
                            add = False
                    if add:
                        matches.add(obj)

            #get full answer matches
            answer_matches = set()
            for o in img_objs:
Пример #3
0
     }
     if gt.isdigit():
         label2score[gt] = 1
     for a in answers:
         if a not in ans2num:
             ans2num[a] = num_ans
             num_ans += 1
         label2score[a] = get_score(answers[a])
     if not label2score:
         vqa_trashed_qids.add(qid)
         total_trash += 1
     else:
         qid2num[qid] = label2score
 elif gt:
     #gt check
     for c in word2alternatives(gt):
         if c in gqa_answers:
             vqa_gqa_ans_overlap.add(gt)
             label2score[gt] = 1
             break
         elif isOrdinal(c) and keepCompound(c) and c not in IGNORE:
             label2score[gt] = 1
             break
     # other answers check
     accept = list(
         filter(lambda x: x[0] not in label2score, answers.items()))
     for (a, f) in accept:
         if a in gqa_answers:
             vqa_gqa_ans_overlap.add(a)
             label2score[a] = get_score(f)
         else:
    img_id = scene["image_id"]
    objs = scene["objects"]
    relationships = scene["relationships"]
    img_info = []

    #GET OBJECTS
    for o in objs:
        #get attributes
        try:
            attrs = o["attributes"]
            attrs = None
            fil_attrs = []
            if attrs is not None:
                for a in attrs:
                    a_set = set(word2alternatives(a)).\
                            intersections(attributes)
                    if not a_set:
                        uniq_attributes[a] += 1
                    fil_attrs.append(next(iter(a)))
        except:
            fil_attrs = []
        #get names
        all_names = set()
        names = o["names"]+[s.split(".")[0].replace("_"," ")\
                for s in o["synsets"]]
        names = list(map(lambda x: x.lower(), names))
        for n in names:
            for n_alt in customCheck(n, objects, objs = True):
                all_names.add(n_alt)
        # the name must exist