Image API

class supervisely_lib.api.image_api.ImageApi(api)[source]

Bases: supervisely_lib.api.module_api.RemoveableBulkModuleApi

API for working with Image. ImageApi object is immutable.

Parameters

api (Api) – API connection to the server

Usage example
# 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.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_info = api.image.get_info_by_id(image_id) # api usage example
static info_sequence()[source]

NamedTuple ImageInfo containing information about Image.

Example
ImageInfo(id=770915,
          name='IMG_3861.jpeg',
          link=None,
          hash='ZdpMD+ZMJx0R8BgsCzJcqM7qP4M8f1AEtoYc87xZmyQ=',
          mime='image/jpeg',
          ext='jpeg',
          size=148388,
          width=1067,
          height=800,
          labels_count=4,
          dataset_id=2532,
          created_at='2021-03-02T10:04:33.973Z',
          updated_at='2021-03-02T10:04:33.973Z',
          meta={},
          path_original='/h5un6l2bnaz1vj8a9qgms4-public/images/original/7/h/Vo/...jpg',
          full_storage_url='http://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/7/h/Vo/...jpg')
static info_tuple_name()[source]

NamedTuple name - ImageInfo.

get_list(dataset_id: int, filters: Optional[List[dict]] = None, sort: str = 'id', sort_order: str = 'asc') → List[NamedTuple][source]

List of Images in the given Dataset.

Parameters
  • dataset_id (int) – Dataset ID in which the Images are located.

  • filters (List[dict], optional) – List of params to sort output Images.

  • sort (str, optional) – string (one of “id” “name” “description” “labelsCount” “createdAt” “updatedAt”)

  • sort_order (str, optional) –

Returns

List of all images with information for the given Dataset. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

# Get list of Images with width = 1067
img_infos = api.image.get_list(dataset_id, filters=[{ 'field': 'width', 'operator': '=', 'value': '1067' }])
print(img_infos)
# Output: [ImageInfo(id=770915,
#                    name='IMG_3861.jpeg',
#                    link=None,
#                    hash='ZdpMD+ZMJx0R8BgsCzJcqM7qP4M8f1AEtoYc87xZmyQ=',
#                    mime='image/jpeg',
#                    ext='jpeg',
#                    size=148388,
#                    width=1067,
#                    height=800,
#                    labels_count=4,
#                    dataset_id=2532,
#                    created_at='2021-03-02T10:04:33.973Z',
#                    updated_at='2021-03-02T10:04:33.973Z',
#                    meta={},
#                    path_original='/h5un6l2bnaz1vj8a9qgms4-public/images/original/7/h/Vo/...jpg',
#                    full_storage_url='http://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/7/h/Vo/...jpg'),
# ImageInfo(id=770916,
#           name='IMG_1836.jpeg',
#           link=None,
#           hash='YZKQrZH5C0rBvGGA3p7hjWahz3/pV09u5m30Bz8GeYs=',
#           mime='image/jpeg',
#           ext='jpeg',
#           size=140222,
#           width=1067,
#           height=800,
#           labels_count=3,
#           dataset_id=2532,
#           created_at='2021-03-02T10:04:33.973Z',
#           updated_at='2021-03-02T10:04:33.973Z',
#           meta={},
#           path_original='/h5un6l2bnaz1vj8a9qgms4-public/images/original/C/Y/Hq/...jpg',
#           full_storage_url='http://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/C/Y/Hq/...jpg')
# ]
get_info_by_id(id: int) → NamedTuple[source]

Get Image information by ID.

Parameters

id (int) – Image ID in Supervisely.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

# You can get Image ID by listing all images in the Dataset as shown in get_list
# Or you can open certain image in Supervisely Annotation Tool UI and get last digits of the URL
img_info = api.image.get_info_by_id(770918)
get_info_by_id_batch(ids: List[int]) → List[NamedTuple][source]

Get Images information by ID.

Parameters

ids (List[int]) – Images IDs in Supervisely.

Returns

Information about Image. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_ids = [376728, 376729, 376730, 376731, 376732, 376733]
img_infos = image.get_info_by_id_batch(img_ids)
download_np(id: int, keep_alpha: bool = False) → numpy.ndarray[source]

Download Image with given id in numpy format.

Parameters
  • id (int) – Image ID in Supervisely.

  • keep_alpha (bool, optional) – If True keeps alpha mask for image, otherwise don’t.

Returns

Image in RGB numpy matrix format

Return type

