def from_json(cls, data, project_meta, key_id_map: KeyIdMap=None): ''' The function from_json convert videoannotation from json format to VideoAnnotation class object. :param data: input videoannotation in json format :param project_meta: ProjectMeta class object :param key_id_map: KeyIdMap class object :return: VideoAnnotation class object ''' #video_name = data[VIDEO_NAME] video_key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_video(video_key, data.get(VIDEO_ID, None)) img_size_dict = data[IMG_SIZE] img_height = img_size_dict[IMG_SIZE_HEIGHT] img_width = img_size_dict[IMG_SIZE_WIDTH] img_size = (img_height, img_width) description = data.get(DESCRIPTION, "") frames_count = data[FRAMES_COUNT] tags = VideoTagCollection.from_json(data[TAGS], project_meta.tag_metas, key_id_map) objects = VideoObjectCollection.from_json(data[OBJECTS], project_meta, key_id_map) frames = FrameCollection.from_json(data[FRAMES], objects, frames_count, key_id_map) return cls(img_size=img_size, frames_count=frames_count, objects=objects, frames=frames, tags=tags, description=description, key=video_key)
def from_json(cls, data, project_meta, key_id_map: KeyIdMap = None): ''' :param data: input PointcloudAnnotation in json format :param project_meta: ProjectMeta class object :param key_id_map: KeyIdMap class object :return: PointcloudAnnotation class object ''' item_key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_video(item_key, data.get(POINTCLOUD_ID, None)) description = data.get(DESCRIPTION, "") tags = VideoTagCollection.from_json(data[TAGS], project_meta.tag_metas, key_id_map) objects = PointcloudObjectCollection.from_json(data[OBJECTS], project_meta, key_id_map) figures = [] for figure_json in data.get(FIGURES, []): figure = PointcloudFigure.from_json(figure_json, objects, None, key_id_map) figures.append(figure) return cls(objects=objects, figures=figures, tags=tags, description=description, key=item_key)
def __init__(self, objects=None, figures=None, tags=None, description="", key=None): self._description = description self._tags = take_with_default(tags, VideoTagCollection()) self._objects = take_with_default(objects, VideoObjectCollection()) self._figures = take_with_default(figures, []) self._key = take_with_default(key, uuid.uuid4())
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, 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.') key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_object(key, data.get(ID, None)) return cls(obj_class=obj_class, key=key, tags=VideoTagCollection.from_json(data[LabelJsonFields.TAGS], project_meta.tag_metas))
def __init__(self, objects=None, figures=None, tags=None, description="", key=None): ''' :param objects: VideoObjectCollection :param figures: list of figures(Point, Cuboid, etc) :param tags: VideoTagCollection :param description: str :param key: uuid class object ''' self._description = description self._tags = take_with_default(tags, VideoTagCollection()) self._objects = take_with_default(objects, VideoObjectCollection()) self._figures = take_with_default(figures, []) self._key = take_with_default(key, uuid.uuid4())
def __init__(self, obj_class: ObjClass, tags: VideoTagCollection = None, key=None, class_id=None, labeler_login=None, updated_at=None, created_at=None): ''' :param obj_class: ObjClass class object :param tags: VideoTagCollection :param key: uuid class object ''' self.labeler_login = labeler_login self.updated_at = updated_at self.created_at = created_at self._obj_class = obj_class self._key = take_with_default(key, uuid.uuid4()) self._tags = take_with_default(tags, VideoTagCollection())
def __init__(self, img_size, frames_count, objects=None, frames=None, tags=None, description="", key=None): if not isinstance(img_size, (tuple, list)): raise TypeError( '{!r} has to be a tuple or a list. Given type "{}".'.format( 'img_size', type(img_size))) self._img_size = tuple(img_size) self._frames_count = frames_count self._description = description self._tags = take_with_default(tags, VideoTagCollection()) self._objects = take_with_default(objects, VideoObjectCollection()) self._frames = take_with_default(frames, FrameCollection()) self._key = take_with_default(key, uuid.uuid4()) self.validate_figures_bounds()
def __init__(self, img_size, frames_count, objects=None, frames=None, tags=None, description="", key=None): ''' The constructor for VideoAnnotation class. :param img_size: size of the image(tuple or list of integers) :param frames_count: int :param objects: VideoObjectCollection :param frames: FrameCollection :param tags: VideoTagCollection :param description: str :param key: uuid class object ''' if not isinstance(img_size, (tuple, list)): raise TypeError('{!r} has to be a tuple or a list. Given type "{}".'.format('img_size', type(img_size))) self._img_size = tuple(img_size) self._frames_count = frames_count self._description = description self._tags = take_with_default(tags, VideoTagCollection()) self._objects = take_with_default(objects, VideoObjectCollection()) self._frames = take_with_default(frames, FrameCollection()) self._key = take_with_default(key, uuid.uuid4()) self.validate_figures_bounds()
def from_json(cls, data, project_meta: ProjectMeta, key_id_map: KeyIdMap = None): ''' The function from_json convert VideoObject from json format to VideoObject class object. Raise error if object class name is not found in the given project meta :param data: input VideoObject in json format :param project_meta: ProjectMeta class object :param key_id_map: KeyIdMap class object :return: VideoObject 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.') key = uuid.UUID(data[KEY]) if KEY in data else uuid.uuid4() if key_id_map is not None: key_id_map.add_object(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(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, 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))
def __init__(self, obj_class: ObjClass, tags: VideoTagCollection = None, key=None): self._obj_class = obj_class self._key = take_with_default(key, uuid.uuid4()) self._tags = take_with_default(tags, VideoTagCollection())