from nucleus import (
BoxAnnotation,
LineAnnotation,
PolygonAnnotation,
Segment,
SegmentationAnnotation,
Point3D,
CuboidAnnotation,
NucleusClient,
)
# You can add various types of annotations to the dataset
box_gt_1 = BoxAnnotation(
label="car",
x=0,
y=0,
width=10,
height=10,
reference_id="image_1",
annotation_id="image_1_car_box_1",
metadata={"vehicle_color": "red"}
)
box_gt_2 = BoxAnnotation(
label="car",
x=4,
y=6,
width=12,
height=18,
reference_id="image_1",
annotation_id="image_1_car_box_2",
metadata={"vehicle_color": "blue"}
)
line_gt = LineAnnotation(
label="lane",
vertices=[{"x": 20, "y": 30}, {"x": 50, "y": 100}],
reference_id="image_2",
annotation_id="image_2_lane_1",
metadata={"position": "left"},
)
polygon_gt = PolygonAnnotation(
label="bus",
vertices=[{"x": 100, "y": 100}, {"x": 150, "y": 200}, {"x": 200, "y": 100}],
reference_id="image_2",
annotation_id="image_2_bus_polygon_1",
metadata={"vehicle_color": "yellow"},
)
segmentation_gt = SegmentationAnnotation(
mask_url="s3://your-bucket-name/segmentation-masks/image_2_mask_id1.png",
annotations=[
Segment(label="grass", index=1),
Segment(label="road", index=2),
Segment(label="bus", index=3, metadata={"vehicle_color": "yellow"}),
Segment(label="tree", index=4)
],
reference_id="image_2",
annotation_id="image_2_mask_1",
)
cuboid_gt = CuboidAnnotation(
label="car",
position=Point3D(100, 100, 10),
dimensions=Point3D(5, 10, 5),
yaw=0,
reference_id="pointcloud_1",
annotation_id="pointcloud_1_car_cuboid_1",
metadata={"vehicle_color": "green"}
)
client = NucleusClient("YOUR_SCALE_API_KEY")
dataset = client.get_dataset("YOUR_DATASET_ID")
response = dataset.annotate(
annotations=[box_gt_1, box_gt_2, line_gt, polygon_gt, segmentation_gt, cuboid_gt],
update=True,
asynchronous=False # async is recommended, but sync jobs are easier to debug
)
print(response)