np.ndarray

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_np = api.image.download_np(770918)
download_path(id: int, path: str) → None[source]

Downloads Image from Dataset to local path by ID.

Parameters
  • id (int) – Image ID in Supervisely.

  • path (str) – Local save path for Image.

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_info = api.image.get_info_by_id(770918)
save_path = os.path.join("/home/admin/work/projects/lemons_annotated/ds1/test_imgs/", img_info.name)

api.image.download_path(770918, save_path)
download_paths(dataset_id: int, ids: List[int], paths: List[str], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None) → None[source]

Download Images with given ids and saves them for the given paths.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely, where Images are located.

  • ids (List[int]) – List of Image IDs in Supervisely.

  • paths (List[str]) – Local save paths for Images.

  • progress_cb (Progress, optional) – Function for tracking download progress.

Raises

RuntimeError if len(ids) != len(paths)

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

local_save_dir = "/home/admin/work/projects/lemons_annotated/ds1/test_imgs"
save_paths = []
image_ids = [771755, 771756, 771757, 771758, 771759, 771760]
img_infos = api.image.get_info_by_id_batch(image_ids)

progress = sly.Progress("Images downloaded: ", len(img_infos))
for img_info in img_infos:
    save_paths.append(os.path.join(local_save_dir, img_info.name))

api.image.download_paths(2573, image_ids, save_paths, progress_cb=progress.iters_done_report)
# Progress:
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 0, "total": 6, "timestamp": "2021-03-15T19:47:15.406Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 1, "total": 6, "timestamp": "2021-03-15T19:47:16.366Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 2, "total": 6, "timestamp": "2021-03-15T19:47:16.367Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 3, "total": 6, "timestamp": "2021-03-15T19:47:16.367Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 4, "total": 6, "timestamp": "2021-03-15T19:47:16.367Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 5, "total": 6, "timestamp": "2021-03-15T19:47:16.368Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 6, "total": 6, "timestamp": "2021-03-15T19:47:16.368Z", "level": "info"}
download_bytes(dataset_id: int, ids: List[int], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None) → bytes[source]

Download Images with given IDs from Dataset in Binary format.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely, where Images are located.

  • ids (List[int]) – List of Image IDs in Supervisely.

  • progress_cb (Progress, optional) – Function for tracking download progress.

Returns

List of Images in binary format

Return type

List[bytes]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_bytes = api.image.download_bytes(dataset_id, [770918])
print(img_bytes)
# Output: [b'ÿØÿàJFIF\...]
download_nps(dataset_id: int, ids: List[int], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None, keep_alpha: bool = False) → List[numpy.ndarray][source]

Download Images with given IDs in numpy format.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely, where Images are located.

  • ids (List[int]) – List of Images IDs in Supervisely.

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • keep_alpha (bool, optional) – If True keeps alpha mask for Image, otherwise don’t.

Returns

List of Images in RGB numpy matrix format

Return type

List[np.ndarray]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_ids = [770918, 770919, 770920]
image_nps = api.image.download_nps(dataset_id, image_ids)
check_existing_hashes(hashes: List[str]) → List[str][source]

Checks existing hashes for Images.

Parameters

hashes (List[str]) – List of hashes.

Returns

List of existing hashes

Return type

List[str]

Usage example

Checkout detailed example here (you must be logged into your Supervisely account)

# Helpful method when your uploading was interrupted
# You can check what images has been successfully uploaded by their hashes and what not
# And continue uploading the rest of the images from that point

os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

# Find project
project = api.project.get_info_by_id(WORKSPACE_ID, PROJECT_ID)

# Get paths of all images in a directory
images_paths = sly.fs.list_files('images_to_upload')

#Calculate hashes for all images paths
hash_to_image = {}
images_hashes = []

for idx, item in enumerate(images_paths):
    item_hash = sly.fs.get_file_hash(item)
    images_hashes.append(item_hash)
    hash_to_image[item_hash] = item

# Get hashes that are already on server
remote_hashes = api.image.check_existing_hashes(images_hashes)
already_uploaded_images = {hh: hash_to_image[hh] for hh in remote_hashes}
check_image_uploaded(hash: str) → bool[source]

Checks if Image has been uploaded.

Parameters

hash (str) – Image hash in Supervisely.

Returns

True if Image with given hash exist, otherwise False

Return type

