def map_object(object_map, obj): """ Use object ids as hashes to `visual_genome.models.Object` instances. If item not in table, create new `Object`. Used when building scene graphs from json. """ oid = ("gw_{}".format(obj["object_id"]) if obj.get("guesswhat", False) else obj["object_id"]) obj["id"] = oid del obj["object_id"] if oid in object_map: object_ = object_map[oid] else: if "attributes" in obj: attrs = obj["attributes"] del obj["attributes"] else: attrs = [] if "abstract_attributes" in obj: abs_attrs = obj["abstract_attributes"] del obj["abstract_attributes"] else: abs_attrs = [] if "situated_attributes" in obj: sit_attrs = obj["situated_attributes"] del obj["situated_attributes"] else: sit_attrs = [] if "w" in obj: obj["width"] = obj["w"] obj["height"] = obj["h"] del obj["w"], obj["h"] if "guesswhat" in obj: obj["guesswhat"] = True else: obj["guesswhat"] = False object_ = Object(**obj) object_.attributes = attrs object_.abstract_attributes = abs_attrs object_.situated_attributes = sit_attrs object_map[oid] = object_ return object_map, object_
def map_object(object_map, obj): """ Use object ids as hashes to `visual_genome.models.Object` instances. If item not in table, create new `Object`. Used when building scene graphs from json. """ oid = "gw_{}".format(obj['object_id']) if obj.get("guesswhat", False) else obj["object_id"] obj['id'] = oid del obj['object_id'] if oid in object_map: object_ = object_map[oid] else: if 'attributes' in obj: attrs = obj['attributes'] del obj['attributes'] else: attrs = [] if 'abstract_attributes' in obj: abs_attrs = obj['abstract_attributes'] del obj['abstract_attributes'] else: abs_attrs = [] if 'situated_attributes' in obj: sit_attrs = obj['situated_attributes'] del obj['situated_attributes'] else: sit_attrs = [] if 'w' in obj: obj['width'] = obj['w'] obj['height'] = obj['h'] del obj['w'], obj['h'] if 'guesswhat' in obj: obj['guesswhat'] = True else: obj['guesswhat'] = False object_ = Object(**obj) object_.attributes = attrs object_.abstract_attributes = abs_attrs object_.situated_attributes = sit_attrs object_map[oid] = object_ return object_map, object_