TagMeta¶
-
class TagMeta(name, value_type, possible_values=
None, color=None, sly_id=None, hotkey=None, applicable_to=None, applicable_classes=None, target_type=None)[source]¶ Bases:
KeyObject,JsonSerializableTag metadata: name, value type (NONE, ANY_STRING, DATE, etc.), optional possible values. Immutable.
- Parameters:
- name : str¶
Tag name.
- value_type : str¶
TagValueType: NONE, ANY_STRING, ANY_NUMBER, ONEOF_STRING, DATE.
- possible_values : List[str], optional¶
Required for ONEOF_STRING; list of allowed values.
- color : List[int, int, int], optional¶
RGB color [R, G, B]. Random if not provided.
- sly_id : int, optional¶
Server-side tag meta ID.
- hotkey : str, optional¶
Hotkey in annotation UI.
- applicable_to : str, optional¶
TagApplicableTo: ALL, IMAGES_ONLY, OBJECTS_ONLY.
- applicable_classes : List[str], optional¶
Restrict to specific class names.
- target_type : str, optional¶
TagTargetType: ALL, FRAME_BASED, GLOBAL.
- Raises:
ValueError – If value_type or color is invalid; ONEOF_STRING requires possible_values.
- Usage Example:
import supervisely as sly meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE) meta_cat = sly.TagMeta('cat', sly.TagValueType.ANY_STRING, applicable_to=sly.TagApplicableTo.OBJECTS_ONLY) colors = ["brown", "white", "black"] meta_coat = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=colors, color=[255, 120, 0])
Methods
Adds a new value to the list of possible values.
Clone makes a copy of TagMeta with new fields, if fields are given, otherwise it will use original TagMeta fields.
Convert a json dict to TagMeta.
get_header_ptable
get_row_ptable
Check if the current TagMeta instance is compatible with another TagMeta instance.
Checks value against object value type to make sure that value is valid.
keyConvert the TagMeta to a json dict.
Attributes
Applicable classes.
Tag applicability to objects, images, or both.
[R,G,B]color.Hotkey for Tag in annotation tool UI.
Name.
Possible values of object.
Tag ID in Supervisely server.
Tag target type (scope) - entities, frames or both.
Value type.
- classmethod from_json(data)[source]¶
Convert a json dict to TagMeta. Read more about Supervisely format.
- Parameters:
- Returns:
TagMeta object
- Return type:
- Usage Example:
import supervisely as sly data = { "name":"Color", "value_type":"oneof_string", "color":"#FF7800", "values":[ "brown", "white", "black", "red", "blue", "yellow", "grey" ], "hotkey":"M", "applicable_type":"all", "classes":[ "car", "bicycle" ] } meta_colors = sly.TagMeta.from_json(data)
- add_possible_value(value)[source]¶
Adds a new value to the list of possible values.
- Parameters:
- Raises:
ValueError – if object’s value type is not “oneof_string” or already exists in a list
- Returns:
New instance of TagMeta object
- Return type:
- Usage Example:
import supervisely as sly #In order to add possible values, you must first initialize a variable where all possible values will be stored if it doesnt exist already colors = ["brown", "white", "black", "red", "chocolate", "gold", "grey"] meta_coat_color = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=colors, applicable_classes=["dog", "cat"]) print(meta_coat_color.possible_values) # Output: ['brown', 'white', 'black', 'red', 'chocolate', 'gold', 'grey'] #Now we can add new possible value to our TagMeta # Remember that TagMeta object is immutable, and we need to assign new instance of TagMeta to a new variable meta_coat_color = meta_coat_color.add_possible_value("bald (no coat)") print(meta_coat_color.possible_values) # Output: ['brown', 'white', 'black', 'red', 'chocolate', 'gold', 'grey', 'bald (no coat)']
-
clone(name=
None, value_type=None, possible_values=None, color=None, sly_id=None, hotkey=None, applicable_to=None, applicable_classes=None, target_type=None)[source]¶ Clone makes a copy of TagMeta with new fields, if fields are given, otherwise it will use original TagMeta fields.
- Parameters:
- name : str¶
Tag name.
- value_type : str¶
Tag value type.
- possible_values : List[str], optional¶
List of possible values.
- color : List[int, int, int], optional¶
[R, G, B] color, generates random color by default.
- sly_id : int, optional¶
Tag ID in Supervisely server.
- hotkey : str, optional¶
Hotkey for Tag in annotation tool UI.
- applicable_to : str, optional¶
Defines applicability of Tag only to images, objects or both.
- applicable_classes : List[str], optional¶
Defines applicability of Tag only to certain classes.
- Returns:
New instance of TagMeta object
- Return type:
- Usage Example:
import supervisely as sly #Original TagMeta meta_dog_breed = sly.TagMeta('breed', sly.TagValueType.NONE) # TagMetas made of original TagMeta # Remember that TagMeta class object is immutable, and we need to assign new instance of TagMeta to a new variable A_breeds = ["Affenpinscher", "Afghan Hound", "Aidi", "Airedale Terrier", "Akbash Dog", "Akita"] meta_A_breed = meta_dog_breed.clone(value_type=sly.TagValueType.ONEOF_STRING, possible_values=A_breeds, hotkey='A') B_breeds = ["Basset Fauve de Bretagne", "Basset Hound", "Bavarian Mountain Hound", "Beagle", "Beagle-Harrier", "Bearded Collie"] meta_B_breed = meta_A_breed.clone(possible_values=B_breeds, hotkey='B') C_breeds = ["Cairn Terrier", "Canaan Dog", "Canadian Eskimo Dog", "Cane Corso", "Cardigan Welsh Corgi", "Carolina Dog"] meta_C_breed = meta_B_breed.clone(possible_values=C_breeds, hotkey='C')
- is_compatible(other)[source]¶
Check if the current TagMeta instance is compatible with another TagMeta instance.
- is_valid_value(value)[source]¶
Checks value against object value type to make sure that value is valid.
- Parameters:
- Returns:
True if value is supported, otherwise False
- Return type:
- Usage Example:
import supervisely as sly # Initialize TagMeta meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) # Check what value type is in our Tagmeta print(meta_dog.value_type) # Output: 'any_string' # Our TagMeta has 'any_string' value type, it means only 'string' values will work with it # Let's check if value is valid for our TagMeta meta_dog.is_valid_value('Woof!') # True meta_dog.is_valid_value(555) # False # TagMetas with 'any_number' value type are compatible with 'int' and 'float' values meta_quantity = sly.TagMeta('quantity', sly.TagValueType.ANY_NUMBER) meta_quantity.is_valid_value('new string value') # False meta_quantity.is_valid_value(555) # True meta_quantity.is_valid_value(3.14159265359) # True
- to_json()[source]¶
Convert the TagMeta to a json dict. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
- Usage Example:
import supervisely as sly colors = ["brown", "white", "black", "red", "blue", "yellow", "grey"] meta_color = sly.TagMeta( 'Color', sly.TagValueType.ONEOF_STRING, possible_values=colors, color=[255, 120, 0], hotkey="M", applicable_classes=["car", "bicycle"] ) meta_color_json = meta_color.to_json() print(meta_color_json) # Output: { # "name":"Color", # "value_type":"oneof_string", # "color":"#FF7800", # "values":[ # "brown", # "white", # "black", # "red", # "blue", # "yellow", # "grey" # ], # "hotkey":"M", # "applicable_type":"all", # "classes":[ # "car", # "bicycle" # ] # }
- property applicable_classes : list[str]¶
Applicable classes.
- Returns:
List of applicable classes
- Return type:
List[str]- Usage Example:
# Imagine we have 2 ObjClasses in our Project class_car = sly.ObjClass(name='car', geometry_type='rectangle') class_bicycle = sly.ObjClass(name='bicycle', geometry_type='rectangle') # You can put a "string" with ObjClass name or use ObjClass.name meta_vehicle = sly.TagMeta('vehicle', sly.TagValueType.NONE, applicable_classes=["car", class_bicycle.name]) print(meta_vehicle.applicable_classes) # Output: ['car', 'bicycle']
- property applicable_to : str¶
Tag applicability to objects, images, or both.
- Returns:
Applicability
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE, applicable_to=IMAGES_ONLY) print(meta_dog.applicable_to) # Output: 'imagesOnly'
- property color : list[int, int, int]¶
[R,G,B]color.- Returns:
Color
- Return type:
List[int, int, int]- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE, color=[255,120,0]) print(meta_dog.color) # Output: [255,120,0]
- property hotkey : str¶
Hotkey for Tag in annotation tool UI.
- Returns:
Hotkey
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE, hotkey='M') print(meta_dog.hotkey) # Output: 'M'
- property name : str¶
Name.
- Returns:
Name
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) print(meta_dog.name) # Output: 'dog'
- property possible_values : list[str]¶
Possible values of object. This is a required field if object has “oneof_string” value type.
- Raises:
ValueError – if list of possible values is not defined or TagMeta value_type is not “oneof_string”.
- Returns:
List of possible values
- Return type:
List[str]- Usage Example:
# List of possible values coat_colors = ["brown", "white", "black", "red", "chocolate", "gold", "grey"] # TagMeta meta_coat_color = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=coat_colors) print(meta_coat_color.possible_values) # Output: ['brown', 'white', 'black', 'red', 'chocolate', 'gold', 'grey'] # Note that this is a required field if object has "oneof_string" value type. meta_coat_color = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING) # Output: ValueError: TagValueType is ONEOF_STRING. List of possible values have to be defined.
- property sly_id : int¶
Tag ID in Supervisely server.
- Returns:
ID
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE, sly_id=38584) print(meta_dog.sly_id) # Output: 38584
- property target_type : str¶
Tag target type (scope) - entities, frames or both.
- Returns:
Target type
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE, target_type=TagTargetType.FRAME_BASED) print(meta_dog.target_type) # Output: 'framesOnly'
- property value_type : str¶
Value type. See possible value types in
TagValueType.- Returns:
Value type
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) meta_dog.value_type == sly.TagValueType.ANY_STRING # True print(meta_dog.value_type) # Output: 'any_string'