bool

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_check_uploaded = api.image.check_image_uploaded("YZKQrZH5C0rBvGGA3p7hjWahz3/pV09u5m30Bz8GeYs=")
print(image_check_uploaded)
# Output: True
upload_path(dataset_id: int, name: str, path: str, meta: Optional[dict] = None) → NamedTuple[source]

Uploads Image with given name from given local path to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • name (str) – Image name.

  • path (str) – Local Image path.

  • meta (dict, optional) – Image metadata.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_info = api.image.upload_path(dataset_id, name="7777.jpeg", path="/home/admin/Downloads/7777.jpeg")
upload_paths(dataset_id: int, names: List[str], paths: List[str], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None, metas: Optional[List[dict]] = None) → List[NamedTuple][source]

Uploads Images with given names from given local path to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • names (List[str]) – List of Images names.

  • paths (List[str]) – List of local Images pathes.

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • metas (List[dict], optional) – Images metadata.

Raises

RuntimeError if len(names) != len(paths)

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_names = ["7777.jpeg", "8888.jpeg", "9999.jpeg"]
image_paths = ["/home/admin/Downloads/img/770918.jpeg", "/home/admin/Downloads/img/770919.jpeg", "/home/admin/Downloads/img/770920.jpeg"]

img_infos = api.image.upload_path(dataset_id, names=img_names, paths=img_paths)
upload_np(dataset_id: int, name: str, img: numpy.ndarray, meta: Optional[dict] = None) → NamedTuple[source]

Upload given Image in numpy format with given name to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • name (str) – Image name with extension.

  • img (np.ndarray) – image in RGB format(numpy matrix)

  • meta (dict, optional) – Image metadata.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_np = sly.image.read("/home/admin/Downloads/7777.jpeg")
img_info = api.image.upload_np(dataset_id, name="7777.jpeg", img=img_np)
upload_nps(dataset_id: int, names: List[str], imgs: List[numpy.ndarray], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None, metas: Optional[List[dict]] = None) → List[NamedTuple][source]

Upload given Images in numpy format with given names to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • names (List[str]) – Images names.

  • imgs (List[np.ndarray]) – Images in RGB numpy matrix format

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • metas (List[dict], optional) – Images metadata.

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_np_1 = sly.image.read("/home/admin/Downloads/7777.jpeg")
img_np_2 = sly.image.read("/home/admin/Downloads/8888.jpeg")
img_np_3 = sly.image.read("/home/admin/Downloads/9999.jpeg")

img_names = ["7777.jpeg", "8888.jpeg", "9999.jpeg"]
img_nps = [img_np_1, img_np_2, img_np_3]

img_infos = api.image.upload_nps(dataset_id, names=img_names, imgs=img_nps)

Uploads Image from given link to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • name (str) – Image name.

  • link (str) – Link to Image.

  • meta (dict, optional) – Image metadata.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_name = 'Avatar.jpg'
img_link = 'https://m.media-amazon.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_.jpg'

img_info = api.image.upload_link(dataset_id, img_name, img_link)

Uploads Images from given links to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • names (List[str]) – Images names.

  • links (List[str]) – Links to Images.

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • metas (List[dict], optional) – Images metadata.

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_names = ['Avatar.jpg', 'Harry Potter.jpg', 'Avengers.jpg']
img_links = ['https://m.media-amazon.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_.jpg',
             'https://m.media-amazon.com/images/M/MV5BNDYxNjQyMjAtNTdiOS00NGYwLWFmNTAtNThmYjU5ZGI2YTI1XkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_.jpg',
             'https://m.media-amazon.com/images/M/MV5BNjQ3NWNlNmQtMTE5ZS00MDdmLTlkZjUtZTBlM2UxMGFiMTU3XkEyXkFqcGdeQXVyNjUwNzk3NDc@._V1_.jpg']

img_infos = api.image.upload_links(dataset_id, img_names, img_links)
upload_hash(dataset_id: int, name: str, hash: str, meta: Optional[dict] = None) → NamedTuple[source]

Upload Image from given hash to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • name (str) – Image name.

  • hash (str) – Image hash.

  • meta (dict, optional) – Image metadata.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

