The Image object represents the Superb Curate image. It may be used to bulk create, delete, fetch and modify an image.
Create
The creation of one or more Superb Curate images can be done using create_bulk which will return a Superb Curate job.
from spb_curate import Image, ImageSourceLocal, ImageSourceUrl
# preparing a Image from a local file
local_image_1 = Image(
key="image_1_key",
source=ImageSourceLocal(asset="/path/to/image"),
metadata={
"misc-key": "new-value",
},
)
# preparing a Image from a URL
url_image_1 = Image(
key="image_2_key",
source=ImageSourceUrl(url="http://example.com/path/to/image.jpg"),
metadata={
"misc-key": "new-value",
},
)
image_job = Image.create_bulk(
dataset_id=dataset.id,
images=[local_image_1, url_image_1],
)
# Increase the timeout for large volumes of images
image_job.wait_until_complete(timeout=1200)
Delete
The removal of images can be done singularly or in bulk.
Removing a single image can be done using delete.
image.delete()Deleting multiple images can be done using delete_bulk on either a list of Image instances, a list of Superb Curate image ids, or a list of image keys.
from spb_curate import Image
# Using Superb AI Curate image instances
images = Image.fetch_all(
dataset_id=dataset.id,
query='annotations."car".count > 0',
)
job = Image.delete_bulk(
dataset_id=dataset.id,
images=images,
)
# using image ids
job = Image.delete_bulk(
dataset_id=dataset.id,
image_ids=["im_0000", "im_0001"],
)
# using image keys
job = Image.delete_bulk(
dataset_id=dataset.id,
image_keys=["traffic1.jpg", "traffic2.jpg"],
)Fetch
Superb Curate images can can either be fetched as a singular object or fetched via a query to get a list of objects.
Fetching a single object can be done using fetch.
from spb_curate import Image
image = Image.fetch(
dataset_id=dataset.id,
id="im_01HV5S089KGG784QB675AF8DH5",
include_annotations=True, # optional
)For fetching images there are multiple options. The recommended function to use is fetch_all_iter however the following fetch functions are also available fetch_all, fetch_page and fetch_page_iter.
from spb_curate import Image
image_iter = Image.fetch_all_iter(
dataset_id=dataset.id,
key="traffic1.jpg", # optional
query='images.id="im_1234"', # optional
slice="traffic", # optional
include_annotations=True, # optional
include_image_url=True, # optional
)
for image in image_iter:
# do somethingModify
Editing the image's metadata can be done using modify.
image.modify(
metadata={
"misc-key": "updated-value",
},
)Refresh
Receiving the up to date data for a image can be done using refresh.
image.refresh()