PointcloudDataset

class PointcloudDataset[source]

Bases: supervisely.project.video_project.VideoDataset

Methods

add_item_file

Adds given item file to dataset items directory, and adds given annotation to dataset annotations directory.

add_item_np

Adds given numpy array as a pointcloud to dataset items directory, and adds given annotation to dataset ann directory.

add_item_raw_bytes

Not available for PointcloudDataset class object.

datasets_dir

rtype

List[str]

delete_item

Delete pointcloud, annotation, pointcloud info and related images from PointcloudDataset.

generate_item_path

Generates full path to the given item.

get_ann

Read pointcloud annotation of item from json.

get_ann_path

Path to the given annotation.

get_classes_stats

get_image_info

Not available for PointcloudDataset class object.

get_img_info_path

Not available for PointcloudDataset class object.

get_img_path

Not available for PointcloudDataset class object.

get_item_info

Information for Item with given name.

get_item_info_path

Get path to the item info json file without checking if the file exists.

get_item_meta_path

Get path to the item info json file without checking if the file exists.

get_item_path

Path to the given item.

get_item_paths

rtype

PointcloudItemPaths

get_items_names

List of video dataset item names.

get_pointcloud_info

Information for Pointcloud with given name.

get_pointcloud_info_path

rtype

str

get_pointcloud_path

Path to the given pointcloud.

get_related_images

rtype

List[Tuple[str, Dict]]

get_related_images_path

rtype

str

get_seg_path

Not available for PointcloudDataset class object.

get_url

Get URL to dataset items list in Supervisely.

ignorable_dirs

rtype

List[str]

item_exists

Checks if given item name belongs to the video dataset.

items

This method is used to iterate over dataset items, receiving item name, path to image and path to annotation json file.

key

set_ann

Replaces given annotation for given item name to dataset annotations directory in json format.

set_ann_dict

Replaces given annotation json for given item name to dataset annotations directory in json format.

set_ann_file

Replaces given annotation json file for given item name to dataset annotations directory in json format.

Attributes

ann_dir

Path to the video dataset annotations directory.

ann_dir_name

str: Annotations directory name

datasets_dir_name

directory

Path to the video dataset directory.

image_infos

If the dataset is opened from the API, returns the list of ImageInfo objects.

img_dir

Not available for PointcloudDataset class object.

img_info_dir

Not available for PointcloudDataset class object.

item_dir

Path to the video dataset items directory.

item_dir_name

str: Items data directory name

item_info_dir

Path to the video dataset item with items info.

item_info_dir_name

str: Items info directory name

meta_dir

Path to the dataset segmentation masks directory.

meta_dir_name

name

Video Dataset name.

path

Returns a relative local path to the dataset.

pointcloud_dir

rtype

str

pointcloud_info_dir

rtype

str

project_dir

Path to the video project containing the video dataset.

related_images_dir_name

str: Related images directory name

seg_dir

Not available for PointcloudDataset class object.

seg_dir_name

str: Segmentation masks directory name

short_name

Short dataset name, which does not include it's parents.

annotation_class

alias of supervisely.pointcloud_annotation.pointcloud_annotation.PointcloudAnnotation

item_info_class

alias of supervisely.api.video.video_api.VideoInfo

item_info_type

alias of supervisely.api.pointcloud.pointcloud_api.PointcloudInfo

add_item_file(item_name, item_path, ann=None, _validate_item=True, _use_hardlink=False, item_info=None)[source]

Adds given item file to dataset items directory, and adds given annotation to dataset annotations directory. if ann is None, creates empty annotation file.

Parameters
item_name : str

Item name.

item_path : str

Path to the item.

ann : PointcloudAnnotation or str, optional

PointcloudAnnotation object or path to annotation json file.

_validate_item : bool, optional

Checks input files format.

_use_hardlink : bool, optional

If True creates a hardlink pointing to src named dst, otherwise don’t.

item_info : PointcloudInfo or dict or str, optional

PointcloudInfo object or PointcloudInfo object converted to dict or path to item info json file for copying to dataset item info directory.

Returns

None

Return type

NoneType

Raises

RuntimeError if item_name already exists in dataset or item name has unsupported extension.

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