dst_dataset_id = 452984
im_info = api.image.get_info_by_id(193940090)
hash = im_info.hash
# It is necessary to upload image with the same name(extention) as in src dataset
name = im_info.name
meta = {1: 'meta_example'}
new_in_info = api.image.upload_hash(dst_dataset_id, name, hash, meta)
print(json.dumps(new_in_info, indent=4))
# Output: [
#     196793586,
#     "IMG_0748.jpeg",
#     null,
#     "NEjmnmdd7DOzaFAKK/nCIl5CtcwZeMkhW3CHe875p9g=",
#     "image/jpeg",
#     "jpeg",
#     66885,
#     600,
#     500,
#     0,
#     452984,
#     "2021-03-16T09:09:45.587Z",
#     "2021-03-16T09:09:45.587Z",
#     {
#         "1": "meta_example"
#     },
#     "/h5un6l2bnaz1vj8a9qgms4-public/images/original/P/a/kn/W2mzMQg435d6wG0.jpg",
#     "https://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/P/a/kn/W2mzMQg435hiHJAPgMU.jpg"
# ]
upload_hashes(dataset_id: int, names: List[str], hashes: List[str], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None, metas: Optional[List[dict]] = None) → List[NamedTuple][source]

Upload images from given hashes to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • names (List[str]) – Images names.

  • hashes (List[str]) – Images hashes.

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • metas (List[dict], optional) – Images metadata.

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

src_dataset_id = 447130
hashes = []
names = []
metas = []
imgs_info = api.image.get_list(src_dataset_id)
# Create lists of hashes, images names and meta information for each image
for im_info in imgs_info:
    hashes.append(im_info.hash)
    # It is necessary to upload images with the same names(extentions) as in src dataset
    names.append(im_info.name)
    metas.append({im_info.name: im_info.size})

dst_dataset_id = 452984
progress = sly.Progress("Images upload: ", len(hashes))
new_imgs_info = api.image.upload_hashes(dst_dataset_id, names, hashes, progress.iters_done_report, metas)
# Output:
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 0, "total": 10, "timestamp": "2021-03-16T11:59:07.444Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 10, "total": 10, "timestamp": "2021-03-16T11:59:07.644Z", "level": "info"}
upload_id(dataset_id: int, name: str, id: int, meta: Optional[dict] = None) → NamedTuple[source]

Upload Image by ID to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • name (str) – Image name.

  • id (int) – Image ID in Supervisely.

  • meta (dict, optional) – Image metadata.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

dst_dataset_id = 452984
im_info = api.image.get_info_by_id(193940090)
id = im_info.id
# It is necessary to upload image with the same name(extention) as in src dataset
name = im_info.name
meta = {1: 'meta_example'}
new_in_info = api.image.upload_id(dst_dataset_id, name, id, meta)
print(json.dumps(new_in_info, indent=4))
# Output: [
#     196793605,
#     "IMG_0748.jpeg",
#     null,
#     "NEjmnmdd7DOzaFAKK/nCIl5CtcwZeMkhW3CHe875p9g=",
#     "image/jpeg",
#     "jpeg",
#     66885,
#     600,
#     500,
#     0,
#     452984,
#     "2021-03-16T09:27:12.620Z",
#     "2021-03-16T09:27:12.620Z",
#     {
#         "1": "meta_example"
#     },
#     "/h5un6l2bnaz1vj8a9qgms4-public/images/original/P/a/kn/W2mzMQg435d6wG0AJGJTOsL1FqMUNOPqu4VdzFAN36LqtGwBIE4AmLOQ1BAxuIyB0bHJAPgMU.jpg",
#     "https://app.supervise.ly/h5un6l2bnaz1vj8a9qgms4-public/images/original/P/a/kn/iEaDEkejnfnb1Tz56ka0hiHJAPgMU.jpg"
# ]
upload_ids(dataset_id: int, names: List[str], ids: List[int], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None, metas: Optional[List[dict]] = None) → List[NamedTuple][source]

Upload Images by IDs to Dataset.

Parameters
  • dataset_id (int) – Dataset ID in Supervisely.

  • names (List[str]) – Images names.

  • ids (List[int]) – Images IDs.

  • progress_cb (Progress, optional) – Function for tracking download progress.

  • metas (List[dict], optional) – Images metadata.

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

src_dataset_id = 447130

ids = []
names = []
metas = []
imgs_info = api.image.get_list(src_dataset_id)
# Create lists of ids, images names and meta information for each image
for im_info in imgs_info:
    ids.append(im_info.id)
    # It is necessary to upload images with the same names(extentions) as in src dataset
    names.append(im_info.name)
    metas.append({im_info.name: im_info.size})

