|
a |
|
b/demo/demo.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "code", |
|
|
5 |
"execution_count": 1, |
|
|
6 |
"metadata": { |
|
|
7 |
"pycharm": { |
|
|
8 |
"is_executing": false |
|
|
9 |
} |
|
|
10 |
}, |
|
|
11 |
"outputs": [], |
|
|
12 |
"source": [ |
|
|
13 |
"from mmaction.apis import init_recognizer, inference_recognizer" |
|
|
14 |
] |
|
|
15 |
}, |
|
|
16 |
{ |
|
|
17 |
"cell_type": "code", |
|
|
18 |
"execution_count": 2, |
|
|
19 |
"metadata": { |
|
|
20 |
"pycharm": { |
|
|
21 |
"is_executing": false |
|
|
22 |
} |
|
|
23 |
}, |
|
|
24 |
"outputs": [], |
|
|
25 |
"source": [ |
|
|
26 |
"config_file = '../configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py'\n", |
|
|
27 |
"# download the checkpoint from model zoo and put it in `checkpoints/`\n", |
|
|
28 |
"checkpoint_file = '../checkpoints/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth'" |
|
|
29 |
] |
|
|
30 |
}, |
|
|
31 |
{ |
|
|
32 |
"cell_type": "code", |
|
|
33 |
"execution_count": 3, |
|
|
34 |
"metadata": { |
|
|
35 |
"pycharm": { |
|
|
36 |
"is_executing": false |
|
|
37 |
} |
|
|
38 |
}, |
|
|
39 |
"outputs": [], |
|
|
40 |
"source": [ |
|
|
41 |
"# build the model from a config file and a checkpoint file\n", |
|
|
42 |
"model = init_recognizer(config_file, checkpoint_file, device='cpu')" |
|
|
43 |
] |
|
|
44 |
}, |
|
|
45 |
{ |
|
|
46 |
"cell_type": "code", |
|
|
47 |
"execution_count": 4, |
|
|
48 |
"metadata": { |
|
|
49 |
"pycharm": { |
|
|
50 |
"is_executing": false |
|
|
51 |
} |
|
|
52 |
}, |
|
|
53 |
"outputs": [], |
|
|
54 |
"source": [ |
|
|
55 |
"# test a single video and show the result:\n", |
|
|
56 |
"video = 'demo.mp4'\n", |
|
|
57 |
"label = '../tools/data/kinetics/label_map_k400.txt'\n", |
|
|
58 |
"results = inference_recognizer(model, video)\n", |
|
|
59 |
"\n", |
|
|
60 |
"labels = open(label).readlines()\n", |
|
|
61 |
"labels = [x.strip() for x in labels]\n", |
|
|
62 |
"results = [(labels[k[0]], k[1]) for k in results]" |
|
|
63 |
] |
|
|
64 |
}, |
|
|
65 |
{ |
|
|
66 |
"cell_type": "code", |
|
|
67 |
"execution_count": 5, |
|
|
68 |
"metadata": { |
|
|
69 |
"collapsed": false, |
|
|
70 |
"jupyter": { |
|
|
71 |
"outputs_hidden": false |
|
|
72 |
}, |
|
|
73 |
"pycharm": { |
|
|
74 |
"is_executing": false, |
|
|
75 |
"name": "#%%\n" |
|
|
76 |
} |
|
|
77 |
}, |
|
|
78 |
"outputs": [ |
|
|
79 |
{ |
|
|
80 |
"name": "stdout", |
|
|
81 |
"output_type": "stream", |
|
|
82 |
"text": [ |
|
|
83 |
"arm wrestling: 29.61644\n", |
|
|
84 |
"rock scissors paper: 10.754839\n", |
|
|
85 |
"shaking hands: 9.9084\n", |
|
|
86 |
"clapping: 9.189912\n", |
|
|
87 |
"massaging feet: 8.305307\n" |
|
|
88 |
] |
|
|
89 |
} |
|
|
90 |
], |
|
|
91 |
"source": [ |
|
|
92 |
"# show the results\n", |
|
|
93 |
"for result in results:\n", |
|
|
94 |
" print(f'{result[0]}: ', result[1])" |
|
|
95 |
] |
|
|
96 |
} |
|
|
97 |
], |
|
|
98 |
"metadata": { |
|
|
99 |
"kernelspec": { |
|
|
100 |
"display_name": "Python 3", |
|
|
101 |
"language": "python", |
|
|
102 |
"name": "python3" |
|
|
103 |
}, |
|
|
104 |
"language_info": { |
|
|
105 |
"codemirror_mode": { |
|
|
106 |
"name": "ipython", |
|
|
107 |
"version": 3 |
|
|
108 |
}, |
|
|
109 |
"file_extension": ".py", |
|
|
110 |
"mimetype": "text/x-python", |
|
|
111 |
"name": "python", |
|
|
112 |
"nbconvert_exporter": "python", |
|
|
113 |
"pygments_lexer": "ipython3", |
|
|
114 |
"version": "3.7.4" |
|
|
115 |
}, |
|
|
116 |
"pycharm": { |
|
|
117 |
"stem_cell": { |
|
|
118 |
"cell_type": "raw", |
|
|
119 |
"metadata": { |
|
|
120 |
"collapsed": false |
|
|
121 |
}, |
|
|
122 |
"source": [] |
|
|
123 |
} |
|
|
124 |
} |
|
|
125 |
}, |
|
|
126 |
"nbformat": 4, |
|
|
127 |
"nbformat_minor": 4 |
|
|
128 |
} |