Importing data and labels
You can programmatically upload your data to the RedBrick AI platform and also upload pre-labels with the data so that your team can correct the annotations on the platform.

Creating data points without labels

You can use the create_datapoints method to upload data to the RedBrick AI platform.
Perform standard SDK set up to create an RBProject object.
1
import redbrick
2
3
# Standard Setup
4
api_key = "<TODO>"
5
org_id = "<TODO>"
6
project_id = "<TODO>"
7
8
project = redbrick.get_project(
9
org_id=org_id,
10
project_id=project_id,
11
api_key=api_key
12
)
Copied!
Construct your data points object and upload to RedBrick.
1
# Your storage id can be found on the Storage Methods tab (left sidebar) on RedBrick AI
2
# redbrick.StorageMethod.REDBRICK is for locally stored data.
3
storage_id = redbrick.StorageMethod.REDBRICK
4
5
datapoints = [
6
{
7
# Must be unique for each datapoint.
8
"name": "my first upload",
9
10
# Must be a valid path to data stored in the storage method
11
# defined above.
12
"items": [
13
"path/to/local/file.png"
14
]
15
}
16
]
17
18
project.upload.create_datapoints(storage_id, datapoints)
Copied!

Creating data points with vector labels

You can also upload data with pre-labels using the create_datapoints method.
1
# Your storage id can be found on the Storage Methods tab (left sidebar) on RedBrick AI
2
# redbrick.StorageMethod.PUBLIC is for publically stored data.
3
storage_id = redbrick.StorageMethod.PUBLIC
4
5
datapoints = [
6
{
7
# Must be unique for each datapoint.
8
"name": "my first upload",
9
10
# Must be a valid path to data stored in the storage method
11
# defined above.
12
"items": [
13
"http://datasets.redbrickai.com/car-vids/car-1/frame20.png"
14
]
15
16
# The labels field needs to be of type LabelObject
17
"labels": [
18
{
19
# category-name must be a valid name part of your
20
# project taxonomy.
21
"category": [["object", "category-name"]],
22
23
"bbox2d": {
24
"xnorm": 0.1,
25
"ynorm": 0.1,
26
"wnorm": 0.2,
27
"hnorm": 0.2
28
}
29
}
30
]
31
}
32
]
33
34
project.upload.create_datapoints(storage_id, datapoints)
Copied!

Creating data points with segmentation labels

To upload data with masks labels, you can use the create_datapoint_from_masks method. You have to first prepare a directory containing your masks in the format defined in the reference documentation.
1
# Directory containing the mask data, in the correct format.
2
dir = "<TODO>"
3
4
# Load map information
5
with open(os.path.join(dir, "class_map.json"), "r") as file:
6
class_map = json.load(file)
7
with open(os.path.join(dir, "datapoint_map.json"), "r") as file:
8
datapoint_map = json.load(file)
9
10
# Iterate over files, and upload data with masks.
11
for file in datapoint_map:
12
mask_im = Image.open(os.path.join(dir, file))
13
mask = np.array(mask_im)[:, :, 0:3] # Ignore Alpha channel
14
mask = mask.astype(np.uint8)
15
16
# Because we are using redbrick.StorageMethod.REDBRICK,
17
# the image_path will need to be path to a locally stored image.
18
image_path = datapoint_map[file]
19
project.upload.create_datapoint_from_masks(
20
redbrick.StorageMethod.REDBRICK, mask, class_map, image_path
21
)
Copied!
Last modified 1mo ago