dst_dataset_id = 452984
progress = sly.Progress("Images upload: ", len(ids))
new_imgs_info = api.image.upload_ids(dst_dataset_id, names, ids, progress.iters_done_report, metas)
# Output:
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 0, "total": 10, "timestamp": "2021-03-16T12:31:36.550Z", "level": "info"}
# {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 10, "total": 10, "timestamp": "2021-03-16T12:31:37.119Z", "level": "info"}
copy_batch(dst_dataset_id: int, ids: List[int], change_name_if_conflict: bool = False, with_annotations: bool = False) → List[NamedTuple][source]

Copies Images with given IDs to Dataset.

Parameters
  • dst_dataset_id (int) – Destination Dataset ID in Supervisely.

  • ids (List[int]) – Images IDs in Supervisely.

  • change_name_if_conflict (bool, optional) – If True adds suffix to the end of Image name when Dataset already contains an Image with identical name, If False and images with the identical names already exist in Dataset raises error.

  • with_annotations (bool, optional) – If True Image will be copied to Dataset with annotations, otherwise only Images without annotations.

Raises

RuntimeError if type of ids is not list or if images ids are from the destination Dataset

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

ds_lemon_id = 1780
ds_kiwi_id = 1233

ds_lemon_img_infos = api.image.get_list(ds_lemon_id)
ds_kiwi_img_infos = api.image.get_list(ds_kiwi_id)

fruit_img_ids = []
for lemon_img_info, kiwi_img_info in zip(ds_lemon_img_infos, ds_kiwi_img_infos):
    fruit_img_ids.append(lemon_img_info.id)
    fruit_img_ids.append(kiwi_img_info.id)

ds_fruit_id = 2574
ds_fruit_img_infos = api.image.copy_batch(ds_fruit_id, fruit_img_ids, with_annotations=True)
move_batch(dst_dataset_id: int, ids: List[int], change_name_if_conflict: bool = False, with_annotations: bool = False) → List[NamedTuple][source]

Moves Images with given IDs to Dataset.

Parameters
  • dst_dataset_id (int) – Destination Dataset ID in Supervisely.

  • ids (List[int]) – Images IDs in Supervisely.

  • change_name_if_conflict (bool, optional) – If True adds suffix to the end of Image name when Dataset already contains an Image with identical name, If False and images with the identical names already exist in Dataset raises error.

  • with_annotations (bool, optional) – If True Image will be copied to Dataset with annotations, otherwise only Images without annotations.

Raises

RuntimeError if type of ids is not list or if images ids are from the destination Dataset

Returns

List with information about Images. See info_sequence

Return type

List[NamedTuple]

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

ds_lemon_id = 1780
ds_kiwi_id = 1233

ds_lemon_img_infos = api.image.get_list(ds_lemon_id)
ds_kiwi_img_infos = api.image.get_list(ds_kiwi_id)

fruit_img_ids = []
for lemon_img_info, kiwi_img_info in zip(ds_lemon_img_infos, ds_kiwi_img_infos):
    fruit_img_ids.append(lemon_img_info.id)
    fruit_img_ids.append(kiwi_img_info.id)

ds_fruit_id = 2574
ds_fruit_img_infos = api.image.move_batch(ds_fruit_id, fruit_img_ids, with_annotations=True)
copy(dst_dataset_id: int, id: int, change_name_if_conflict: bool = False, with_annotations: bool = False) → NamedTuple[source]

Copies Image with given ID to destination Dataset.

Parameters
  • dst_dataset_id (int) – Destination Dataset ID in Supervisely.

  • id (int) – Image ID in Supervisely.

  • change_name_if_conflict (bool, optional) – If True adds suffix to the end of Image name when Dataset already contains an Image with identical name, If False and images with the identical names already exist in Dataset raises error.

  • with_annotations (bool, optional) – If True Image will be copied to Dataset with annotations, otherwise only Images without annotations.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

dst_ds_id = 365184
img_id = 121236920

img_info = api.image.copy(dst_ds_id, img_id, with_annotations=True)
move(dst_dataset_id: int, id: int, change_name_if_conflict: bool = False, with_annotations: bool = False) → NamedTuple[source]

Moves Image with given ID to destination Dataset.

Parameters
  • dst_dataset_id (int) – Destination Dataset ID in Supervisely.

  • id (int) – Image ID in Supervisely.

  • change_name_if_conflict (bool, optional) – If True adds suffix to the end of Image name when Dataset already contains an Image with identical name, If False and images with the identical names already exist in Dataset raises error.

  • with_annotations (bool, optional) – If True Image will be copied to Dataset with annotations, otherwise only Images without annotations.

