ProjectMeta

class ProjectMeta[source]

Bases: supervisely.io.json.JsonSerializable

General information about ProjectMeta. ProjectMeta object is immutable.

Parameters
obj_classes : ObjClassCollection or List[ObjClass], optional

ObjClassCollection or just list that stores ObjClass instances with unique names.

tag_metas : TagMetaCollection or List[TagMeta], optional

TagMetaCollection or just list that stores TagMeta instances with unique names.

project_type : ProjectType, optional

Type of items in project: images, videos, volumes, point_clouds.

project_settings : dict or ProjectSettings, optional

Additional project properties. For example, multi-view settings.

Usage example
import supervisely as sly

# Example 1: Empty ProjectMeta
meta = sly.ProjectMeta()
print(meta)
# Output:
# ProjectMeta:
# Object Classes
# +------+-------+-------+--------+
# | Name | Shape | Color | Hotkey |
# +------+-------+-------+--------+
# +------+-------+-------+--------+
# Tags
# +------+------------+-----------------+--------+---------------+--------------------+
# | Name | Value type | Possible values | Hotkey | Applicable to | Applicable classes |
# +------+------------+-----------------+--------+---------------+--------------------+
# +------+------------+-----------------+--------+---------------+--------------------+

# Example 2: Complex ProjectMeta
lemon = sly.ObjClass('lemon', sly.Rectangle)
kiwi = sly.ObjClass('kiwi', sly.Polygon)
tag_fruit = sly.TagMeta('fruit', sly.TagValueType.ANY_STRING)
objects = sly.ObjClassCollection([lemon, kiwi])
# or objects = [lemon, kiwi]
tags = sly.TagMetaCollection([tag_fruit])
# or tags = [tag_fruit]
meta = sly.ProjectMeta(obj_classes=objects, tag_metas=tags, project_type=sly.ProjectType.IMAGES)
print(meta)
# Output:
# +-------+-----------+----------------+--------+
# |  Name |   Shape   |     Color      | Hotkey |
# +-------+-----------+----------------+--------+
# | lemon | Rectangle | [108, 15, 138] |        |
# |  kiwi |  Polygon  | [15, 98, 138]  |        |
# +-------+-----------+----------------+--------+
# Tags
# +-------+------------+-----------------+--------+---------------+--------------------+
# |  Name | Value type | Possible values | Hotkey | Applicable to | Applicable classes |
# +-------+------------+-----------------+--------+---------------+--------------------+
# | fruit | any_string |       None      |        |      all      |         []         |
# +-------+------------+-----------------+--------+---------------+--------------------+

# Example 3: Add multi-view to the project

lemon = sly.ObjClass('lemon', sly.Rectangle)
kiwi = sly.ObjClass('kiwi', sly.Polygon)
tag_fruit = sly.TagMeta('fruit', sly.TagValueType.ANY_STRING)

settings = sly.ProjectSettings(
    multiview_enabled=True,
    multiview_tag_name=tag_fruit.name,
    multiview_is_synced=False,
)
meta = sly.ProjectMeta(
    obj_classes=[lemon, kiwi],
    tag_metas=tag_fruit,
    project_type=sly.ProjectType.IMAGES,
    project_settings=settings
)

# Example 4: Custom color
cat_class = sly.ObjClass("cat", sly.Rectangle, color=[0, 255, 0])
scene_tag = sly.TagMeta("scene", sly.TagValueType.ANY_STRING)
meta = sly.ProjectMeta(obj_classes=[cat_class], tag_metas=[scene_tag])

Methods

add_obj_class

Adds given ObjClass to ProjectMeta.

add_obj_classes

Adds given ObjClasses to ProjectMeta.

add_tag_meta

Adds given TagMeta to ProjectMeta.

add_tag_metas

Adds given TagMetas to ProjectMeta.

clone

Clone makes a copy of ProjectMeta with new fields, if fields are given, otherwise it will use original ProjectMeta fields.