ann = "/home/admin/work/supervisely/projects/ptc_project/ds0/ann/PTC_8888.pcd.json"
ds.add_item_file("PTC_8888.pcd", "/home/admin/work/supervisely/projects/ptc_project/ds0/pointcloud/PTC_8888.pcd", ann=ann)
print(ds.item_exists("PTC_8888.pcd"))
# Output: True
add_item_np(item_name, pointcloud, ann=None, item_info=None)[source]

Adds given numpy array as a pointcloud to dataset items directory, and adds given annotation to dataset ann directory. if ann is None, creates empty annotation file.

Parameters
item_name : str

Item name.

pointcloud : np.ndarray

numpy Pointcloud array [N, 3], in (X, Y, Z) format.

ann : PointcloudAnnotation or str, optional

PointcloudAnnotation object or path to annotation .json file.

item_info : NamedTuple, optional

NamedTuple PointcloudItemInfo containing information about Pointcloud.

Returns

None

Return type

NoneType

Raises

Exception if item_name already exists in dataset or item name has unsupported extension

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

pointcloud_path = "/home/admin/Pointclouds/ptc0.pcd"
img_np = sly.image.read(img_path)
ds.add_item_np("IMG_050.jpeg", img_np)
add_item_raw_bytes(item_name, item_raw_bytes, ann=None, img_info=None)[source]

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

delete_item(item_name)[source]

Delete pointcloud, annotation, pointcloud info and related images from PointcloudDataset.

Parameters
item_name : str

Item name.

Returns

True if successful, otherwise False

Return type

bool

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

result = dataset.delete_item("PTC_0748.pcd")
# Output: True
generate_item_path(item_name)

Generates full path to the given item.

Parameters
item_name : str

Item name.

Returns

Full path to the given item

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)

print(ds.generate_item_path("IMG_0748.jpeg"))
# Output: '/home/admin/work/supervisely/projects/lemons_annotated/ds1/img/IMG_0748.jpeg'
get_ann(item_name, project_meta, key_id_map=None)[source]

Read pointcloud annotation of item from json.

Parameters
item_name : str

Pointcloud name.

project_meta : ProjectMeta

Project Meta.

key_id_map : KeyIdMap, optional

KeyIdMap object.

Returns

PointcloudAnnotation object

Return type

PointcloudAnnotation

Raises

RuntimeError if item not found in the project

Usage example
import supervisely as sly

project_path = "/home/admin/work/supervisely/projects/pointcloud_project"
project = sly.PointcloudProject(project_path, sly.OpenMode.READ)

ds = project.datasets.get('ds1')

annotation = ds.get_ann("PTC_0056")
# Output: RuntimeError: Item PTC_0056 not found in the project.

annotation = ds.get_ann("PTC_0056.pcd")
print(type(annotation).__name__)
# Output: PointcloudAnnotation
get_ann_path(item_name)[source]

Path to the given annotation.

Parameters
item_name : str

PointcloudAnnotation name.

Returns

Path to the given annotation

Return type

str

Raises

RuntimeError if item not found in the project

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

ds.get_ann_path("PTC_0748")
# Output: RuntimeError: Item PTC_0748 not found in the project.

ds.get_ann_path("PTC_0748.pcd")
# Output: '/home/admin/work/supervisely/projects/ptc_project/ds0/ann/IMG_0748.pcd.json'
get_image_info(item_name)[source]

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

Return type

None

get_img_info_path(img_name)[source]

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

Return type

str

get_img_path(item_name)[source]

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

Return type

str

get_item_info(item_name)

Information for Item with given name.

Parameters
item_name : str

Item name.

Returns

VideoInfo object.

Return type

VideoInfo

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.get_item_info("video_0748.mp4"))
# Output:
# VideoInfo(
#     id=198702499,
#     name='video_0748.mp4',
#     hash='ehYHLNFWmMNuF2fPUgnC/g/tkIIEjNIOhdbNLQXkE8Y=',
#     team_id=16087,
#     workspace_id=23821,
#     project_id=124974,
#     dataset_id=466639,
#     path_original='/h5un6l2bnaz1vj8a9qgms4-public/videos/w/7/i4/GZYoCs...9F3kyVJ7.mp4',
#     frames_to_timecodes=[0, 0.033367, 0.066733, 0.1001,...,10.777433, 10.8108, 10.844167],
#     frames_count=326,
#     frame_width=3840,
#     frame_height=2160,
#     created_at='2021-03-23T13:14:25.536Z',
#     updated_at='2021-03-23T13:16:43.300Z'
# )
get_item_info_path(item_name)

