Upload data

To upload data to your project, use the following code snippet:

from trainyolo.client import Client, Project

APIKEY = "YOUR_API_KEY"

# get client
client = Client(APIKEY)

# get project by name
name = 'project name'
project = Project.get_by_name(client, name)

## option 1: from a list of image paths
## fastest if you want to upload images without annotations 
image_paths = [
    'path/to/first/image.jpg',
    'path/to/second/image.jpg',
    'path/to/third/image.jpg'
]
project.push(image_paths)

## option 2: upload image one at a time, together with annotations
image_paths = [
    'path/to/first/image.jpg',
    'path/to/second/image.jpg',
    'path/to/third/image.jpg'
]
for image_p in image_paths:
    sample = project.add_sample(image_p)
    # now you can also add annotations
    # format bbox: [x_top_left, y_top_left, width, height]
    # category_id: starting from 1
    annotations = [
        {'bbox':[10, 10, 100, 100], 'category_id': 1},
        {'bbox':[20, 20, 100, 100], 'category_id': 1},
        {'bbox':[30, 30, 100, 100], 'category_id': 1},
        {'bbox':[40, 40, 100, 100], 'category_id': 1},
    ]
    sample.label = annotations

Last updated