delete_obj_class

Removes given ObjClass by name from ProjectMeta.

delete_obj_classes

Removes given ObjClasses by names from ProjectMeta.

delete_tag_meta

Removes given TagMeta by name from ProjectMeta.

delete_tag_metas

Removes given TagMetas by names from ProjectMeta.

from_json

Convert a json dict to ProjectMeta.

get_obj_class

Get given ObjClass by name from ProjectMeta.

get_obj_class_by_id

Get given ObjClass by name from ProjectMeta.

get_tag_meta

Get given TagMeta by name from ProjectMeta.

get_tag_meta_by_id

Return TagMeta with given id.

get_tag_name_by_id

Return tag name with given id.

merge

Merge all instances from given ProjectMeta into a single ProjectMeta object.

merge_list

Merge ProjectMetas from given list of ProjectMetas into single ProjectMeta object.

to_detection_task

Convert project meta classes geometries to Rectangles or skip them and create new ProjectMeta.

to_json

Convert the ProjectMeta to a json dict.

to_segmentation_task

Convert project meta classes geometries with keep_geometries types to Bitmaps and create new ProjectMeta.

Attributes

obj_classes

Collection of ObjClasses in ProjectMeta.

project_settings

Settings of the project.

project_type

Type of project.

tag_metas

Collection of TagMetas in ProjectMeta.

add_obj_class(new_obj_class)[source]

Adds given ObjClass to ProjectMeta.

Parameters
new_obj_class : ObjClass

ObjClass object.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_obj_class(class_cat)
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#178A0F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }
add_obj_classes(new_obj_classes)[source]

Adds given ObjClasses to ProjectMeta.

Parameters
new_obj_classes : ObjClassCollection or List[ObjClass]