Get path to the item info json file without checking if the file exists.

Parameters
item_name : str

Item name.

Returns

Path to the given item info json file.

Return type

str

Raises

RuntimeError if item not found in the project.

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.get_item_info_path("video_0748"))
# Output: RuntimeError: Item video_0748 not found in the project.

print(ds.get_item_info_path("video_0748.mp4"))
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0/video_info/video_0748.mp4.json'
get_item_meta_path(item_name)

Get path to the item info json file without checking if the file exists.

Parameters
item_name : str

Item name.

Returns

Path to the given item info json file.

Return type

str

Raises

RuntimeError if item not found in the project.

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)

print(ds.get_item_info_path("IMG_0748"))
# Output: RuntimeError: Item IMG_0748 not found in the project.

print(ds.get_item_info_path("IMG_0748.jpeg"))
# Output: '/home/admin/work/supervisely/projects/lemons_annotated/ds1/img_info/IMG_0748.jpeg.json'
get_item_path(item_name)

Path to the given item.

Parameters
item_name : str

Item name.

Returns

Path to the given item.

Return type

str

Raises

RuntimeError if item not found in the project

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.get_item_path("video_0748"))
# Output: RuntimeError: Item video_0748 not found in the project.

print(ds.get_item_path("video_0748.mp4"))
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0/video/video_0748.mp4'
get_items_names()

List of video dataset item names.

Returns

List of item names.

Return type

list [ str ]

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.get_item_names())
# Output: ['video_0002.mp4', 'video_0005.mp4', 'video_0008.mp4', ...]
get_pointcloud_info(item_name)[source]

Information for Pointcloud with given name.

Parameters
item_name : str

Pointcloud name.

Returns

Pointcloud with information for the given Dataset

Return type

NamedTuple

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

info = ds.get_pointcloud_info("IMG_0748.pcd")
get_pointcloud_path(item_name)[source]

Path to the given pointcloud.

Parameters
item_name : str

Pointcloud name

Returns

Path to the given pointcloud

Return type

str

Raises

RuntimeError if item not found in the project

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/ptc_project/ds0"
ds = sly.PointcloudDataset(dataset_path, sly.OpenMode.READ)

ds.get_pointcloud_path("PTC_0748")
# Output: RuntimeError: Item IMG_0748 not found in the project.

ds.get_pointcloud_path("PTC_0748.pcd")
# Output: '/home/admin/work/supervisely/projects/ptc_project/ds0/pointcloud/PTC_0748.pcd'
get_seg_path(item_name)[source]

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

Return type

str

static get_url(project_id, dataset_id)

Get URL to dataset items list in Supervisely.

Parameters
project_id : int

VideoProject ID in Supervisely.

dataset_id : int

VideoDataset ID in Supervisely.

Returns

URL to dataset items list.

Return type

str

Usage example
from supervisely import VideoDataset

project_id = 10093
dataset_id = 45330
ds_items_link = VideoDataset.get_url(project_id, dataset_id)

print(ds_items_link)
# Output: "/projects/10093/datasets/45330/entities"
item_exists(item_name)

Checks if given item name belongs to the video dataset.

Parameters
item_name : str

Item name.

Returns

True if item exist, otherwise False.

Return type

bool

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

ds.item_exists("video_0748")     # False
ds.item_exists("video_0748.mp4") # True
items()

This method is used to iterate over dataset items, receiving item name, path to image and path to annotation json file. It is useful when you need to iterate over dataset items and get paths to images and annotations.

Returns

Generator object, that yields tuple of item name, path to image and path to annotation json file.

Return type

Generator[Tuple[str]]

Usage example
import supervisely as sly

input = "path/to/local/directory"
# Creating Supervisely project from local directory.
project = sly.Project(input, sly.OpenMode.READ)

