Skip to content

Commit efd05db

Browse files
author
Anthony Krivonos
authored
Add metadata support for scene categories (#348)
* Add metadata support for scene categories * Version bump
1 parent 95681af commit efd05db

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.18](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.18) - 2022-08-16
9+
10+
### Added
11+
- Metadata and confidence support for scene categories
12+
813
## [0.14.17](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.17) - 2022-08-15
914

1015
### Fixed
@@ -16,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1621
## [0.14.16](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.16) - 2022-08-12
1722

1823
### Added
19-
- Scene cateogorization support
24+
- Scene categorization support
2025

2126
## [0.14.15](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.15) - 2022-08-11
2227

nucleus/annotation.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,25 +902,31 @@ class SceneCategoryAnnotation(Annotation):
902902
903903
::
904904
905-
from nucleus import CategoryAnnotation
905+
from nucleus import SceneCategoryAnnotation
906906
907907
category = SceneCategoryAnnotation(
908908
label="running",
909909
reference_id="scene_1",
910910
taxonomy_name="action",
911+
metadata={
912+
"weather": "clear",
913+
},
911914
)
912915
913916
Parameters:
914917
label (str): The label for this annotation.
915918
reference_id (str): User-defined ID of the scene to which to apply this annotation.
916919
taxonomy_name (Optional[str]): The name of the taxonomy this annotation conforms to.
917920
See :meth:`Dataset.add_taxonomy`.
921+
metadata: Arbitrary key/value dictionary of info to attach to this annotation.
922+
Strings, floats and ints are supported best by querying and insights
923+
features within Nucleus. For more details see our `metadata guide
924+
<https://nucleus.scale.com/docs/upload-metadata>`_.
918925
"""
919926

920927
label: str
921928
reference_id: str
922929
taxonomy_name: Optional[str] = None
923-
# todo(546247): add metadata support when required
924930
metadata: Optional[Dict] = field(default_factory=dict)
925931

926932
@classmethod
@@ -929,6 +935,7 @@ def from_json(cls, payload: dict):
929935
label=payload[LABEL_KEY],
930936
reference_id=payload[REFERENCE_ID_KEY],
931937
taxonomy_name=payload.get(TAXONOMY_NAME_KEY, None),
938+
metadata=payload.get(METADATA_KEY, {}),
932939
)
933940

934941
def to_payload(self) -> dict:
@@ -937,6 +944,7 @@ def to_payload(self) -> dict:
937944
TYPE_KEY: CATEGORY_TYPE,
938945
GEOMETRY_KEY: {},
939946
REFERENCE_ID_KEY: self.reference_id,
947+
METADATA_KEY: self.metadata,
940948
}
941949
if self.taxonomy_name is not None:
942950
payload[TAXONOMY_NAME_KEY] = self.taxonomy_name

nucleus/prediction.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,65 @@ def from_json(cls, payload: dict):
575575
class SceneCategoryPrediction(SceneCategoryAnnotation):
576576
"""A prediction of a category for a scene.
577577
578+
::
579+
580+
from nucleus import SceneCategoryPrediction
581+
582+
category = SceneCategoryPrediction(
583+
label="running",
584+
reference_id="scene_1",
585+
taxonomy_name="action",
586+
confidence=0.83,
587+
metadata={
588+
"weather": "clear",
589+
},
590+
)
591+
578592
Parameters:
579593
label: The label for this annotation (e.g. action, subject, scenario).
580594
reference_id: The reference ID of the scene you wish to apply this annotation to.
581595
taxonomy_name: The name of the taxonomy this annotation conforms to.
582596
See :meth:`Dataset.add_taxonomy`.
597+
confidence: 0-1 indicating the confidence of the prediction.
598+
metadata: Arbitrary key/value dictionary of info to attach to this annotation.
599+
Strings, floats and ints are supported best by querying and insights
600+
features within Nucleus. For more details see our `metadata guide
601+
<https://nucleus.scale.com/docs/upload-metadata>`_.
583602
"""
584603

604+
def __init__(
605+
self,
606+
label: str,
607+
reference_id: str,
608+
taxonomy_name: Optional[str] = None,
609+
confidence: Optional[float] = None,
610+
metadata: Optional[Dict] = None,
611+
):
612+
super().__init__(
613+
label=label,
614+
taxonomy_name=taxonomy_name,
615+
reference_id=reference_id,
616+
metadata=metadata,
617+
)
618+
self.confidence = confidence
619+
620+
def to_payload(self) -> dict:
621+
payload = super().to_payload()
622+
if self.confidence is not None:
623+
payload[CONFIDENCE_KEY] = self.confidence
624+
625+
return payload
626+
627+
@classmethod
628+
def from_json(cls, payload: dict):
629+
return cls(
630+
label=payload.get(LABEL_KEY, 0),
631+
taxonomy_name=payload.get(TAXONOMY_NAME_KEY, None),
632+
reference_id=payload[REFERENCE_ID_KEY],
633+
confidence=payload.get(CONFIDENCE_KEY, None),
634+
metadata=payload.get(METADATA_KEY, {}),
635+
)
636+
585637

586638
Prediction = Union[
587639
BoxPrediction,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.14.17"
24+
version = "0.14.18"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)