Returns

Information about Image. See info_sequence

Return type

NamedTuple

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

dst_ds_id = 365484
img_id = 533336920

img_info = api.image.copy(dst_ds_id, img_id, with_annotations=True)
url(team_id: int, workspace_id: int, project_id: int, dataset_id: int, image_id: int) → str[source]

Gets Image URL by ID.

Parameters
  • team_id (int) – Team ID in Supervisely.

  • workspace_id (int) – Workspace ID in Supervisely.

  • project_id (int) – Project ID in Supervisely.

  • dataset_id (int) – Dataset ID in Supervisely.

  • image_id (int) – Image ID in Supervisely.

Returns

Image URL

Return type

str

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

team_id = 16087
workspace_id = 23821
project_id = 53939
dataset_id = 254737
image_id = 121236920

img_url = api.image.url(team_id, workspace_id, project_id, dataset_id, image_id)
print(url)
# Output: https://app.supervise.ly/app/images/16087/23821/53939/254737#image-121236920
download_paths_by_hashes(hashes: List[str], paths: List[str], progress_cb: Optional[supervisely_lib.task.progress.Progress] = None) → None[source]

Download Images with given hashes in Supervisely server and saves them for the given paths.

Parameters
  • hashes (List[str]) – List of images hashes in Supervisely.

  • paths (List[str]) – List of paths to save images.

  • progress_cb (Progress, optional) – Function for tracking download progress.

Raises

RuntimeError if len(hashes) != len(paths)

Returns

None

Return type

NoneType

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

dataset_id = 447130
dir_for_save = '/home/admin/Downloads/img'
hashes = []
paths = []
imgs_info = api.image.get_list(dataset_id)
for im_info in imgs_info:
    hashes.append(im_info.hash)
    # It is necessary to save images with the same names(extentions) as on the server
    paths.append(os.path.join(dir_for_save, im_info.name))
api.image.download_paths_by_hashes(hashes, paths)
get_project_id(image_id: int) → int[source]

Gets Project ID by Image ID.

Parameters

image_id (int) – Image ID in Supervisely.

Returns

Project ID where Image is located.

Return type

int

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

img_project_id = api.image.get_project_id(121236920)
print(img_project_id)
# Output: 53939
storage_url(path_original: str) → str[source]

Get full Image URL link in Supervisely server.

Parameters

path_original (str) – Original Image path in Supervisely server.

Returns

Full Image URL link in Supervisely server

Return type

str

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_id = 376729
img_info = api.image.get_info_by_id(image_id)
img_storage_url = api.image.storage_url(img_info.path_original)
preview_url(url: str, width: Optional[int] = None, height: Optional[int] = None, quality: int = 70) → str[source]

Previews Image with the given resolution parameters.

Parameters
  • url (str) – Full Image storage URL.

  • width (int) – Preview Image width.

  • height (int) – Preview Image height.

  • quality (int) – Preview Image quality.

Returns

New URL with resized Image

Return type

str

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

image_id = 376729
img_info = api.image.get_info_by_id(image_id)
img_preview_url = api.image.preview_url(img_info.full_storage_url, width=512, height=256)

# DOESN'T WORK
update_meta(id: int, meta: dict) → dict[source]

Updates Image meta by ID.

Parameters
  • id (int) – Image ID in Supervisely.

  • meta (dict) – Image metadata.

Raises

TypeError if meta type is not dict

Returns

Image information in dict format with new meta

Return type

dict

Usage example
os.environ['SERVER_ADDRESS'] = 'https://app.supervise.ly'
os.environ['API_TOKEN'] = 'Your Supervisely API Token'
api = sly.Api.from_env()

upd_img_meta = api.image.get_info_by_id(121236920)
print(upd_img_meta.upd_img_meta)
# Output: {}

new_meta = {'Camera Make': 'Canon', 'Color Space': 'sRGB', 'Focal Length': '16 mm'}
new_img_info = api.image.update_meta(121236920, new_meta)

upd_img_meta = api.image.get_info_by_id(121236920)
print(json.dumps(upd_img_meta.meta, indent=4))
# Output: {
#     "Camera Make": "Canon",
#     "Color Space": "sRGB",
#     "Focal Length": "16 mm"
# }
add_tag(image_id, tag_id, value=None)[source]
add_tag_batch(image_ids, tag_id, value=None)[source]
InfoType

alias of supervisely_lib.api.module_api.ImageInfo