PointcloudTagCollection¶
- class PointcloudTagCollection[source]¶
Bases:
supervisely.annotation.tag_collection.TagCollection
Collection with
PointcloudTag
instances.PointcloudTagCollection
object 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" # } # ]
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 dicts 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
PointcloudTagCollection
to a list of json dicts.- item_type¶
alias of
supervisely.pointcloud_annotation.pointcloud_tag.PointcloudTag
- 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
)¶ Create a TagCollection 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
TagCollection 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 = 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 dicts in json format to
PointcloudTagCollection
. 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.PointcloudTagCollection.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
)[source]¶ 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" # } # ]