|
10 | 10 | }, |
11 | 11 | { |
12 | 12 | "cell_type": "code", |
13 | | - "execution_count": null, |
| 13 | + "execution_count": 1, |
14 | 14 | "id": "e7a90379-d9ee-45d9-9073-7ed5132fa6b1", |
15 | 15 | "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 | + ], |
17 | 26 | "source": [ |
18 | 27 | "import numpy as np\n", |
19 | 28 | "import os\n", |
20 | 29 | "import cv2\n", |
21 | 30 | "\n", |
22 | | - "from viclip import retrieve_text, _frame_from_video" |
| 31 | + "from viclip import get_viclip, retrieve_text, _frame_from_video" |
23 | 32 | ] |
24 | 33 | }, |
25 | 34 | { |
|
35 | 44 | }, |
36 | 45 | { |
37 | 46 | "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, |
39 | 76 | "id": "3fb7397a-02ef-41b5-9ffe-f2363b277778", |
40 | 77 | "metadata": {}, |
41 | 78 | "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 | + }, |
42 | 87 | { |
43 | 88 | "name": "stdout", |
44 | 89 | "output_type": "stream", |
45 | 90 | "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" |
51 | 96 | ] |
52 | 97 | } |
53 | 98 | ], |
|
63 | 108 | " \"A man in a gray sweater plays fetch with his dog in the snowy yard, throwing a toy and watching it run.\",\n", |
64 | 109 | " \"A person bundled up in a blanket walks through the snowy landscape, enjoying the serene winter scenery.\"]\n", |
65 | 110 | "\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", |
67 | 114 | "\n", |
68 | 115 | "for t, p in zip(texts, probs):\n", |
69 | 116 | " print(f'text: {t} ~ prob: {p:.4f}')" |
70 | 117 | ] |
71 | 118 | }, |
72 | 119 | { |
73 | 120 | "cell_type": "code", |
74 | | - "execution_count": null, |
| 121 | + "execution_count": 6, |
75 | 122 | "id": "a2969ba6-19d0-4893-b071-b82fa046c312", |
76 | 123 | "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": {}, |
77 | 151 | "outputs": [], |
78 | 152 | "source": [] |
79 | 153 | } |
|
0 commit comments