Skip to content

Commit ccede52

Browse files
committed
update viclip demo
1 parent 6382e09 commit ccede52

File tree

15 files changed

+1161
-328
lines changed

15 files changed

+1161
-328
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

Data/InternVid/demo.ipynb

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,25 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": null,
13+
"execution_count": 1,
1414
"id": "e7a90379-d9ee-45d9-9073-7ed5132fa6b1",
1515
"metadata": {},
16-
"outputs": [],
16+
"outputs": [
17+
{
18+
"name": "stderr",
19+
"output_type": "stream",
20+
"text": [
21+
"/mnt/petrelfs/wangyi/.conda/envs/pt13/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
22+
" from .autonotebook import tqdm as notebook_tqdm\n"
23+
]
24+
}
25+
],
1726
"source": [
1827
"import numpy as np\n",
1928
"import os\n",
2029
"import cv2\n",
2130
"\n",
22-
"from viclip import retrieve_text, _frame_from_video"
31+
"from viclip import get_viclip, retrieve_text, _frame_from_video"
2332
]
2433
},
2534
{
@@ -35,19 +44,55 @@
3544
},
3645
{
3746
"cell_type": "code",
38-
"execution_count": 6,
47+
"execution_count": 3,
48+
"id": "e6c1cd7a",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"# modify xxx to the path of the pretrained model\n",
53+
"model_cfgs = {\n",
54+
" 'viclip-l-internvid-10m-flt': {\n",
55+
" 'size': 'l',\n",
56+
" 'pretrained': 'xxx/ViCLIP-L_InternVid-FLT-10M.pth',\n",
57+
" },\n",
58+
" 'viclip-l-internvid-200m': {\n",
59+
" 'size': 'l',\n",
60+
" 'pretrained': 'xxx/ViCLIP-L_InternVid-200M.pth',\n",
61+
" },\n",
62+
" 'viclip-b-internvid-10m-flt': {\n",
63+
" 'size': 'b',\n",
64+
" 'pretrained': 'xxx/ViCLIP-B_InternVid-FLT-10M.pth',\n",
65+
" },\n",
66+
" 'viclip-b-internvid-200m': {\n",
67+
" 'size': 'b',\n",
68+
" 'pretrained': 'xxx/ViCLIP-B_InternVid-200M.pth',\n",
69+
" },\n",
70+
"}"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": 5,
3976
"id": "3fb7397a-02ef-41b5-9ffe-f2363b277778",
4077
"metadata": {},
4178
"outputs": [
79+
{
80+
"name": "stderr",
81+
"output_type": "stream",
82+
"text": [
83+
"/mnt/petrelfs/wangyi/.conda/envs/pt13/lib/python3.9/site-packages/torch/utils/checkpoint.py:31: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n",
84+
" warnings.warn(\"None of the inputs have requires_grad=True. Gradients will be None\")\n"
85+
]
86+
},
4287
{
4388
"name": "stdout",
4489
"output_type": "stream",
4590
"text": [
46-
"text: A man in a gray sweater plays fetch with his dog in the snowy yard, throwing a toy and watching it run. ~ prob: 0.8264\n",
47-
"text: A playful dog and its owner wrestle in the snowy yard, chasing each other with joyous abandon. ~ prob: 0.1587\n",
48-
"text: A pet dog excitedly runs through the snowy yard, chasing a toy thrown by its owner. ~ prob: 0.0141\n",
49-
"text: A person dressed in a blue jacket shovels the snow-covered pavement outside their house. ~ prob: 0.0006\n",
50-
"text: A playful dog slides down a snowy hill, wagging its tail with delight. ~ prob: 0.0002\n"
91+
"text: A man in a gray sweater plays fetch with his dog in the snowy yard, throwing a toy and watching it run. ~ prob: 0.8333\n",
92+
"text: A playful dog and its owner wrestle in the snowy yard, chasing each other with joyous abandon. ~ prob: 0.1266\n",
93+
"text: A pet dog excitedly runs through the snowy yard, chasing a toy thrown by its owner. ~ prob: 0.0368\n",
94+
"text: A person dressed in a blue jacket shovels the snow-covered pavement outside their house. ~ prob: 0.0030\n",
95+
"text: A playful dog slides down a snowy hill, wagging its tail with delight. ~ prob: 0.0003\n"
5196
]
5297
}
5398
],
@@ -63,17 +108,46 @@
63108
" \"A man in a gray sweater plays fetch with his dog in the snowy yard, throwing a toy and watching it run.\",\n",
64109
" \"A person bundled up in a blanket walks through the snowy landscape, enjoying the serene winter scenery.\"]\n",
65110
"\n",
66-
"texts, probs = retrieve_text(frames, text_candidates, name='viclip', topk=5)\n",
111+
"cfg = model_cfgs['viclip-l-internvid-10m-flt']\n",
112+
"model_l = get_viclip(cfg['size'], cfg['pretrained'])\n",
113+
"texts, probs = retrieve_text(frames, text_candidates, models=model_l, topk=5)\n",
67114
"\n",
68115
"for t, p in zip(texts, probs):\n",
69116
" print(f'text: {t} ~ prob: {p:.4f}')"
70117
]
71118
},
72119
{
73120
"cell_type": "code",
74-
"execution_count": null,
121+
"execution_count": 6,
75122
"id": "a2969ba6-19d0-4893-b071-b82fa046c312",
76123
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"text: A playful dog and its owner wrestle in the snowy yard, chasing each other with joyous abandon. ~ prob: 0.8192\n",
130+
"text: A man in a gray sweater plays fetch with his dog in the snowy yard, throwing a toy and watching it run. ~ prob: 0.1084\n",
131+
"text: A pet dog excitedly runs through the snowy yard, chasing a toy thrown by its owner. ~ prob: 0.0676\n",
132+
"text: A playful dog slides down a snowy hill, wagging its tail with delight. ~ prob: 0.0047\n",
133+
"text: A person dressed in a blue jacket shovels the snow-covered pavement outside their house. ~ prob: 0.0002\n"
134+
]
135+
}
136+
],
137+
"source": [
138+
"cfg = model_cfgs['viclip-b-internvid-10m-flt']\n",
139+
"model_b = get_viclip(cfg['size'], cfg['pretrained'])\n",
140+
"texts, probs = retrieve_text(frames, text_candidates, models=model_b, topk=5)\n",
141+
"\n",
142+
"for t, p in zip(texts, probs):\n",
143+
" print(f'text: {t} ~ prob: {p:.4f}')"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"id": "ebdae1be-0dc4-4f3c-9856-5e0fd27aa368",
150+
"metadata": {},
77151
"outputs": [],
78152
"source": []
79153
}

0 commit comments

Comments
 (0)