for dataset in project.datasets:
    for item_name, image_path, ann_path in dataset.items():
        print(f"Item '{item_name}': image='{image_path}', ann='{ann_path}'")
set_ann(item_name, ann, key_id_map=None)

Replaces given annotation for given item name to dataset annotations directory in json format.

Parameters
item_name : str

Item name.

ann : VideoAnnotation

VideoAnnotation object.

key_id_map : KeyIdMap, optional

KeyIdMap object.

Returns

None

Return type

NoneType

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

height, width = 500, 700
new_ann = sly.VideoAnnotation((height, width), frames_count=0)
ds.set_ann("video_0748.mp4", new_ann)
set_ann_dict(item_name, ann)

Replaces given annotation json for given item name to dataset annotations directory in json format.

Parameters
item_name : str

Item name.

ann : dict

Annotation as a dict in json format.

Returns

None

Return type

NoneType

Raises

RuntimeError if ann_path is not str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)

new_ann_json = {
    "description":"",
    "size":{
        "height":500,
        "width":700
    },
    "tags":[],
    "objects":[],
    "customBigData":{}
}

ds.set_ann_dict("IMG_8888.jpeg", new_ann_json)
set_ann_file(item_name, ann_path)

Replaces given annotation json file for given item name to dataset annotations directory in json format.

Parameters
item_name : str

Item Name.

ann_path : str

Path to the Annotation json file.

Returns

None

Return type

NoneType

Raises

RuntimeError if ann_path is not str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)

new_ann = "/home/admin/work/supervisely/projects/kiwi_annotated/ds1/ann/IMG_1812.jpeg.json"
ds.set_ann_file("IMG_1812.jpeg", new_ann)
property ann_dir

Path to the video dataset annotations directory.

Returns

Path to the video dataset directory with annotations.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.ann_dir)
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0/ann'
ann_dir_name = 'ann'

str: Annotations directory name

property directory

Path to the video dataset directory.

Returns

Path to the video dataset directory.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.directory)
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0'
property image_infos

If the dataset is opened from the API, returns the list of ImageInfo objects. Otherwise raises an exception.

Raises

ValueError: If the dataset is opened in local mode.

Returns

List of ImageInfo objects.

Return type

List[ImageInfo]

property img_dir

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

Return type

str

property img_info_dir

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

property item_dir

Path to the video dataset items directory.

Returns

Path to the video dataset items directory.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.item_dir)
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0/video'
item_dir_name = 'pointcloud'

str: Items data directory name

property item_info_dir

Path to the video dataset item with items info.

Returns

Path to the video dataset directory with items info.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)

print(ds.item_info_dir)
# Output: '/home/admin/work/supervisely/projects/videos_example/ds0/video_info'
item_info_dir_name = 'pointcloud_info'

str: Items info directory name

property meta_dir

Path to the dataset segmentation masks directory.

Returns

Path to the dataset directory with masks.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)

print(ds.meta_dir)
# Output: '/home/admin/work/supervisely/projects/lemons_annotated/ds1/meta'
property name

Video Dataset name.

Returns

Video Dataset Name.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)
print(ds.name)
# Output: "ds0"
property path

Returns a relative local path to the dataset.

Returns

Relative local path to the dataset.

Return type

str

property project_dir

Path to the video project containing the video dataset.

Returns

Path to the video project.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/videos_example/ds0"
ds = sly.VideoDataset(dataset_path, sly.OpenMode.READ)
print(ds.project_dir)
# Output: "/home/admin/work/supervisely/projects/videos_example"
related_images_dir_name = 'related_images'

str: Related images directory name

property seg_dir

Not available for PointcloudDataset class object. :raises: NotImplementedError in all cases.

seg_dir_name = None

str: Segmentation masks directory name

property short_name

Short dataset name, which does not include it’s parents. To get the full name of the dataset, use name.

Returns

Dataset Name.

Return type

str

Usage example
import supervisely as sly
dataset_path = "/home/admin/work/supervisely/projects/lemons_annotated/ds1"
ds = sly.Dataset(dataset_path, sly.OpenMode.READ)
print(ds.name)
# Output: "ds1"