List of ObjClass objects.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
class_dog = sly.ObjClass('dog', sly.Bitmap)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_obj_classes([class_cat, class_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#8A0F3F",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#8A0F56",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }
add_tag_meta(new_tag_meta)[source]

Adds given TagMeta to ProjectMeta.

Parameters
new_tag_meta : TagMeta

TagMeta object.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_tag_meta(tag_cat)
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#178A0F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
add_tag_metas(new_tag_metas)[source]

Adds given TagMetas to ProjectMeta.

Parameters
new_tag_metas : List[TagMeta]

List of TagMeta objects.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
tag_dog = sly.TagMeta('dog_tag', sly.TagValueType.ANY_STRING)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_tag_metas([tag_cat, tag_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#0F248A",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         },
#         {
#             "name": "dog_tag",
#             "value_type": "any_string",
#             "color": "#8A5C0F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
clone(obj_classes=None, tag_metas=None, project_type=None, project_settings=None)[source]

Clone makes a copy of ProjectMeta with new fields, if fields are given, otherwise it will use original ProjectMeta fields.

Parameters
obj_classes : ObjClassCollection or List[ObjClass], optional

ObjClassCollection or just list that stores ObjClass instances with unique names.

tag_metas : TagMetaCollection or List[TagMeta], optional

TagMetaCollection that stores TagMeta instances with unique names.

project_type : str, optional

Type of items in project: images, videos, volumes, point_clouds.

project_settings : dict or ProjectSettings, optional

Additional project properties. For example, multi-view settings

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
collection_cat = sly.ObjClassCollection([class_cat])
# or collection_cat = [class_cat]
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
collection_tag_cat = sly.TagMetaCollection([tag_cat])
# or collection_tag_cat = [tag_cat]
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
new_meta = meta.clone(obj_classes=collection_cat, tag_metas=collection_tag_cat)
new_meta_json = new_meta.to_json()
print(json.dumps(new_meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#190F8A",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#8A6D0F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
delete_obj_class(obj_class_name)[source]

Removes given ObjClass by name from ProjectMeta.

Parameters
obj_class_name : str

ObjClass name.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_obj_class(class_cat)
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#268A0F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }

# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.delete_obj_class('cat')
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": []
# }
delete_obj_classes(obj_class_names)[source]

Removes given ObjClasses by names from ProjectMeta.

Parameters
obj_class_names : List[str]

List of ObjClasses names.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
class_dog = sly.ObjClass('dog', sly.Bitmap)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_obj_classes([class_cat, class_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#8A0F18",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#0F8A7F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }

# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.delete_obj_classes(['cat', 'dog'])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": []
# }
delete_tag_meta(tag_name)[source]

Removes given TagMeta by name from ProjectMeta.

Parameters
tag_name : str

TagMeta name.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_tag_meta(tag_cat)
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#8A540F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }

# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.delete_tag_meta('cat_tag')
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": []
# }
delete_tag_metas(tag_names)[source]

Removes given TagMetas by names from ProjectMeta.

Parameters
tag_names : List[TagMeta]

List of TagMetas names.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
tag_dog = sly.TagMeta('dog_tag', sly.TagValueType.ANY_STRING)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_tag_metas([tag_cat, tag_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#0F298A",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         },
#         {
#             "name": "dog_tag",
#             "value_type": "any_string",
#             "color": "#8A410F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }

# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.delete_tag_metas(['cat_tag', 'dog_tag'])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": []
# }
classmethod from_json(data)[source]

Convert a json dict to ProjectMeta. Read more about Supervisely format.

Parameters
data : dict

ProjectMeta in json format as a dict.

Returns

ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta_json = {
    "classes": [
        {
            "title": "lemon",
            "shape": "rectangle",
            "color": "#8A0F7B"
        },
        {
            "title": "kiwi",
            "shape": "polygon",
            "color": "#8A0F50"
        }
    ],
    "tags": [
        {
            "name": "fruit",
            "value_type": "any_string",
            "color": "#0F6F8A"
        }
    ]
}
meta = sly.ProjectMeta.from_json(meta_json)
get_obj_class(obj_class_name)[source]

Get given ObjClass by name from ProjectMeta.

Parameters
obj_class_name : str

ObjClass name.

Returns

ObjClass object

Return type

ObjClass

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
class_dog = sly.ObjClass('dog', sly.Bitmap)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_obj_classes([class_cat, class_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#8A140F",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#0F8A35",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }

class_cat = meta.get_obj_class('cat')
print(class_cat)
# Output:
# Name:  cat       Shape: Rectangle    Color: [138, 20, 15]  Geom. settings: {}              Hotkey

class_elephant = meta.get_obj_class('elephant')
print(class_elephant)
# Output:
# None
get_obj_class_by_id(obj_class_id)[source]

Get given ObjClass by name from ProjectMeta.

Parameters
obj_class_id : int

ObjClass id.

Returns

ObjClass object or None

Return type

ObjClass

Usage example
import supervisely as sly

meta = sly.ProjectMeta.from_json(api.project.get_meta(project_id))

obj_class_id = 123
get_tag_meta(tag_name)[source]

Get given TagMeta by name from ProjectMeta.

Parameters
tag_name : str

TagMeta name.

Returns

TagMeta object or None.

Return type

TagMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
tag_dog = sly.TagMeta('dog_tag', sly.TagValueType.ANY_STRING)
# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.add_tag_metas([tag_cat, tag_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [],
#     "tags": [
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#590F8A",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         },
#         {
#             "name": "dog_tag",
#             "value_type": "any_string",
#             "color": "#0F8A88",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }

tag_cat = meta.get_tag_meta('cat_tag')
print(tag_cat)
# Output:
# Name:  cat_tag                  Value type:any_string    Possible values:None       Hotkey                  Applicable toall        Applicable classes[]

tag_elephant = meta.get_tag_meta('elephant_tag')
print(tag_elephant)
# Output:
# None
get_tag_meta_by_id(tag_id)[source]

Return TagMeta with given id.

Parameters
tag_id : int

TagMeta id to search for.

Returns

TagMeta with given id.

Return type

TagMeta or None

get_tag_name_by_id(tag_id)[source]

Return tag name with given id.

Parameters
tag_id : int

TagMeta id to search for.

Returns

tag name with given id.

Return type

tag name or None

merge(other)[source]

Merge all instances from given ProjectMeta into a single ProjectMeta object.

Parameters
other : ProjectMeta

ProjectMeta object.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Raises

ValueError Upon attempt to merge metas which contain the same obj class or tag meta

Usage example
import supervisely as sly

meta_1 = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
tag_cat = sly.TagMeta('cat_tag', sly.TagValueType.ANY_STRING)
meta_1 = meta_1.add_obj_class(class_cat)
meta_1 = meta_1.add_tag_meta(tag_cat)

meta_2 = sly.ProjectMeta()
class_dog = sly.ObjClass('dog', sly.Rectangle)
tag_dog = sly.TagMeta('dog_tag', sly.TagValueType.ANY_STRING)
meta_2 = meta_2.add_obj_class(class_dog)
meta_2 = meta_2.add_tag_meta(tag_dog)

merge_meta = meta_1.merge(meta_2)
merge_meta_json = merge_meta.to_json()
print(json.dumps(merge_meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "dog",
#             "shape": "rectangle",
#             "color": "#0F8A62",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#340F8A",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": [
#         {
#             "name": "dog_tag",
#             "value_type": "any_string",
#             "color": "#380F8A",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         },
#         {
#             "name": "cat_tag",
#             "value_type": "any_string",
#             "color": "#8A0F82",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
static merge_list(metas)[source]

Merge ProjectMetas from given list of ProjectMetas into single ProjectMeta object.

Parameters
metas : List[ProjectMeta]

List of ProjectMeta objects.

Returns

New instance of ProjectMeta object

Return type

ProjectMeta

Usage example
import supervisely as sly

meta = sly.ProjectMeta()

meta_1 = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Rectangle)
meta_1 = meta_1.add_obj_class(class_cat)

meta_2 = sly.ProjectMeta()
tag_dog = sly.TagMeta('dog_tag', sly.TagValueType.ANY_STRING)
meta_2 = meta_2.add_tag_meta(tag_dog)

# Remember that ProjectMeta object is immutable, and we need to assign new instance of ProjectMeta to a new variable
meta = meta.merge_list([meta_1, meta_2])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#0F8A45",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": [
#         {
#             "name": "dog_tag",
#             "value_type": "any_string",
#             "color": "#320F8A",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
to_detection_task(convert_classes=False)[source]

Convert project meta classes geometries to Rectangles or skip them and create new ProjectMeta.

Parameters
convert_classes : bool, optional

Convert classes with no Rectangle type to Rectangle or skip them.

Returns

New project meta and dict correspondences of old classes to new

Return type

Tuple[ProjectMeta, Dict[ObjClass, ObjClass]]

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Polygon)
class_dog = sly.ObjClass('dog', sly.Bitmap)
meta = meta.add_obj_classes([class_cat, class_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "polygon",
#             "color": "#208A0F",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#8A570F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }

res_meta, mapping = meta.to_detection_task(convert_classes=True)
res_meta_json = res_meta.to_json()
print(json.dumps(res_meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "rectangle",
#             "color": "#3A0F8A",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "rectangle",
#             "color": "#8A310F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }
to_json()[source]

Convert the ProjectMeta to a json dict. Read more about Supervisely format.

Returns

Json format as a dict

Return type

dict

Usage example
meta_json = meta.to_json()
print(meta_json)
# Output: {
#     "classes": [
#         {
#             "title": "lemon",
#             "shape": "rectangle",
#             "color": "#720F8A",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "kiwi",
#             "shape": "polygon",
#             "color": "#8A0F6F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": [
#         {
#             "name": "fruit",
#             "value_type": "any_string",
#             "color": "#788A0F",
#             "hotkey": "",
#             "applicable_type": "all",
#             "classes": []
#         }
#     ]
# }
to_segmentation_task(keep_geometries=[<class 'supervisely.geometry.polygon.Polygon'>, <class 'supervisely.geometry.bitmap.Bitmap'>], target_classes=None)[source]

Convert project meta classes geometries with keep_geometries types to Bitmaps and create new ProjectMeta.

Parameters
keep_geometries : List, optional

List of geometries that can be converted.

Returns

New project meta and dict correspondences of old classes to new

Return type

Tuple[ProjectMeta, Dict[ObjClass, ObjClass]]

Usage example
import supervisely as sly

meta = sly.ProjectMeta()
class_cat = sly.ObjClass('cat', sly.Polygon)
class_dog = sly.ObjClass('dog', sly.Bitmap)
meta = meta.add_obj_classes([class_cat, class_dog])
meta_json = meta.to_json()
print(json.dumps(meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "polygon",
#             "color": "#208A0F",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#8A570F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }

res_meta, mapping = meta.to_segmentation_task()
res_meta_json = res_meta.to_json()
print(json.dumps(res_meta_json, indent=4))
# Output: {
#     "classes": [
#         {
#             "title": "cat",
#             "shape": "bitmap",
#             "color": "#208A0F",
#             "geometry_config": {},
#             "hotkey": ""
#         },
#         {
#             "title": "dog",
#             "shape": "bitmap",
#             "color": "#8A570F",
#             "geometry_config": {},
#             "hotkey": ""
#         }
#     ],
#     "tags": []
# }
property obj_classes

Collection of ObjClasses in ProjectMeta.

Returns

ObjClassCollection object

Return type

ObjClassCollection

Usage example
import supervisely as sly

lemon = sly.ObjClass('lemon', sly.Rectangle)
kiwi = sly.ObjClass('kiwi', sly.Polygon)
objects = sly.ObjClassCollection([lemon, kiwi])
# or objects = [lemon, kiwi]

meta = sly.ProjectMeta(obj_classes=objects, project_type=sly.ProjectType.IMAGES)

meta_classes = meta.obj_classes
print(meta_classes.to_json())
# Output: [
#     {
#         "title":"lemon",
#         "shape":"rectangle",
#         "color":"#6C0F8A",
#         "geometry_config":{
#
#         },
#         "hotkey":""
#     },
#     {
#         "title":"kiwi",
#         "shape":"polygon",
#         "color":"#0F628A",
#         "geometry_config":{
#
#         },
#         "hotkey":""
#     }
# ]
property project_settings

Settings of the project. See possible values in :class: ProjectSettings.

Returns

Project settings

Return type

class

Dict[str, str]

Usage example
import supervisely as sly

s = sly.ProjectSettings(
    multiview_enabled=True,
    multiview_tag_name='multi_tag',
    multiview_is_synced=False,
)
meta = sly.ProjectMeta(project_settings=s)

print(meta.project_settings)
# Output: <class 'supervisely.project.project_settings.ProjectSettings'>
property project_type

Type of project. See possible value types in ProjectType.

Returns

Project type

Return type

str

Usage example
import supervisely as sly

meta = sly.ProjectMeta(project_type=sly.ProjectType.IMAGES)

print(meta.project_type)
# Output: 'images'
property tag_metas

Collection of TagMetas in ProjectMeta.

Returns

TagMetaCollection object

Return type

TagMetaCollection

Usage example
import supervisely as sly

tag_fruit = sly.TagMeta('fruit', sly.TagValueType.ANY_STRING)
tags = sly.TagMetaCollection([tag_fruit])
# or tags = [tag_fruit]

meta = sly.ProjectMeta(tag_metas=tags)

meta_tags = meta.tag_metas
print(meta_tags.to_json())
# Output: [
#     {
#         "name":"fruit",
#         "value_type":"any_string",
#         "color":"#818A0F",
#         "hotkey":"",
#         "applicable_type":"all",
#         "classes":[]
#     }
# ]