DataGym.ai
Search…
⌃K

Images

Manage the images in your DataGym.ai Datasets with our Python API
The Image objects in our Python API are not real images (in bytes) but hold the reference attributes (ID, name, etc.) from images in DataGym.ai. However, the Python API Client allows you to directly download these images from your DataGym.ai Projects.

Upload Images

1. Choose the Dataset you want to upload images to
dataset = client.get_dataset_by_name("Dataset_Name")
2.1 Upload a local image to DataGym.ai
uploaded_image = client.upload_image(dataset.id, "PATH_TO_LOCAL_IMAGE")
optionally you can manually set the image name
uploaded_image = client.upload_image(dataset.id, "PATH_TO_LOCAL_IMAGE", "name.jpg")
2.2 Upload from image urls
image_url_list = [image_url_1, image_url_2]
upload_results = client.create_images_from_urls(dataset.id, image_url_list)

Download Images

Select an image from your Project/Dataset

1. Choose a Project (or Dataset)
dummy_project = client.get_project_by_name("Dummy_Project")
2. Choose an image
We simple take the first image of our Dummy Project for this example
dummy_images = dummy_project.get_images()
first_dummy_img = dummy_images[0]

Download the image data

Download as Bytes

You can download and store the selected image as byte stream via the download_image_bytes method of the API Client. The method requires the Image object you selected during the recent steps.
img_data = client.download_image_bytes(image_id=first_dummy_img)
download_image_bytes returns the image as bytes in Python
Use-Case: Do you want to inspect the image you downloaded in your application? Let's use some additional packages to visualize our newly downloaded image
Install Pillow - the Python Imaging Library - with pip to run this example
from PIL import Image
import io
image = Image.open(io.BytesIO(image_data))
image.show()
This little script will view the Image on your machine.

Download image as file

You can also directly download an image to your machine. Therefore, execute the download_image method which requires the Image object you want to download and the destination on your machine.
client.download_image(image=first_dummy_img, file_path="")

Delete Images

To delete an image from your DataGym.ai Dataset use the delete_image method of the Client class. The method only requires an Image Object.
delete_success = client.delete_image(image=first_dummy_img)
delete_image returns True if the image was successfully deleted
Executing this method will permanently delete the Image from your DataGym.ai Dataset

The Image object

Image Attributes

The Image object in the Python API is modeled after DataGym's Images.
>>>> print(first_dummy_img)
<Image {
'id': '<IMAGE_ID>',
'image_name': 'sattelite_01.jpg',
'image_type': 'SHAREABLE_LINK',
'timestamp': 1584711260832
}>