PointcloudEpisodeTagCollection¶
- class PointcloudEpisodeTagCollection[source]¶
Bases:
supervisely.pointcloud_annotation.pointcloud_tag_collection.PointcloudTagCollection
Collection with
PointcloudEpisodeTag
instances.PointcloudEpisodeTagCollection
object is immutable.- Usage example
import supervisely as sly # Create TagMetas (see class TagMeta for additional information about creating TagMetas) colors = ["brown", "white", "black", "red", "chocolate", "gold", "grey"] meta_car_color = sly.TagMeta('car color', sly.TagValueType.ONEOF_STRING, possible_values=colors) # Create tags tag_car_color_white = sly.PointcloudEpisodeTag(meta_car_color, value="white", frame_range=(15, 20)) tag_car_color_red = sly.PointcloudEpisodeTag(meta_car_color, value="red", frame_range=(11, 22)) tags_arr = [tag_car_color_white, tag_car_color_red] # Create PointcloudEpisodeTagCollection from point cloud episodes Tags tags = sly.PointcloudEpisodeTagCollection(tags_arr) # Add item to PointcloudEpisodeTagCollection meta_bus = sly.TagMeta('bus', sly.TagValueType.NONE) tag_bus = sly.PointcloudEpisodeTag(meta_bus, frame_range=(11, 14)) # Remember that PointcloudEpisodeTagCollection is immutable, and we need to assign new instance of PointcloudEpisodeTagCollection to a new variable tags = tags.add(tag_bus) # You can also add multiple items to collection meta_truck = sly.TagMeta('truck', sly.TagValueType.NONE) meta_moto = sly.TagMeta('moto', sly.TagValueType.NONE) tag_truck = sly.PointcloudEpisodeTag(meta_truck, frame_range=(6, 10)) tag_moto = sly.PointcloudEpisodeTag(meta_moto, frame_range=(11, 15)) additional_tags = [tag_truck, tag_moto] tags = tags.add_items(additional_tags) # Has key, checks if given key exist in collection tags.has_key(meta_moto.key()) # Output: True # Intersection, finds intersection of given list of instances with collection items meta_bus = sly.TagMeta('bus', sly.TagValueType.NONE) tag_bus = sly.PointcloudEpisodeTag(meta_bus, frame_range=(0, 5)) meta_truck = sly.TagMeta('truck', sly.TagValueType.NONE, frame_range=(6, 11)) tag_truck = sly.PointcloudEpisodeTag(meta_truck) tags_vehicles = sly.PointcloudEpisodeTagCollection([tag_bus, tag_truck]) tags_intersections = tags.intersection(tags_vehicles) print(tags_intersections.to_json()) # Output: [] # Let's add the moto Tag from another collection and compare them again tags_vehicles = tags_vehicles.add(tag_moto) tags_intersections = tags.intersection(tags_vehicles) print(tags_intersections.to_json()) # Output: [ # { # "name": "moto", # "frameRange": [11, 15], # "key": "3f37e10a658e440db3ab9f5c0be7fb67" # } # ] # Difference, finds difference between collection and given list of Tags or PointcloudEpisodeTagCollection meta_car = sly.TagMeta('car', sly.TagValueType.NONE) tag_car = sly.PointcloudEpisodeTag(meta_car, frame_range=(6, 11)) meta_bicycle = sly.TagMeta('bicycle', sly.TagValueType.NONE) tag_bicycle = sly.PointcloudEpisodeTag(meta_bicycle, frame_range=(6, 11)) tags_vehicles = sly.PointcloudEpisodeTagCollection([tag_car, tag_bicycle]) meta_pedestrian = sly.TagMeta('pedestrian', sly.TagValueType.NONE) tag_pedestrian = sly.PointcloudEpisodeTag(meta_pedestrian, frame_range=(14, 20)) meta_road = sly.TagMeta('road', sly.TagValueType.NONE) tag_road = sly.PointcloudEpisodeTag(meta_road, frame_range=(13, 22)) difference = tags_vehicles.difference([tag_pedestrian, tag_road]) print(difference.to_json()) # Output: [ # { # "name": "car", # "frameRange": [6, 11], # "key": "eba949cb996e44ac8aebec72a0875b13" # }, # { # "name": "bicycle", # "frameRange": [6, 11], # "key": "f9f03baec21e428ba04525d8df003e22" # } # ] # Merge, merges collection and given list of collections tags_vehicles = sly.PointcloudEpisodeTagCollection([tag_car, tag_bicycle]) tags_merge = sly.PointcloudEpisodeTagCollection([tag_pedestrian, tag_road]) merged_collections = tags_vehicles.merge(tags_merge) print(merged_collections.to_json()) # Output: [ # { # "frameRange": [6, 11], # "key": "a6527453a3d34e68865bc0ad4b66f673", # "name": "car" # }, # { # "frameRange": [6, 11], # "key": "e9a9a306fd9c4ea180d1edf2a6fb1cf0", # "name": "bicycle" # }, # { # "frameRange": [14, 20], # "key": "8480532ff4db4600839ab403b1d0ab85", # "name": "pedestrian" # }, # { # "frameRange": [13, 22], # "key": "828f58c0c5174dbba40f7374dcc8016a", # "name": "road" # } # ]
Methods
Add given item to collection.
Add items from given list to collection.
Makes a copy of KeyIndexedCollection with new fields, if fields are given, otherwise it will use fields of the original KeyIndexedCollection.
Find difference between collection and given list of instances.
Create a PointcloudEpisodeTagCollection object from API response data.
Convert a list with dicts in json format to
PointcloudEpisodeTagCollection
.Get item from collection with given key(name).
Get item from collection with given key(name).
Check if given key(item name exist in collection).
Find intersection of given list of instances with collection items.
Get list of all items in collection.
Get list of all keys(item names) in collection.
Merge collection with other MultiKeyIndexedCollection object.
Merge collection with other MultiKeyIndexedCollection object.
Remove items from collection by given list of keys.
Convert the
PointcloudTagCollection
to a list of json dicts.- add(item)¶
Add given item to collection.
- Parameters
- item : KeyObject
ObjClassCollection
,TagMetaCollection
orTagCollection
object.
- Returns
New instance of KeyIndexedCollection
- Return type
KeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) # Remember that KeyIndexedCollection object is immutable, and we need to assign new instance of KeyIndexedCollection to a new variable item_dog = sly.ObjClass('dog', sly.Rectangle) new_collection = collection.add(item_dog)
- add_items(items)¶
Add items from given list to collection.
- Parameters
- items : List[KeyObject]
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects.
- Returns
New instance of KeyIndexedCollection
- Return type
KeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) # Remember that KeyIndexedCollection object is immutable, and we need to assign new instance of KeyIndexedCollection to a new variable item_dog = sly.ObjClass('dog', sly.Rectangle) item_mouse = sly.ObjClass('mouse', sly.Bitmap) new_collection = collection.add_items([item_dog, item_mouse])
-
clone(items=
None
)¶ Makes a copy of KeyIndexedCollection with new fields, if fields are given, otherwise it will use fields of the original KeyIndexedCollection.
- Parameters
- items : List[KeyObject], optional
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects.
- Returns
New instance of KeyIndexedCollection
- Return type
KeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) # Remember that KeyIndexedCollection object is immutable, and we need to assign new instance of KeyIndexedCollection to a new variable new_collection = collection.clone()
- difference(other)¶
Find difference between collection and given list of instances.
- Parameters
- key : List[KeyObject]
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects.
- Returns
KeyIndexedCollection object
- Return type
KeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) item_dog = sly.TagMeta('dog', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) items = [item_dog, item_turtle] diff = collection.difference(items) print(diff.to_json()) # Output: [ # { # "name": "cat", # "value_type": "none", # "color": "#8A150F", # "hotkey": "", # "applicable_type": "all", # "classes": [] # } # ]
-
classmethod from_api_response(data, tag_meta_collection, id_to_tagmeta=
None
)[source]¶ Create a PointcloudEpisodeTagCollection object from API response data.
- Parameters
- data : List[Dict]
API response data.
- tag_meta_collection : TagMetaCollection
TagMetaCollection object
- id_to_tagmeta : Optional[Dict[int, TagMeta]]
Mapping of tag IDs to tag metadata.
- Returns
PointcloudEpisodeTagCollection object.
- Return type
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() project_id = 18428 pcd_id = 19481209 project_meta_json = api.project.get_meta(project_id) project_meta = sly.ProjectMeta.from_json(project_meta_json) pcd_info = api.pointcloud_episode.get_info_by_id(pcd_id) tag_collection = sly.PointcloudEpisodeTagCollection.from_api_response( pcd_info.tags, project_meta.tag_metas ) print(tag_collection) # Output: # Tags: # +-------+--------------+-------+ # | Name | Value type | Value | # +-------+--------------+-------+ # | color | oneof_string | red | # | car | none | None | # +-------+--------------+-------+
-
classmethod from_json(data, tag_meta_collection, key_id_map=
None
)[source]¶ Convert a list with dicts in json format to
PointcloudEpisodeTagCollection
. Read more about Supervisely format.- Parameters
- data :
List[Dict]
List with dicts in json format.
- tag_meta_collection :
TagMetaCollection
TagMetaCollection object.
- key_id_map :
KeyIdMap
, optional KeyIdMap object.
- data :
- Returns
TagCollection object.
- Return type
- Usage example
import supervisely as sly # Initialize TagMetaCollection meta_weather = sly.TagMeta('Weather', sly.TagValueType.ANY_STRING) seasons = ["Winter", "Spring", "Summer", "Autumn"] meta_season = sly.TagMeta('Season', sly.TagValueType.ONEOF_STRING, possible_values=seasons) metas_arr = [meta_weather, meta_season] tag_metas = sly.TagMetaCollection(metas_arr) data = [ { "name":"Weather", "value":"Sunny" }, { "name":"Season", "value":"Spring" } ] tags = sly.PointcloudEpisodeTagCollection.from_json(data, tag_metas)
-
get(key, default=
None
)¶ Get item from collection with given key(name). If there are many values for the same key, the first value will be returned.
- Parameters
- items : str
Name of KeyObject in collection.
- default : optional
The value that is returned if there is no key in the collection.
- Returns
ObjClassCollection
,TagMetaCollection
orTagCollection
object- Return type
KeyObject
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) item = collection.get('cat') print(item) # Output: # Name: cat Value type:none Possible values:None Hotkey Applicable toall Applicable classes[]
-
get_all(key, default=
[]
)¶ Get item from collection with given key(name). If there are many values for the same key,all values will be returned by list.
- Parameters
- items : str
Name of KeyObject in collection.
- default : List, optional
The value that is returned if there is no key in the collection.
- Returns
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects or empty list- Return type
List[KeyObject]
orlist
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) items = collection.get('cat') print(items) # Output: # [<supervisely.annotation.tag_meta.TagMeta object at 0x7f0278662340>, <supervisely.annotation.obj_class.ObjClass object at 0x7f02786623a0>]
- has_key(key)¶
Check if given key(item name exist in collection).
- Parameters
- key : str
The key to look for in the collection.
- Returns
Is the key in the collection or not
- Return type
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) collection.has_key('cat') # True collection.has_key('hamster') # False
- intersection(other)¶
Find intersection of given list of instances with collection items.
- Parameters
- key : List[KeyObject]
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects.
- Raises
ValueError
if find items with same keys(item names)- Returns
MultiKeyIndexedCollection object
- Return type
MultiKeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) # Note, item_cat_2 have same key as item_cat, but another value item_cat_2 = sly.TagMeta('cat', sly.TagValueType.ANY_STRING) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) items = [item_cat_2, item_turtle] intersect = collection.intersection(items) print(intersect.to_json()) # Output: [ # { # "name": "turtle", # "value_type": "any_string", # "color": "#5B8A0F", # "hotkey": "", # "applicable_type": "all", # "classes": [] # } # ]
- items()¶
Get list of all items in collection.
- Returns
List of
ObjClassCollection
,TagMetaCollection
orTagCollection
objects- Return type
List[KeyObject]
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) print(collection.items()) # Output: # [<supervisely.annotation.tag_meta.TagMeta object at 0x7fdbd28ce340>, # <supervisely.annotation.obj_class.ObjClass object at 0x7fdbd28ce3a0>, # <supervisely.annotation.tag_meta.TagMeta object at 0x7fdbd28ce370>]
- keys()¶
Get list of all keys(item names) in collection.
- Returns
List of collection keys
- Return type
List[str]
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) collection = sly.collection.key_indexed_collection.KeyIndexedCollection([item_cat, item_turtle]) keys = collection.keys() # ['cat', 'turtle']
- merge(other)¶
Merge collection with other MultiKeyIndexedCollection object.
- Parameters
- key : MultiKeyIndexedCollection
MultiKeyIndexedCollection object.
- Returns
MultiKeyIndexedCollection object
- Return type
MultiKeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) item_dog = sly.TagMeta('dog', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_dog, item_turtle]) merge = collection.merge(other_collection) print(merge.to_json()) # Output: [ # { # "name": "cat", # "value_type": "none", # "color": "#198A0F", # "hotkey": "", # "applicable_type": "all", # "classes": [] # }, # { # "title": "cat", # "shape": "rectangle", # "color": "#898A0F", # "geometry_config": {}, # "hotkey": "" # }, # { # "name": "turtle", # "value_type": "any_string", # "color": "#650F8A", # "hotkey": "", # "applicable_type": "all", # "classes": [] # }, # { # "name": "turtle", # "value_type": "any_string", # "color": "#0F8A83", # "hotkey": "", # "applicable_type": "all", # "classes": [] # }, # { # "name": "dog", # "value_type": "none", # "color": "#1A8A0F", # "hotkey": "", # "applicable_type": "all", # "classes": [] # } # ]
- merge_without_duplicates(other)¶
Merge collection with other MultiKeyIndexedCollection object. Duplicates will be ignored.
- Parameters
- key : MultiKeyIndexedCollection
MultiKeyIndexedCollection object.
- Raises
ValueError
if item name from given MultiKeyIndexedCollection is in collection but items in both are different- Returns
MultiKeyIndexedCollection object
- Return type
MultiKeyIndexedCollection
- Usage Example
import supervisely as sly item_cat = sly.TagMeta('cat', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_cat = sly.ObjClass('cat', sly.Rectangle) collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_cat, item_turtle, other_cat]) item_dog = sly.TagMeta('dog', sly.TagValueType.NONE) item_turtle = sly.TagMeta('turtle', sly.TagValueType.ANY_STRING) other_collection = sly.collection.key_indexed_collection.MultiKeyIndexedCollection([item_dog, item_turtle]) merge = collection.merge_without_duplicates(other_collection) print(merge.to_json()) # Output: [ # { # "name": "dog", # "value_type": "none", # "color": "#8A0F37", # "hotkey": "", # "applicable_type": "all", # "classes": [] # }, # { # "name": "cat", # "value_type": "none", # "color": "#778A0F", # "hotkey": "", # "applicable_type": "all", # "classes": [] # }, # { # "title": "cat", # "shape": "rectangle", # "color": "#8A0F76", # "geometry_config": {}, # "hotkey": "" # }, # { # "name": "turtle", # "value_type": "any_string", # "color": "#850F8A", # "hotkey": "", # "applicable_type": "all", # "classes": [] # } # ]
- remove_items(keys)¶
Remove items from collection by given list of keys. Creates a new instance of KeyIndexedCollection.
- Parameters
- keys : List[str]
List of keys(item names) in collection.
- Returns
New instance of KeyIndexedCollection
- Return type
KeyIndexedCollection
-
to_json(key_id_map=
None
)¶ Convert the
PointcloudTagCollection
to a list of json dicts. Read more about Supervisely format.- Parameters
- key_id_map :
KeyIdMap
, optional KeyIdMap object.
- key_id_map :
- Returns
List of dicts in json format
- Return type
List[dict]
- Usage example
import supervisely as sly meta_weather = sly.TagMeta('Weather', sly.TagValueType.ANY_STRING) seasons = ["Winter", "Spring", "Summer", "Autumn"] meta_season = sly.TagMeta('Season', sly.TagValueType.ONEOF_STRING, possible_values=seasons) tag_weather = sly.PointcloudTag(meta_weather, value="Sunny") tag_season = sly.PointcloudTag(meta_season, value="Spring") tags_arr = [tag_weather, tag_season] tags = sly.PointcloudTagCollection(tags_arr) tags_json = tags.to_json() # Output: [ # { # "name":"Weather", # "value":"Sunny", # "key": "058ad7993a534082b4d94cc52542a97d" # }, # { # "name":"Season", # "value":"Spring", # "key": "0c0033c5b4834d4cbabece4317295f07" # } # ]