forked from cvisionai/tator-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivities.py
58 lines (49 loc) · 1.99 KB
/
activities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
""" This example shows how to create activities.
"""
import logging
import sys
import random
import time
import tator
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == '__main__':
parser = tator.get_parser()
parser.add_argument('--video_type_id', help="Video type ID.", type=int, required=True)
parser.add_argument('--video_id', help="Video ID.", type=int, required=True)
args = parser.parse_args()
tator_api = tator.get_api(args.host, args.token)
# Get the video object and video type object.
video = tator_api.get_media(args.video_id)
video_type = tator_api.get_media_type(args.video_type_id)
# Create a new state type for the project to represent activities. Activities will
# have a user-defined attribute called "Something in view" to indicate whether
# an object of interest is visible in the video during that frame. The interpolation
# parameter indicates that the latest update to this value should be used for
# visual indication in the UI.
response = tator_api.create_state_type(video_type.project, state_type_spec={
'name': 'Activity Change',
'association': 'Frame',
'media_types': [video_type.id],
'attribute_types': [{
'name': 'Something in view',
'dtype': 'bool',
}],
})
state_type_id = response.id
logger.info(response.message)
# Create activity change every 10 frames with "Something in view" indicator
# switching between true and false.
states = [{
'type': state_type_id,
'frame': frame,
'media_ids': [args.video_id],
'Something in view': (frame % 20) == 0,
} for frame in range(0, video.num_frames, 10)]
state_ids = []
for response in tator.util.chunked_create(
tator_api.create_state_list, video_type.project, body=states
):
state_ids += response.id
logger.info(f"Created {len(state_ids)} activity changes!")