Skip to content

Commit e3a0d8d

Browse files
caitlinwheelesscaitlinwheelessmakseq
authored
docs: DOC-264: Add export options to video object tracking template (#6620)
Co-authored-by: caitlinwheeless <[email protected]> Co-authored-by: Max Tkachenko <[email protected]>
1 parent c1abf56 commit e3a0d8d

File tree

1 file changed

+135
-13
lines changed

1 file changed

+135
-13
lines changed

docs/source/templates/video_object_detector.md

+135-13
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Video object detection is aimed at detecting object in a video stream with bound
1414
Video object tracking is a further extension where detected objects are tracked as they move around video frames, in both spatial and temporal directions.
1515
The illustrated templates provide both manual and automatic ways of tracking objects in videos. In addition to the new video player that supports frame-by-frame video object tracking, the latest release also features a new annotation user interface that is more efficient, ergonomic, and flexible.
1616

17-
18-
1917
!!! attention "important"
2018

2119
1. Video classification and object tracking were available to preview prior to Label Studio version 1.6, but these features are now fully functional and production-ready.
@@ -35,22 +33,17 @@ The prerequisites to use the video object detection feature are as follows:
3533

3634
## Key features supported
3735

38-
The following key features are supported by the video player.
39-
40-
1. The video and object detection use case using the bounding box on the video.
41-
2. Video segmentation for the video by creating rectangles on the video.
36+
The following key features are supported by the video player:
4237

43-
44-
!!! attention "important"
45-
46-
In the future releases, Timeline segmentation will allow you to label a conversation based on the timeline.
38+
* The video and object detection use case using the bounding box on the video.
39+
* Video segmentation for the video by creating rectangles on the video.
4740

4841

4942
## Labeling Configuration
5043

51-
The simplest way to get object detection and tracking project is to go in [project settings](/guide/setup.html#Modify-the-labeling-interface) and specify the following labeling configuration.
44+
The simplest way to get object detection and tracking project is to specify the following labeling configuration in your project settings.
5245

53-
```html
46+
```xml
5447
<View>
5548
<Header>Label the video:</Header>
5649
<Video name="video" value="$video" framerate="25.0"/>
@@ -75,8 +68,11 @@ You can add a [header](/tags/header.html) to provide instructions to the annotat
7568

7669
Use the [Video](/tags/video.html) object tag to specify the video data. The `framerate` parameter sets the frame rate of all videos in the project. Check all available parameters on the tag page reference.
7770
```xml
78-
<Video name="video" value="$video" framerate="25.0"/>
71+
<Video name="video" value="$video" frameRate="25.0"/>
7972
```
73+
74+
!!! note
75+
Ensure the `frameRate` matches the video's framerate. If your video has defects or variable framerate, it might cause discrepancies. Transcoding the video to a constant framerate before uploading can help.
8076

8177
Use the [VideoRectangle](/tags/videorectangle.html) control tag to allow annotators to add rectangles to video frames:
8278
```xml
@@ -171,6 +167,132 @@ The keyframe format inside `value.sequence` list is the following:
171167
}
172168
```
173169

170+
### Exporting with interpolated frames
171+
172+
By default, only keyframes are included when exporting data.
173+
174+
When exporting your annotations, you may want to include interpolated frames. This would ensure that every frame in the video is included.
175+
176+
You can accomplish this by using the `interpolate_key_frames` parameter and one of the following methods:
177+
178+
179+
#### Use the API to create an export snapshot with interpolation enabled
180+
181+
You can use the Label Studio API to create an export snapshot with keyframe interpolation enabled.
182+
183+
**Endpoint:**
184+
```
185+
POST /api/projects/{project_id}/exports
186+
```
187+
**Request Body:**
188+
```json
189+
{
190+
"title": "Export with Interpolated Keyframes",
191+
"serialization_options": {
192+
"interpolate_key_frames": true
193+
}
194+
}
195+
```
196+
**Example cURL Command:**
197+
```bash
198+
curl -X POST 'https://your-label-studio-domain.com/api/projects/{project_id}/exports' \
199+
-H 'Authorization: Token YOUR_API_KEY' \
200+
-H 'Content-Type: application/json' \
201+
--data-raw '{
202+
"title": "Export with Interpolated Keyframes",
203+
"serialization_options": {
204+
"interpolate_key_frames": true
205+
}
206+
}'
207+
```
208+
**Steps:**
209+
1. **Create export snapshot:**
210+
- Send a `POST` request to `/api/projects/{project_id}/exports` with `interpolate_key_frames` set to `true` in the `serialization_options`.
211+
2. **Check export status:**
212+
- Poll the export status using `GET /api/projects/{project_id}/exports/{export_id}` until the `status` is `completed`.
213+
3. **Download the export:**
214+
- Once the export is completed, download the export file using:
215+
```
216+
GET /api/projects/{project_id}/exports/{export_id}/download?exportType=JSON
217+
```
218+
- Example cURL Command:
219+
```bash
220+
curl -X GET 'https://your-label-studio-domain.com/api/projects/{project_id}/exports/{export_id}/download?exportType=JSON' \
221+
-H 'Authorization: Token YOUR_API_KEY' \
222+
-o 'exported_annotations.json'
223+
```
224+
225+
#### Use the Label Studio SDK
226+
227+
If you're using the Label Studio SDK, you can create an export with interpolation enabled:
228+
229+
**Python code example:**
230+
231+
```python
232+
from label_studio_sdk import Client
233+
import time
234+
# Connect to Label Studio
235+
ls = Client(url='http://localhost:8080', api_key='YOUR_API_KEY')
236+
# Get your project by ID
237+
project = ls.get_project(PROJECT_ID)
238+
# Create an export snapshot with interpolation enabled
239+
export_result = project.export_snapshot_create(
240+
title='Export with Interpolated Keyframes',
241+
serialization_options={
242+
'interpolate_key_frames': True
243+
}
244+
)
245+
# Get the export ID
246+
export_id = export_result['id']
247+
# Wait for the export to complete
248+
while True:
249+
export_status = project.get_export_status(export_id)
250+
if export_status['status'] == 'completed':
251+
break
252+
elif export_status['status'] == 'failed':
253+
raise Exception('Export failed')
254+
else:
255+
time.sleep(5) # Wait for 5 seconds before checking again
256+
# Download the export
257+
export_file_path = project.export_snapshot_download(
258+
export_id, export_type='JSON', path='.'
259+
)
260+
print(f'Exported data saved to {export_file_path}')
261+
```
262+
263+
**Notes:**
264+
- Replace `YOUR_API_KEY` with your actual API key.
265+
- Replace `PROJECT_ID` with your project ID.
266+
- Ensure that you have installed the latest version of the Label Studio SDK.
267+
268+
#### Use the Command Line Interface (CLI)
269+
270+
You can use the Label Studio CLI to export annotations with interpolated keyframes.
271+
272+
**Command:**
273+
```bash
274+
label-studio export --host http://localhost:8080 --api-key YOUR_API_KEY PROJECT_ID JSON --interpolate-key-frames
275+
```
276+
**Notes:**
277+
- The `--interpolate-key-frames` flag enables interpolation during export.
278+
- Replace `YOUR_API_KEY` and `PROJECT_ID` with your API key and project ID, respectively.
279+
- The exported data will be saved in the `data/export` directory by default.
280+
281+
282+
#### Use the export endpoint with query parameter
283+
284+
You can directly export tasks with interpolation by using the export endpoint and passing `interpolate_key_frames` as a query parameter.
285+
**Endpoint:**
286+
```
287+
GET /api/projects/{project_id}/export?interpolate_key_frames=true
288+
```
289+
**Example cURL Command:**
290+
```bash
291+
curl -X GET 'https://your-label-studio-domain.com/api/projects/{project_id}/export?interpolate_key_frames=true' \
292+
-H 'Authorization: Token YOUR_API_KEY' \
293+
-o 'exported_annotations.json'
294+
```
295+
174296
## Label Studio UI enhancements
175297

176298
The video player functionality includes the following UI enhancements:

0 commit comments

Comments
 (0)