PointcloudTagCollection¶
-
class PointcloudTagCollection(items=
None)[source]¶ Bases:
TagCollectionCollection with
PointcloudTaginstances.PointcloudTagCollectionobject is immutable.- Usage Example:
import supervisely as sly # Create TagMetas (see class TagMeta for additional information about creating TagMetas) 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) # Create Pointcloud Tags tag_weather = sly.PointcloudTag(meta_weather, value="Sunny") tag_season = sly.PointcloudTag(meta_season, value="Spring") tags_arr = [tag_weather, tag_season] # Create PointcloudTagCollection from Pointcloud Tags tags = sly.PointcloudTagCollection(tags_arr) # Add item to PointcloudTagCollection meta_potato = sly.TagMeta('potato', sly.TagValueType.NONE) tag_potato = sly.PointcloudTag(meta_potato) # Remember that PointcloudTagCollection is immutable, and we need to assign new instance of PointcloudTagCollection to a new variable tags = tags.add(tag_potato) # You can also add multiple items to collection meta_cabbage = sly.TagMeta('cabbage', sly.TagValueType.NONE) meta_carrot = sly.TagMeta('carrot', sly.TagValueType.NONE) meta_turnip = sly.TagMeta('turnip', sly.TagValueType.NONE) tag_cabbage = sly.PointcloudTag(meta_cabbage) tag_carrot = sly.PointcloudTag(meta_carrot) tag_turnip = sly.PointcloudTag(meta_turnip) additional_veggies = [tag_cabbage, tag_carrot, tag_turnip] tags = tags.add_items(additional_veggies) # Has key, checks if given key exist in collection tags.has_key(tag_cabbage.key()) # Output: True # Intersection, finds intersection of given list of instances with collection items meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE) tag_dog = sly.PointcloudTag(meta_dog) meta_cat = sly.TagMeta('cat', sly.TagValueType.NONE) tag_cat = sly.PointcloudTag(meta_cat) meta_turtle = sly.TagMeta('turtle', sly.TagValueType.NONE) tag_turtle = sly.PointcloudTag(meta_turtle) tags_animals = sly.PointcloudTagCollection([tag_dog, tag_cat, tag_turtle]) tags_intersections = tags.intersection(tags_animals) print(tags_intersections.to_json()) # Output: [] # Let's add the potato Tag from another collection and compare them again tags_animals = tags_animals.add(tag_potato) tags_intersections = tags.intersection(tags_animals) print(tags_intersections.to_json()) # Output: [ # { # "name":"potato", # "key": "058ad7993a534082b4d94cc52542a97d" # } # ] # Difference, finds difference between collection and given list of Tags or TagCollection meta_car = sly.TagMeta('car', sly.TagValueType.NONE) tag_car = sly.Tag(meta_car) meta_bicycle = sly.TagMeta('bicycle', sly.TagValueType.NONE) tag_bicycle = sly.PointcloudTag(meta_bicycle) tags_vehicles = sly.PointcloudTagCollection([tag_car, tag_bicycle]) meta_pedestrian = sly.TagMeta('pedestrian', sly.TagValueType.NONE) tag_pedestrian = sly.PointcloudTag(meta_pedestrian) meta_road = sly.TagMeta('road', sly.TagValueType.NONE) tag_road = sly.PointcloudTag(meta_road) difference = tags_vehicles.difference([tag_pedestrian, tag_road]) print(difference.to_json()) # Output: [ # { # "name": "car", # "key": "058ad7993a534082b4d94cc52542a97d" # }, # { # "name": "bicycle", # "key": ""0c0033c5b4834d4cbabece4317295f07" # } # ] # Merge, merges collection and given list of TagMetas tags_vehicles = sly.TagMetaCollection([tag_car, tag_bicycle]) tags_merge = sly.TagMetaCollection([tag_pedestrian, tag_road]) merged_collections = tags_vehicles.merge(tags_merge) print(merged_collections.to_json()) # Output: [ # { # "name":"pedestrian" # }, # { # "name":"road" # }, # { # "name":"car" # }, # { # "name":"bicycle" # } # ]- Parameters:
:raises
DuplicateKeyError: if instance with given name already exist- Usage Example:
import supervisely as sly # Create TagMetas (see class TagMeta for additional information about creating TagMetas) 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) # Create Tags tag_weather = sly.Tag(meta_weather, value="Sunny") tag_season = sly.Tag(meta_season, value="Spring") tags_arr = [tag_weather, tag_season] # Create TagCollection from Tags tags = sly.TagCollection(tags_arr) # Add item to TagCollection meta_potato = sly.TagMeta('potato', sly.TagValueType.NONE) tag_potato =sly.Tag(meta_potato) # Remember that TagCollection is immutable, and we need to assign new instance of TagCollection to a new variable tags = tags.add(tag_potato) # You can also add multiple items to collection meta_cabbage = sly.TagMeta('cabbage', sly.TagValueType.NONE) meta_carrot = sly.TagMeta('carrot', sly.TagValueType.NONE) meta_turnip = sly.TagMeta('turnip', sly.TagValueType.NONE) tag_cabbage = sly.Tag(meta_cabbage) tag_carrot = sly.Tag(meta_carrot) tag_turnip = sly.Tag(meta_turnip) additional_veggies = [tag_cabbage, tag_carrot, tag_turnip] tags = tags.add_items(additional_veggies) # Has key, checks if given key exist in collection tags.has_key("cabbage") # Output: True # Find intersection of given list of instances with collection items meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE) tag_dog = sly.Tag(meta_dog) meta_cat = sly.TagMeta('cat', sly.TagValueType.NONE) tag_cat = sly.Tag(meta_cat) meta_turtle = sly.TagMeta('turtle', sly.TagValueType.NONE) tag_turtle = sly.Tag(meta_turtle) tags_animals = sly.TagCollection([tag_dog, tag_cat, tag_turtle]) tags_intersections = tags.intersection(tags_animals) print(tags_intersections.to_json()) # Output: [] # Let's add the potato Tag from another collection and compare them again tags_animals = tags_animals.add(tag_potato) tags_intersections = tags.intersection(tags_animals) print(tags_intersections.to_json()) # Output: [ # { # "name":"potato" # } # ] # Find difference between collection and given list of Tags or TagCollection meta_car = sly.TagMeta('car', sly.TagValueType.NONE) tag_car = sly.Tag(meta_car) meta_bicycle = sly.TagMeta('bicycle', sly.TagValueType.NONE) tag_bicycle = sly.Tag(meta_bicycle) tags_vehicles = sly.TagCollection([tag_car, tag_bicycle]) meta_pedestrian = sly.TagMeta('pedestrian', sly.TagValueType.NONE) tag_pedestrian = sly.Tag(meta_pedestrian) meta_road = sly.TagMeta('road', sly.TagValueType.NONE) tag_road = sly.Tag(meta_road) difference = tags_vehicles.difference([tag_pedestrian, tag_road]) print(difference.to_json()) # Output: [ # { # "name":"car" # }, # { # "name":"bicycle" # } # ] # Merge collection and given list of TagMetas tags_vehicles = sly.TagMetaCollection([tag_car, tag_bicycle]) tags_merge = sly.TagMetaCollection([tag_pedestrian, tag_road]) merged_collections = tags_vehicles.merge(tags_merge) print(merged_collections.to_json()) # Output: [ # { # "name":"pedestrian" # }, # { # "name":"road" # }, # { # "name":"car" # }, # { # "name":"bicycle" # } # ]
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 TagCollection object from API response data.
Convert a list with dictionaries in json format to
PointcloudTagCollection.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
PointcloudTagCollectionto a list of json dicts.- item_type¶
alias of
PointcloudTag
-
classmethod from_api_response(data, tag_meta_collection, id_to_tagmeta=
None)¶ Create a TagCollection object from API response data.
- Parameters:
- Returns:
TagCollection object.
- Return type:
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() project_id = 17200 image_id = 19369643 project_meta_json = api.project.get_meta(project_id) project_meta = sly.ProjectMeta.from_json(project_meta_json) image_info = api.image.get_info_by_id(image_id) tag_collection = sly.TagCollection.from_api_response( image_info.tags, project_meta.tag_metas ) print(tag_collection) # Output: # Tags: # +-------+--------------+-------+ # | Name | Value type | Value | # +-------+--------------+-------+ # | Lemon | oneof_string | big | # | Kiwi | none | None | # +-------+--------------+-------+
-
classmethod from_json(data, tag_meta_collection, key_id_map=
None)[source]¶ Convert a list with dictionaries in json format to
PointcloudTagCollection. Read more about Supervisely format.- Parameters:
- Returns:
Pointcloud tag collection.
- 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.PointcloudTagCollection.from_json(data, tag_metas)
- add(item)¶
Add given item to collection.
- Parameters:
- item¶
ObjClassCollection, TagMetaCollection orTagCollectionobject.
- Returns:
New instance of
KeyIndexedCollection- 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]) # 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 of
ObjClassCollection, TagMetaCollection orTagCollectionobjects.
- Returns:
New instance of
KeyIndexedCollection- 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]) # 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=
None¶ List of
ObjClassCollection, TagMetaCollection orTagCollectionobjects.
- items=
- Returns:
New instance of
KeyIndexedCollection- 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]) # 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:
- other¶
List of items to subtract from the collection.
- Returns:
KeyIndexedCollectionobject- 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]) 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": [] # } # ]
-
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:
- Returns:
ObjClassCollection, TagMetaCollection orTagCollectionobject- 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) 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:
- Returns:
List of
ObjClassCollection, TagMetaCollection orTagCollectionobjects or empty list- Return type:
List[
KeyObject] or list- 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:
- 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:
- other¶
List of items to intersect with the collection.
- Raises:
ValueError – if find items with same keys(item names)
- Returns:
MultiKeyIndexedCollectionobject- 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) 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 orTagCollectionobjects- 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:
- other¶
Other multi key indexed collection object.
- Returns:
Merged multi key indexed collection object
- 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) 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:
- other¶
Other multi key indexed collection object.
- Raises:
ValueError – if item name from given
MultiKeyIndexedCollectionis in collection but items in both are different- Returns:
MultiKeyIndexedCollection object
- 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) 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:
- Returns:
New instance of
KeyIndexedCollection- Return type:
-
to_json(key_id_map=
None)[source]¶ Convert the
PointcloudTagCollectionto a list of json dicts. Read more about Supervisely format.- Parameters:
- key_id_map=
None¶ Key ID map.
- key_id_map=
- Returns:
List of dictionaries 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" # } # ]