def from_json(cls, data, objects: VideoObjectCollection, frame_index, key_id_map: KeyIdMap = None): object_id = data.get(OBJECT_ID, None) object_key = None if OBJECT_KEY in data: object_key = uuid.UUID(data[OBJECT_KEY]) if object_id is None and object_key is None: raise RuntimeError("Figure can not be deserialized from json: object_id or object_key are not found") if object_key is None: if key_id_map is None: raise RuntimeError("Figure can not be deserialized: key_id_map is None") object_key = key_id_map.get_object_key(object_id) if object_key is None: raise RuntimeError("Object with id={!r} not found in key_id_map".format(object_id)) object = objects.get(object_key) if object is None: raise RuntimeError("Figure can not be deserialized: corresponding object {!r} not found in ObjectsCollection".format(object_key.hex)) shape_str = data[ApiField.GEOMETRY_TYPE] geometry_json = data[ApiField.GEOMETRY] shape = GET_GEOMETRY_FROM_STR(shape_str) geometry = shape.from_json(geometry_json) key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_figure(key, data.get(ID, None)) return cls(object, geometry, frame_index, key)
def from_json(cls, data, project_meta: ProjectMeta, key_id_map: KeyIdMap = None): ''' The function from_json convert PointcloudObject from json format to PointcloudObject class object. Raise error if object class name is not found in the given project meta :param data: input PointcloudObject in json format :param project_meta: ProjectMeta class object :param key_id_map: KeyIdMap class object :return: PointcloudObject class object ''' obj_class_name = data[LabelJsonFields.OBJ_CLASS_NAME] obj_class = project_meta.get_obj_class(obj_class_name) if obj_class is None: raise RuntimeError( f'Failed to deserialize a object from JSON: class name {obj_class_name!r} ' f'was not found in the given project meta.') object_id = data.get(ID, None) existing_key = None if object_id is not None and key_id_map is not None: existing_key = key_id_map.get_object_key(object_id) json_key = uuid.UUID(data[KEY]) if KEY in data else None if (existing_key is not None) and (json_key is not None) and (existing_key != json_key): raise RuntimeError( "Object id = {!r}: existing_key {!r} != json_key {!r}".format( object_id, existing_key, json_key)) if existing_key is not None: key = existing_key elif json_key is not None: key = json_key else: key = uuid.uuid4() if key_id_map is not None and existing_key is None: key_id_map.add_object(key, object_id) class_id = data.get(CLASS_ID, None) labeler_login = data.get(LABELER_LOGIN, None) updated_at = data.get(UPDATED_AT, None) created_at = data.get(CREATED_AT, None) return cls(obj_class=obj_class, key=key, tags=VideoTagCollection.from_json( data[LabelJsonFields.TAGS], project_meta.tag_metas), class_id=class_id, labeler_login=labeler_login, updated_at=updated_at, created_at=created_at)
def from_json(cls, data, objects: VideoObjectCollection, frame_index, key_id_map: KeyIdMap = None): ''' The function from_json convert VideoFigure from json format to VideoFigure class object. :param data: input VideoFigure in json format :param objects: VideoObjectCollection :param frame_index: int :param key_id_map: KeyIdMap class object :return: VideoFigure class object ''' object_id = data.get(OBJECT_ID, None) object_key = None if OBJECT_KEY in data: object_key = uuid.UUID(data[OBJECT_KEY]) if object_id is None and object_key is None: raise RuntimeError("Figure can not be deserialized from json: object_id or object_key are not found") if object_key is None: if key_id_map is None: raise RuntimeError("Figure can not be deserialized: key_id_map is None") object_key = key_id_map.get_object_key(object_id) if object_key is None: raise RuntimeError("Object with id={!r} not found in key_id_map".format(object_id)) object = objects.get(object_key) if object is None: raise RuntimeError("Figure can not be deserialized: corresponding object {!r} not found in ObjectsCollection".format(object_key.hex)) shape_str = data[ApiField.GEOMETRY_TYPE] geometry_json = data[ApiField.GEOMETRY] shape = GET_GEOMETRY_FROM_STR(shape_str) geometry = shape.from_json(geometry_json) key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_figure(key, data.get(ID, None)) class_id = data.get(CLASS_ID, None) labeler_login = data.get(LABELER_LOGIN, None) updated_at = data.get(UPDATED_AT, None) created_at = data.get(CREATED_AT, None) return cls(object, geometry, frame_index, key, class_id=class_id, labeler_login=labeler_login, updated_at=updated_at, created_at=created_at)
def from_json(cls, data, project_meta: ProjectMeta, key_id_map: KeyIdMap = None): obj_class_name = data[LabelJsonFields.OBJ_CLASS_NAME] obj_class = project_meta.get_obj_class(obj_class_name) if obj_class is None: raise RuntimeError( f'Failed to deserialize a object from JSON: class name {obj_class_name!r} ' f'was not found in the given project meta.') object_id = data.get(ID, None) existing_key = key_id_map.get_object_key( object_id) if object_id is not None else None json_key = uuid.UUID(data[KEY]) if KEY in data else None if (existing_key is not None) and (json_key is not None) and (existing_key != json_key): raise RuntimeError( "Object id = {!r}: existing_key {!r} != json_key {!r}".format( object_id, existing_key, json_key)) if existing_key is not None: key = existing_key elif json_key is not None: key = json_key else: key = uuid.uuid4() if key_id_map is not None and existing_key is None: key_id_map.add_object(key, object_id) return cls(obj_class=obj_class, key=key, tags=VideoTagCollection.from_json( data[LabelJsonFields.TAGS], project_meta.tag_metas))