imr555 commited on
Commit
31ce199
·
verified ·
1 Parent(s): 5f72936

Upload 237 files

Browse files

All VitimeLLM related Files required for training Shikra for videos other than the data files

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. Vtimellm_training_file/LICENSE +403 -0
  3. Vtimellm_training_file/README.md +131 -0
  4. Vtimellm_training_file/demo_gradio.py +201 -0
  5. Vtimellm_training_file/docs/data.md +54 -0
  6. Vtimellm_training_file/docs/eval.md +32 -0
  7. Vtimellm_training_file/docs/inference.ipynb +292 -0
  8. Vtimellm_training_file/docs/inference_for_glm.ipynb +261 -0
  9. Vtimellm_training_file/docs/offline_demo.md +40 -0
  10. Vtimellm_training_file/docs/train.md +48 -0
  11. Vtimellm_training_file/final_test_24th_April_1_4data_1test.txt +940 -0
  12. Vtimellm_training_file/images/demo.mp4 +3 -0
  13. Vtimellm_training_file/images/ex.png +0 -0
  14. Vtimellm_training_file/images/ex1.png +0 -0
  15. Vtimellm_training_file/images/ex2.png +0 -0
  16. Vtimellm_training_file/images/ex3.png +0 -0
  17. Vtimellm_training_file/images/framework.png +0 -0
  18. Vtimellm_training_file/requirements.txt +16 -0
  19. Vtimellm_training_file/scripts/stage1.sh +34 -0
  20. Vtimellm_training_file/scripts/stage1_glm.sh +34 -0
  21. Vtimellm_training_file/scripts/stage2.sh +38 -0
  22. Vtimellm_training_file/scripts/stage2_glm.sh +38 -0
  23. Vtimellm_training_file/scripts/stage2_test.sh +38 -0
  24. Vtimellm_training_file/scripts/stage3.sh +40 -0
  25. Vtimellm_training_file/scripts/stage3_glm.sh +40 -0
  26. Vtimellm_training_file/scripts/stage3_test.sh +83 -0
  27. Vtimellm_training_file/scripts/zero2.json +23 -0
  28. Vtimellm_training_file/scripts/zero3.json +28 -0
  29. Vtimellm_training_file/scripts/zero3_offload.json +56 -0
  30. Vtimellm_training_file/stage3_test_1_backup.txt +0 -0
  31. Vtimellm_training_file/video_read_test_1.py +192 -0
  32. Vtimellm_training_file/vtimellm/__init__.py +1 -0
  33. Vtimellm_training_file/vtimellm/__pycache__/__init__.cpython-310.pyc +0 -0
  34. Vtimellm_training_file/vtimellm/__pycache__/constants.cpython-310.pyc +0 -0
  35. Vtimellm_training_file/vtimellm/__pycache__/conversation.cpython-310.pyc +0 -0
  36. Vtimellm_training_file/vtimellm/__pycache__/inference.cpython-310.pyc +0 -0
  37. Vtimellm_training_file/vtimellm/__pycache__/mm_utils.cpython-310.pyc +0 -0
  38. Vtimellm_training_file/vtimellm/__pycache__/utils.cpython-310.pyc +0 -0
  39. Vtimellm_training_file/vtimellm/constants.py +10 -0
  40. Vtimellm_training_file/vtimellm/conversation.py +384 -0
  41. Vtimellm_training_file/vtimellm/demo_gradio.py +185 -0
  42. Vtimellm_training_file/vtimellm/eval/data_example.json +20 -0
  43. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/LICENSE +33 -0
  44. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/README.md +73 -0
  45. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/dataset.py +122 -0
  46. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/bert_f_score.py +23 -0
  47. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/bert_r_score.py +23 -0
  48. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/mover.py +38 -0
  49. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/requirements.txt +2 -0
  50. Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/soda.py +242 -0
.gitattributes CHANGED
@@ -39,3 +39,6 @@ random_10_sample_of_vidstg/random_10_sample_of_val.json filter=lfs diff=lfs merg
39
  Processed_Dataset/vidstg_train_processed.json filter=lfs diff=lfs merge=lfs -text
40
  xitong/train_annotations.json filter=lfs diff=lfs merge=lfs -text
41
  xitong/vidstg_train_processed.json filter=lfs diff=lfs merge=lfs -text
 
 
 
 
39
  Processed_Dataset/vidstg_train_processed.json filter=lfs diff=lfs merge=lfs -text
40
  xitong/train_annotations.json filter=lfs diff=lfs merge=lfs -text
41
  xitong/vidstg_train_processed.json filter=lfs diff=lfs merge=lfs -text
42
+ Vtimellm_training_file/images/demo.mp4 filter=lfs diff=lfs merge=lfs -text
43
+ Vtimellm_training_file/wandb/run-20240424_080728-6yg2q8fd/run-6yg2q8fd.wandb filter=lfs diff=lfs merge=lfs -text
44
+ Vtimellm_training_file/wandb/run-20240424_092011-8hkwf2fw/run-8hkwf2fw.wandb filter=lfs diff=lfs merge=lfs -text
Vtimellm_training_file/LICENSE ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Attribution-NonCommercial-NoDerivatives 4.0 International
2
+
3
+ =======================================================================
4
+
5
+ Creative Commons Corporation ("Creative Commons") is not a law firm and
6
+ does not provide legal services or legal advice. Distribution of
7
+ Creative Commons public licenses does not create a lawyer-client or
8
+ other relationship. Creative Commons makes its licenses and related
9
+ information available on an "as-is" basis. Creative Commons gives no
10
+ warranties regarding its licenses, any material licensed under their
11
+ terms and conditions, or any related information. Creative Commons
12
+ disclaims all liability for damages resulting from their use to the
13
+ fullest extent possible.
14
+
15
+ Using Creative Commons Public Licenses
16
+
17
+ Creative Commons public licenses provide a standard set of terms and
18
+ conditions that creators and other rights holders may use to share
19
+ original works of authorship and other material subject to copyright
20
+ and certain other rights specified in the public license below. The
21
+ following considerations are for informational purposes only, are not
22
+ exhaustive, and do not form part of our licenses.
23
+
24
+ Considerations for licensors: Our public licenses are
25
+ intended for use by those authorized to give the public
26
+ permission to use material in ways otherwise restricted by
27
+ copyright and certain other rights. Our licenses are
28
+ irrevocable. Licensors should read and understand the terms
29
+ and conditions of the license they choose before applying it.
30
+ Licensors should also secure all rights necessary before
31
+ applying our licenses so that the public can reuse the
32
+ material as expected. Licensors should clearly mark any
33
+ material not subject to the license. This includes other CC-
34
+ licensed material, or material used under an exception or
35
+ limitation to copyright. More considerations for licensors:
36
+ wiki.creativecommons.org/Considerations_for_licensors
37
+
38
+ Considerations for the public: By using one of our public
39
+ licenses, a licensor grants the public permission to use the
40
+ licensed material under specified terms and conditions. If
41
+ the licensor's permission is not necessary for any reason--for
42
+ example, because of any applicable exception or limitation to
43
+ copyright--then that use is not regulated by the license. Our
44
+ licenses grant only permissions under copyright and certain
45
+ other rights that a licensor has authority to grant. Use of
46
+ the licensed material may still be restricted for other
47
+ reasons, including because others have copyright or other
48
+ rights in the material. A licensor may make special requests,
49
+ such as asking that all changes be marked or described.
50
+ Although not required by our licenses, you are encouraged to
51
+ respect those requests where reasonable. More considerations
52
+ for the public:
53
+ wiki.creativecommons.org/Considerations_for_licensees
54
+
55
+ =======================================================================
56
+
57
+ Creative Commons Attribution-NonCommercial-NoDerivatives 4.0
58
+ International Public License
59
+
60
+ By exercising the Licensed Rights (defined below), You accept and agree
61
+ to be bound by the terms and conditions of this Creative Commons
62
+ Attribution-NonCommercial-NoDerivatives 4.0 International Public
63
+ License ("Public License"). To the extent this Public License may be
64
+ interpreted as a contract, You are granted the Licensed Rights in
65
+ consideration of Your acceptance of these terms and conditions, and the
66
+ Licensor grants You such rights in consideration of benefits the
67
+ Licensor receives from making the Licensed Material available under
68
+ these terms and conditions.
69
+
70
+
71
+ Section 1 -- Definitions.
72
+
73
+ a. Adapted Material means material subject to Copyright and Similar
74
+ Rights that is derived from or based upon the Licensed Material
75
+ and in which the Licensed Material is translated, altered,
76
+ arranged, transformed, or otherwise modified in a manner requiring
77
+ permission under the Copyright and Similar Rights held by the
78
+ Licensor. For purposes of this Public License, where the Licensed
79
+ Material is a musical work, performance, or sound recording,
80
+ Adapted Material is always produced where the Licensed Material is
81
+ synched in timed relation with a moving image.
82
+
83
+ b. Copyright and Similar Rights means copyright and/or similar rights
84
+ closely related to copyright including, without limitation,
85
+ performance, broadcast, sound recording, and Sui Generis Database
86
+ Rights, without regard to how the rights are labeled or
87
+ categorized. For purposes of this Public License, the rights
88
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
89
+ Rights.
90
+
91
+ c. Effective Technological Measures means those measures that, in the
92
+ absence of proper authority, may not be circumvented under laws
93
+ fulfilling obligations under Article 11 of the WIPO Copyright
94
+ Treaty adopted on December 20, 1996, and/or similar international
95
+ agreements.
96
+
97
+ d. Exceptions and Limitations means fair use, fair dealing, and/or
98
+ any other exception or limitation to Copyright and Similar Rights
99
+ that applies to Your use of the Licensed Material.
100
+
101
+ e. Licensed Material means the artistic or literary work, database,
102
+ or other material to which the Licensor applied this Public
103
+ License.
104
+
105
+ f. Licensed Rights means the rights granted to You subject to the
106
+ terms and conditions of this Public License, which are limited to
107
+ all Copyright and Similar Rights that apply to Your use of the
108
+ Licensed Material and that the Licensor has authority to license.
109
+
110
+ g. Licensor means the individual(s) or entity(ies) granting rights
111
+ under this Public License.
112
+
113
+ h. NonCommercial means not primarily intended for or directed towards
114
+ commercial advantage or monetary compensation. For purposes of
115
+ this Public License, the exchange of the Licensed Material for
116
+ other material subject to Copyright and Similar Rights by digital
117
+ file-sharing or similar means is NonCommercial provided there is
118
+ no payment of monetary compensation in connection with the
119
+ exchange.
120
+
121
+ i. Share means to provide material to the public by any means or
122
+ process that requires permission under the Licensed Rights, such
123
+ as reproduction, public display, public performance, distribution,
124
+ dissemination, communication, or importation, and to make material
125
+ available to the public including in ways that members of the
126
+ public may access the material from a place and at a time
127
+ individually chosen by them.
128
+
129
+ j. Sui Generis Database Rights means rights other than copyright
130
+ resulting from Directive 96/9/EC of the European Parliament and of
131
+ the Council of 11 March 1996 on the legal protection of databases,
132
+ as amended and/or succeeded, as well as other essentially
133
+ equivalent rights anywhere in the world.
134
+
135
+ k. You means the individual or entity exercising the Licensed Rights
136
+ under this Public License. Your has a corresponding meaning.
137
+
138
+
139
+ Section 2 -- Scope.
140
+
141
+ a. License grant.
142
+
143
+ 1. Subject to the terms and conditions of this Public License,
144
+ the Licensor hereby grants You a worldwide, royalty-free,
145
+ non-sublicensable, non-exclusive, irrevocable license to
146
+ exercise the Licensed Rights in the Licensed Material to:
147
+
148
+ a. reproduce and Share the Licensed Material, in whole or
149
+ in part, for NonCommercial purposes only; and
150
+
151
+ b. produce and reproduce, but not Share, Adapted Material
152
+ for NonCommercial purposes only.
153
+
154
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
155
+ Exceptions and Limitations apply to Your use, this Public
156
+ License does not apply, and You do not need to comply with
157
+ its terms and conditions.
158
+
159
+ 3. Term. The term of this Public License is specified in Section
160
+ 6(a).
161
+
162
+ 4. Media and formats; technical modifications allowed. The
163
+ Licensor authorizes You to exercise the Licensed Rights in
164
+ all media and formats whether now known or hereafter created,
165
+ and to make technical modifications necessary to do so. The
166
+ Licensor waives and/or agrees not to assert any right or
167
+ authority to forbid You from making technical modifications
168
+ necessary to exercise the Licensed Rights, including
169
+ technical modifications necessary to circumvent Effective
170
+ Technological Measures. For purposes of this Public License,
171
+ simply making modifications authorized by this Section 2(a)
172
+ (4) never produces Adapted Material.
173
+
174
+ 5. Downstream recipients.
175
+
176
+ a. Offer from the Licensor -- Licensed Material. Every
177
+ recipient of the Licensed Material automatically
178
+ receives an offer from the Licensor to exercise the
179
+ Licensed Rights under the terms and conditions of this
180
+ Public License.
181
+
182
+ b. No downstream restrictions. You may not offer or impose
183
+ any additional or different terms or conditions on, or
184
+ apply any Effective Technological Measures to, the
185
+ Licensed Material if doing so restricts exercise of the
186
+ Licensed Rights by any recipient of the Licensed
187
+ Material.
188
+
189
+ 6. No endorsement. Nothing in this Public License constitutes or
190
+ may be construed as permission to assert or imply that You
191
+ are, or that Your use of the Licensed Material is, connected
192
+ with, or sponsored, endorsed, or granted official status by,
193
+ the Licensor or others designated to receive attribution as
194
+ provided in Section 3(a)(1)(A)(i).
195
+
196
+ b. Other rights.
197
+
198
+ 1. Moral rights, such as the right of integrity, are not
199
+ licensed under this Public License, nor are publicity,
200
+ privacy, and/or other similar personality rights; however, to
201
+ the extent possible, the Licensor waives and/or agrees not to
202
+ assert any such rights held by the Licensor to the limited
203
+ extent necessary to allow You to exercise the Licensed
204
+ Rights, but not otherwise.
205
+
206
+ 2. Patent and trademark rights are not licensed under this
207
+ Public License.
208
+
209
+ 3. To the extent possible, the Licensor waives any right to
210
+ collect royalties from You for the exercise of the Licensed
211
+ Rights, whether directly or through a collecting society
212
+ under any voluntary or waivable statutory or compulsory
213
+ licensing scheme. In all other cases the Licensor expressly
214
+ reserves any right to collect such royalties, including when
215
+ the Licensed Material is used other than for NonCommercial
216
+ purposes.
217
+
218
+
219
+ Section 3 -- License Conditions.
220
+
221
+ Your exercise of the Licensed Rights is expressly made subject to the
222
+ following conditions.
223
+
224
+ a. Attribution.
225
+
226
+ 1. If You Share the Licensed Material, You must:
227
+
228
+ a. retain the following if it is supplied by the Licensor
229
+ with the Licensed Material:
230
+
231
+ i. identification of the creator(s) of the Licensed
232
+ Material and any others designated to receive
233
+ attribution, in any reasonable manner requested by
234
+ the Licensor (including by pseudonym if
235
+ designated);
236
+
237
+ ii. a copyright notice;
238
+
239
+ iii. a notice that refers to this Public License;
240
+
241
+ iv. a notice that refers to the disclaimer of
242
+ warranties;
243
+
244
+ v. a URI or hyperlink to the Licensed Material to the
245
+ extent reasonably practicable;
246
+
247
+ b. indicate if You modified the Licensed Material and
248
+ retain an indication of any previous modifications; and
249
+
250
+ c. indicate the Licensed Material is licensed under this
251
+ Public License, and include the text of, or the URI or
252
+ hyperlink to, this Public License.
253
+
254
+ For the avoidance of doubt, You do not have permission under
255
+ this Public License to Share Adapted Material.
256
+
257
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
258
+ reasonable manner based on the medium, means, and context in
259
+ which You Share the Licensed Material. For example, it may be
260
+ reasonable to satisfy the conditions by providing a URI or
261
+ hyperlink to a resource that includes the required
262
+ information.
263
+
264
+ 3. If requested by the Licensor, You must remove any of the
265
+ information required by Section 3(a)(1)(A) to the extent
266
+ reasonably practicable.
267
+
268
+
269
+ Section 4 -- Sui Generis Database Rights.
270
+
271
+ Where the Licensed Rights include Sui Generis Database Rights that
272
+ apply to Your use of the Licensed Material:
273
+
274
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
275
+ to extract, reuse, reproduce, and Share all or a substantial
276
+ portion of the contents of the database for NonCommercial purposes
277
+ only and provided You do not Share Adapted Material;
278
+
279
+ b. if You include all or a substantial portion of the database
280
+ contents in a database in which You have Sui Generis Database
281
+ Rights, then the database in which You have Sui Generis Database
282
+ Rights (but not its individual contents) is Adapted Material; and
283
+
284
+ c. You must comply with the conditions in Section 3(a) if You Share
285
+ all or a substantial portion of the contents of the database.
286
+
287
+ For the avoidance of doubt, this Section 4 supplements and does not
288
+ replace Your obligations under this Public License where the Licensed
289
+ Rights include other Copyright and Similar Rights.
290
+
291
+
292
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
293
+
294
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
295
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
296
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
297
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
298
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
299
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
300
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
301
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
302
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
303
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
304
+
305
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
306
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
307
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
308
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
309
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
310
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
311
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
312
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
313
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
314
+
315
+ c. The disclaimer of warranties and limitation of liability provided
316
+ above shall be interpreted in a manner that, to the extent
317
+ possible, most closely approximates an absolute disclaimer and
318
+ waiver of all liability.
319
+
320
+
321
+ Section 6 -- Term and Termination.
322
+
323
+ a. This Public License applies for the term of the Copyright and
324
+ Similar Rights licensed here. However, if You fail to comply with
325
+ this Public License, then Your rights under this Public License
326
+ terminate automatically.
327
+
328
+ b. Where Your right to use the Licensed Material has terminated under
329
+ Section 6(a), it reinstates:
330
+
331
+ 1. automatically as of the date the violation is cured, provided
332
+ it is cured within 30 days of Your discovery of the
333
+ violation; or
334
+
335
+ 2. upon express reinstatement by the Licensor.
336
+
337
+ For the avoidance of doubt, this Section 6(b) does not affect any
338
+ right the Licensor may have to seek remedies for Your violations
339
+ of this Public License.
340
+
341
+ c. For the avoidance of doubt, the Licensor may also offer the
342
+ Licensed Material under separate terms or conditions or stop
343
+ distributing the Licensed Material at any time; however, doing so
344
+ will not terminate this Public License.
345
+
346
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
347
+ License.
348
+
349
+
350
+ Section 7 -- Other Terms and Conditions.
351
+
352
+ a. The Licensor shall not be bound by any additional or different
353
+ terms or conditions communicated by You unless expressly agreed.
354
+
355
+ b. Any arrangements, understandings, or agreements regarding the
356
+ Licensed Material not stated herein are separate from and
357
+ independent of the terms and conditions of this Public License.
358
+
359
+
360
+ Section 8 -- Interpretation.
361
+
362
+ a. For the avoidance of doubt, this Public License does not, and
363
+ shall not be interpreted to, reduce, limit, restrict, or impose
364
+ conditions on any use of the Licensed Material that could lawfully
365
+ be made without permission under this Public License.
366
+
367
+ b. To the extent possible, if any provision of this Public License is
368
+ deemed unenforceable, it shall be automatically reformed to the
369
+ minimum extent necessary to make it enforceable. If the provision
370
+ cannot be reformed, it shall be severed from this Public License
371
+ without affecting the enforceability of the remaining terms and
372
+ conditions.
373
+
374
+ c. No term or condition of this Public License will be waived and no
375
+ failure to comply consented to unless expressly agreed to by the
376
+ Licensor.
377
+
378
+ d. Nothing in this Public License constitutes or may be interpreted
379
+ as a limitation upon, or waiver of, any privileges and immunities
380
+ that apply to the Licensor or You, including from the legal
381
+ processes of any jurisdiction or authority.
382
+
383
+ =======================================================================
384
+
385
+ Creative Commons is not a party to its public
386
+ licenses. Notwithstanding, Creative Commons may elect to apply one of
387
+ its public licenses to material it publishes and in those instances
388
+ will be considered the “Licensor.” The text of the Creative Commons
389
+ public licenses is dedicated to the public domain under the CC0 Public
390
+ Domain Dedication. Except for the limited purpose of indicating that
391
+ material is shared under a Creative Commons public license or as
392
+ otherwise permitted by the Creative Commons policies published at
393
+ creativecommons.org/policies, Creative Commons does not authorize the
394
+ use of the trademark "Creative Commons" or any other trademark or logo
395
+ of Creative Commons without its prior written consent including,
396
+ without limitation, in connection with any unauthorized modifications
397
+ to any of its public licenses or any other arrangements,
398
+ understandings, or agreements concerning use of licensed material. For
399
+ the avoidance of doubt, this paragraph does not form part of the
400
+ public licenses.
401
+
402
+ Creative Commons may be contacted at creativecommons.org.
403
+
Vtimellm_training_file/README.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # VTimeLLM \[[Paper](https://arxiv.org/pdf/2311.18445.pdf)\]
2
+ Official PyTorch implementation of the paper "VTimeLLM: Empower LLM to Grasp Video Moments".
3
+
4
+
5
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance-4)](https://paperswithcode.com/sota/video-based-generative-performance-4?p=vtimellm-empower-llm-to-grasp-video-moments)
6
+
7
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/dense-video-captioning-on-activitynet)](https://paperswithcode.com/sota/dense-video-captioning-on-activitynet?p=vtimellm-empower-llm-to-grasp-video-moments)
8
+
9
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance-3)](https://paperswithcode.com/sota/video-based-generative-performance-3?p=vtimellm-empower-llm-to-grasp-video-moments)
10
+
11
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance-1)](https://paperswithcode.com/sota/video-based-generative-performance-1?p=vtimellm-empower-llm-to-grasp-video-moments)
12
+
13
+
14
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance-5)](https://paperswithcode.com/sota/video-based-generative-performance-5?p=vtimellm-empower-llm-to-grasp-video-moments)
15
+
16
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance-2)](https://paperswithcode.com/sota/video-based-generative-performance-2?p=vtimellm-empower-llm-to-grasp-video-moments)
17
+
18
+ [![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/vtimellm-empower-llm-to-grasp-video-moments/video-based-generative-performance)](https://paperswithcode.com/sota/video-based-generative-performance?p=vtimellm-empower-llm-to-grasp-video-moments)
19
+
20
+ ---
21
+
22
+ ## :loudspeaker: Latest Updates
23
+ - **Jan-2**: Thanks to [Xiao Xia](https://github.com/Rishubi) , [Shengbo Tong](https://github.com/tsb-19) and [Beining Wang](https://github.com/Benson0704), we have refactored the code to now support both the LLAMA and ChatGLM3 architectures. We translated the training data into Chinese and fine-tuned a Chinese version based on the ChatGLM3-6b.
24
+ - **Dec-14**: Released the training code and data. All the resources including models, datasets and extracted features are available
25
+ [here](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2F&mode=list). :fire::fire:
26
+ - **Dec-4**: VTimeLLM: demo released.
27
+
28
+ ---
29
+
30
+
31
+
32
+ ## VTimeLLM Overview :bulb:
33
+
34
+ VTimeLLM is a novel Video LLM designed for fine-grained video moment understanding and reasoning with respect to time boundary.
35
+
36
+ VTimeLLM adopts a boundary-aware three-stage training strategy, which respectively utilizes image-text pairs for feature alignment, multiple-event videos to increase temporal-boundary awareness, and high-quality video-instruction tuning to further improve temporal understanding ability as well as align with human intents.
37
+
38
+ ![framework](images/framework.png)
39
+
40
+
41
+ ---
42
+
43
+ ## Contributions :trophy:
44
+
45
+ - We propose VTimeLLM, the first boundary-aware Video LLM, to the best of our knowledge.
46
+ - We propose the boundary-aware three-stage training strategy, which consecutively leverages i) large-scale image-text data for feature alignment, ii) large-scale multi-event video-text data together with the temporal-related single-turn and multi-turn QA to enhance the awareness of time boundary, and iii) instruction tuning on the high-quality dialog dataset for better temporal reasoning ability.
47
+ - We conduct extensive experiments to demonstrate that the proposed VTimeLLM significantly outperforms existing Video LLMs in various fine-grained temporal-related video tasks, showing its superior ability for video understanding and reasoning.
48
+
49
+
50
+ ---
51
+
52
+ ## Installation :wrench:
53
+
54
+ We recommend setting up a conda environment for the project:
55
+ ```shell
56
+ conda create --name=vtimellm python=3.10
57
+ conda activate vtimellm
58
+
59
+ git clone https://github.com/huangb23/VTimeLLM.git
60
+ cd VTimeLLM
61
+ pip install -r requirements.txt
62
+ ```
63
+ Additionally, install additional packages for training cases.
64
+ ```shell
65
+ pip install ninja
66
+ pip install flash-attn --no-build-isolation
67
+ ```
68
+
69
+
70
+
71
+ ## Running Demo Offline :cd:
72
+
73
+ To run the demo offline, please refer to the instructions in [offline_demo.md](docs/offline_demo.md).
74
+
75
+ ## Training :train:
76
+
77
+ For training instructions, check out [train.md](docs/train.md).
78
+
79
+ ## Qualitative Analysis :mag:
80
+
81
+ A Comprehensive Evaluation of VTimeLLM's Performance across Multiple Tasks.
82
+
83
+
84
+ ### Video Understanding and Conversational Tasks :speech_balloon:
85
+ ![0](images/ex.png)
86
+
87
+ ---
88
+
89
+ ### Creative Tasks :paintbrush:
90
+ ![1](images/ex1.png)
91
+
92
+ ---
93
+ ### Fine-grained Understanding Tasks :globe_with_meridians:
94
+ ![2](images/ex2.png)
95
+
96
+ ---
97
+ ### Video Reasoning Tasks :question:
98
+ ![3](images/ex3.png)
99
+
100
+ ---
101
+
102
+
103
+ ## Acknowledgements :pray:
104
+
105
+ We are grateful for the following awesome projects our VTimeLLM arising from:
106
+
107
+ * [LLaVA](https://github.com/haotian-liu/LLaVA): Large Language and Vision Assistant
108
+ * [FastChat](https://github.com/lm-sys/FastChat): An Open Platform for Training, Serving, and Evaluating Large Language Model based Chatbots
109
+ * [Video-ChatGPT](https://github.com/mbzuai-oryx/Video-ChatGPT): Towards Detailed Video Understanding via Large Vision and Language Models
110
+ * [LLaMA](https://github.com/facebookresearch/llama): Open and Efficient Foundation Language Models
111
+ * [Vid2seq](https://github.com/google-research/scenic/tree/main/scenic/projects/vid2seq): Large-Scale Pretraining of a Visual Language Model for Dense Video Captioning
112
+ * [InternVid](https://github.com/OpenGVLab/InternVideo/tree/main/Data/InternVid): A Large-scale Video-Text dataset
113
+
114
+
115
+ If you're using VTimeLLM in your research or applications, please cite using this BibTeX:
116
+ ```bibtex
117
+ @article{huang2023vtimellm,
118
+ title={VTimeLLM: Empower LLM to Grasp Video Moments},
119
+ author={Huang, Bin and Wang, Xin and Chen, Hong and Song, Zihan and Zhu, Wenwu},
120
+ journal={arXiv preprint arXiv:2311.18445},
121
+ year={2023}
122
+ }
123
+ ```
124
+
125
+ ## License :scroll:
126
+ <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png" /></a>
127
+
128
+ This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/4.0/">Creative Commons Attribution-NonCommercial-NoDerivs 4.0 International License</a>.
129
+
130
+
131
+ Looking forward to your feedback, contributions, and stars! :star2:
Vtimellm_training_file/demo_gradio.py ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Adapted from: https://github.com/Vision-CAIR/MiniGPT-4/blob/main/demo.py
3
+ """
4
+ import argparse
5
+ import os
6
+ root_dir = os.path.join(os.getcwd(), "..")
7
+ import sys
8
+ sys.path.append(root_dir)
9
+
10
+ import torch
11
+ import gradio as gr
12
+
13
+ import decord
14
+ decord.bridge.set_bridge('torch')
15
+
16
+ from vtimellm.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
17
+ from vtimellm.conversation import conv_templates, SeparatorStyle
18
+ from vtimellm.model.builder import load_pretrained_model
19
+ from vtimellm.utils import disable_torch_init
20
+ from vtimellm.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, VideoExtractor
21
+ from PIL import Image
22
+ from transformers import TextStreamer
23
+ try:
24
+ from torchvision.transforms import InterpolationMode
25
+ BICUBIC = InterpolationMode.BICUBIC
26
+ except ImportError:
27
+ from PIL import Image
28
+ BICUBIC = Image.BICUBIC
29
+ from torchvision.transforms import Compose, Resize, CenterCrop, Normalize
30
+ import clip
31
+
32
+ # def parse_args():
33
+ # parser = argparse.ArgumentParser()
34
+ # parser.add_argument("--gpu_id", type=int, default=0, help="specify the gpu to load the model.")
35
+ # parser.add_argument("--model_base", type=str, required=True, help="Path to your vicuna-7b-v1.5 huggingface checkpoint")
36
+ # parser.add_argument("--clip_path", type=str, default=os.path.join(root_dir, "checkpoints/clip/ViT-L-14.pt"))
37
+ # parser.add_argument("--pretrain_mm_mlp_adapter", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin"))
38
+ # parser.add_argument("--stage2", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage2"))
39
+ # parser.add_argument("--stage3", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage3_test"))
40
+ # parser.add_argument("--share", action='store_true')
41
+ # args = parser.parse_args()
42
+ # return args
43
+
44
+
45
+ def parse_args():
46
+ parser = argparse.ArgumentParser()
47
+ parser.add_argument("--gpu_id", type=int, default=0, help="specify the gpu to load the model.")
48
+ parser.add_argument("--model_base", type=str, required=True, help="Path to your vicuna-7b-v1.5 huggingface checkpoint")
49
+ parser.add_argument("--clip_path", type=str, default="/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/clip/ViT-L-14.pt")
50
+ parser.add_argument("--pretrain_mm_mlp_adapter", type=str, default="/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin")
51
+ parser.add_argument("--stage2", type=str, default="/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/vtimellm-vicuna-v1-5-7b-stage2")
52
+ parser.add_argument("--stage3", type=str, default="/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/vtimellm-vicuna-v1-5-7b-stage3_test")
53
+ parser.add_argument("--share", action='store_true')
54
+ args = parser.parse_args()
55
+ return args
56
+
57
+
58
+
59
+
60
+ # ========================================
61
+ # Model Initialization
62
+ # ========================================
63
+
64
+ args = parse_args()
65
+ device = f'cuda:{args.gpu_id}'
66
+
67
+ disable_torch_init()
68
+ tokenizer, model, context_len = load_pretrained_model(args, args.stage2, args.stage3)
69
+ model = model.to(torch.float16).to(device)
70
+
71
+ clip_model, _ = clip.load(args.clip_path)
72
+ clip_model.eval()
73
+ clip_model = clip_model.to(device)
74
+
75
+ transform = Compose([
76
+ Resize(224, interpolation=BICUBIC),
77
+ CenterCrop(224),
78
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
79
+ ])
80
+
81
+ print('Initialization Finished')
82
+
83
+ # ========================================
84
+ # Gradio Setting
85
+ # ========================================
86
+
87
+ TEXT_PLACEHOLDER = 'Upload your video first, or directly click the examples at the bottom of the page.'
88
+
89
+ def gradio_reset(chat_state, video_features_state, conv_state):
90
+ if chat_state is not None:
91
+ chat_state.messages = []
92
+ video_features_state = None
93
+ conv_state = {}
94
+ return None, gr.update(value=None, interactive=True), gr.update(value='', placeholder=TEXT_PLACEHOLDER, interactive=False), gr.update(value="Upload & Start Chat", interactive=True), chat_state, video_features_state, conv_state
95
+
96
+ def upload_video(gr_video, chat_state, video_features_state, conv_state, chatbot):
97
+ if not gr_video:
98
+ return None, None, gr.update(interactive=True), chat_state, video_features_state, conv_state, None
99
+ else:
100
+ print(gr_video)
101
+ video_loader = VideoExtractor(N=100)
102
+ _, images = video_loader.extract({'id': None, 'video': gr_video})
103
+
104
+ transform = Compose([
105
+ Resize(224, interpolation=BICUBIC),
106
+ CenterCrop(224),
107
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
108
+ ])
109
+
110
+ # print(images.shape) # <N, 3, H, W>
111
+ images = transform(images / 255.0)
112
+ images = images.to(torch.float16)
113
+ with torch.no_grad():
114
+ video_features_state = clip_model.encode_image(images.to('cuda'))
115
+
116
+ chatbot = chatbot + [((gr_video,), None)]
117
+ chat_state = conv_templates["v1"].copy()
118
+ conv_state['first'] = True
119
+
120
+ return gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, video_features_state, conv_state, chatbot
121
+
122
+ def gradio_ask(user_message, chatbot, chat_state, conv_state):
123
+ if len(user_message) == 0:
124
+ conv_state['should_answer'] = False
125
+ return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state, conv_state
126
+ conv_state['should_answer'] = True
127
+ chatbot = chatbot + [[user_message, None]]
128
+ if conv_state['first']:
129
+ user_message = DEFAULT_IMAGE_TOKEN + '\n' + user_message
130
+ conv_state['first'] = False
131
+ chat_state.append_message(chat_state.roles[0], user_message)
132
+ chat_state.append_message(chat_state.roles[1], None)
133
+ return '', chatbot, chat_state, conv_state
134
+
135
+
136
+ def gradio_answer(chatbot, chat_state, video_features_state, conv_state, temperature):
137
+ if not conv_state['should_answer']:
138
+ return chatbot, chat_state
139
+ prompt = chat_state.get_prompt()
140
+ input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(device)
141
+ stop_str = chat_state.sep if chat_state.sep_style != SeparatorStyle.TWO else chat_state.sep2 # plain:sep(###) v1:sep2(None)
142
+ keywords = [stop_str]
143
+ stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
144
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
145
+
146
+ with torch.inference_mode():
147
+ output_ids = model.generate(
148
+ input_ids,
149
+ images=video_features_state[None,].to(device),
150
+ do_sample=True,
151
+ temperature=temperature,
152
+ max_new_tokens=1024,
153
+ streamer=streamer,
154
+ use_cache=True,
155
+ stopping_criteria=[stopping_criteria]
156
+ )
157
+
158
+ outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:]).strip()
159
+ chat_state.messages[-1][-1] = outputs
160
+
161
+ chatbot[-1][1] = outputs
162
+ print(chat_state.get_prompt())
163
+ print(chat_state)
164
+ return chatbot, chat_state
165
+
166
+ with gr.Blocks() as demo:
167
+ gr.Markdown('''# Demo for VTimeLLM''')
168
+
169
+ with gr.Row():
170
+ with gr.Column(scale=0.5):
171
+ video = gr.Video()
172
+
173
+ upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
174
+ clear = gr.Button("Reset")
175
+
176
+ temperature = gr.Slider(
177
+ minimum=0,
178
+ maximum=2.0,
179
+ value=0.05,
180
+ step=0.01,
181
+ interactive=True,
182
+ label="Temperature",
183
+ )
184
+ with gr.Column():
185
+ chat_state = gr.State()
186
+ video_features_state = gr.State()
187
+ conv_state = gr.State({})
188
+ chatbot = gr.Chatbot(label='VTimeLLM')
189
+ text_input = gr.Textbox(label='User', placeholder=TEXT_PLACEHOLDER, interactive=False)
190
+
191
+
192
+ with gr.Column():
193
+ gr.Examples(examples=[
194
+ [os.path.join(root_dir, f"images/demo.mp4"), "Explain why the video is funny."],
195
+ ], inputs=[video, text_input])
196
+
197
+ upload_button.click(upload_video, [video, chat_state, video_features_state, conv_state, chatbot], [video, text_input, upload_button, chat_state, video_features_state, conv_state, chatbot])
198
+ text_input.submit(gradio_ask, [text_input, chatbot, chat_state, conv_state], [text_input, chatbot, chat_state, conv_state]).then(gradio_answer, [chatbot, chat_state, video_features_state, conv_state, temperature], [chatbot, chat_state])
199
+ clear.click(gradio_reset, [chat_state, video_features_state, conv_state], [chatbot, video, text_input, upload_button, chat_state, video_features_state, conv_state], queue=False)
200
+
201
+ demo.queue().launch(share=args.share)
Vtimellm_training_file/docs/data.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Our dataset can be downloaded from [here](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Fdata&mode=list). The data is organized in the following JSON format:
2
+
3
+ * source: The original sources of the dataset. This field is ['internvid'](https://huggingface.co/datasets/OpenGVLab/InternVid) in stage 2 and ['anet'](http://activity-net.org/download.html) or ['didemo'](https://drive.google.com/drive/u/0/folders/1_oyJ5rQiZboipbMl6tkhY8v0s9zDkvJc) in stage 3.
4
+ * id: The ID of the video in the original dataset.
5
+ * conversations: The conversation data used for training. We utilize special tokens (such as `<s0>`, `<e0>`) to indicate timestamps. These need to be replaced during training using information from the 'meta' field.
6
+ * meta:
7
+ * split: refers to the extraction of a segment from the original video as input, with two numbers denoting the start and end timestamps of the extraction. If this field does not exist, the entire video is used as input.
8
+ * duration: indicates the length of the input video.
9
+ * token: represents the timestamp of special tokens appearing in 'conversations'.
10
+
11
+ Here is an example:
12
+
13
+ ```json
14
+ {
15
+ "source": "internvid",
16
+ "id": "3n3oCNerzV0",
17
+ "conversations": [
18
+ {
19
+ "from": "human",
20
+ "value": "<video>\nI'd appreciate it if you could provide a detailed account of the events that occurred at different timestamps in the video."
21
+ },
22
+ {
23
+ "from": "gpt",
24
+ "value": "From <s0> to <e0>, woman is counting money with a pen on a white table. From <s1> to <e1>, two people shaking hands in front of a desk."
25
+ }
26
+ ],
27
+ "meta": {
28
+ "split": [
29
+ 129.8,
30
+ 184.0
31
+ ],
32
+ "duration": 54.2,
33
+ "token": {
34
+ "<s0>": 0,
35
+ "<e0>": 9.4,
36
+ "<s1>": 49.4,
37
+ "<e1>": 53.2
38
+ }
39
+ }
40
+ }
41
+
42
+ ```
43
+
44
+ Due to Internvid's data being sourced from YouTube, the 'id' field provides the YouTube ID of the video. We download the [original video](https://www.youtube.com/watch?v=3n3oCNerzV0) and extract the segment from 129.8s to 184.0s as input.
45
+
46
+ If we sample $N=100$ frames as input, then `<s0>` should be replaced by $\frac{0}{54.2} * N = 00$, `<e0>` should be replaced by $\frac{9.4}{54.2} * N = 17$. and `<s1>` and `<e1>` should be replaced in a similar manner. Finally, in this example, the question from 'human' remains unchanged, while the 'answer' from 'gpt' is shown as below:
47
+
48
+ ```
49
+ From 00 to 17, woman is counting money with a pen on a white table. From 91 to 98, two people shaking hands in front of a desk.
50
+ ```
51
+
52
+
53
+
54
+ In the Stage 3 data, approximately 20k data originate from [VideoChatGPT](https://github.com/mbzuai-oryx/Video-ChatGPT). This subset of data does not contain special tokens and the 'meta' field.
Vtimellm_training_file/docs/eval.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # VTimeLLM-Vicuna Evaluation
2
+
3
+ We provide evaluation code for VTimeLLM-Vicuna on dense video captioning and temporal video grounding tasks. Before proceeding, you should be able to run the inference code (refer to [offline_demo.md](offline_demo.md)). Below, we outline the evaluation process using the [ActivityNet Captions](https://cs.stanford.edu/people/ranjaykrishna/densevid/) dataset as an example.
4
+
5
+ - Download the annotation JSON file for the dataset. For the ActivityNet Captions dataset, the test set annotation file is `val_2.json`. For other datasets, you need to preprocess them to match the JSON format of this dataset.
6
+ - Download the raw videos of the dataset and store them in a specific folder.
7
+ - (Optional) Pre-extract video features (refer to inference.py) and store them in a specific folder. (For the ActivityNet Captions dataset, we have extracted features for approximately 80% of the test set videos, placed in the [feat folder of the stage3 training](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Ffeat&mode=list). You can use them for incomplete testing.)
8
+ - Run the evaluation code, and record the model's responses in a log file. (Specify at least one of `feat_folder` and `video_folder`) :
9
+
10
+ ```bash
11
+ python vtimellm/eval/eval.py \
12
+ --data_path /path/to/val_2.json \
13
+ --feat_folder /path/to/feat \
14
+ --video_folder /path/to/video \
15
+ --log_path /path/to/log \
16
+ --model_base <path to the Vicuna v1.5 weights>
17
+ ```
18
+
19
+ * In order to compute metrics for the dense video captioning task, you need to install `pycocoevalcap` and `Java`.
20
+
21
+ ```bash
22
+ pip install pycocoevalcap
23
+ conda install conda-forge::openjdk
24
+ ```
25
+
26
+ * Parse the log file and obtain the corresponding metrics.
27
+
28
+ ```bash
29
+ python vtimellm/eval/metric.py \
30
+ --data_path /path/to/val_2.json \
31
+ --log_path /path/to/log
32
+ ```
Vtimellm_training_file/docs/inference.ipynb ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "6401fb4e-c559-49e5-bc88-874a74dd54c4",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import os\n",
11
+ "root_dir = os.path.join(os.getcwd(), \"..\")\n",
12
+ "import sys\n",
13
+ "sys.path.append(root_dir)\n",
14
+ "from vtimellm.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN\n",
15
+ "from vtimellm.conversation import conv_templates, SeparatorStyle\n",
16
+ "from vtimellm.model.builder import load_pretrained_model, load_lora\n",
17
+ "from vtimellm.utils import disable_torch_init\n",
18
+ "from vtimellm.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, VideoExtractor\n",
19
+ "from PIL import Image\n",
20
+ "import requests\n",
21
+ "from io import BytesIO\n",
22
+ "from transformers import TextStreamer\n",
23
+ "from easydict import EasyDict as edict\n",
24
+ "try:\n",
25
+ " from torchvision.transforms import InterpolationMode\n",
26
+ " BICUBIC = InterpolationMode.BICUBIC\n",
27
+ "except ImportError:\n",
28
+ " from PIL import Image\n",
29
+ " BICUBIC = Image.BICUBIC\n",
30
+ "from torchvision.transforms import Compose, Resize, CenterCrop, Normalize\n",
31
+ "import numpy as np\n",
32
+ "import clip\n",
33
+ "import torch"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 2,
39
+ "id": "a05c755d-ae5c-4e93-ae6f-4e4a6e795b14",
40
+ "metadata": {},
41
+ "outputs": [],
42
+ "source": [
43
+ "args = edict()\n",
44
+ "args.model_base = \"/path/to/vicuna-7b-v1.5\"\n",
45
+ "args.clip_path = os.path.join(root_dir, \"checkpoints/clip/ViT-L-14.pt\")\n",
46
+ "args.pretrain_mm_mlp_adapter = os.path.join(root_dir, \"checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin\")\n",
47
+ "args.stage2 = os.path.join(root_dir, \"checkpoints/vtimellm-vicuna-v1-5-7b-stage2\")\n",
48
+ "args.stage3 = os.path.join(root_dir, \"checkpoints/vtimellm-vicuna-v1-5-7b-stage3\")\n",
49
+ "args.video_path = os.path.join(root_dir, \"images/demo.mp4\")\n",
50
+ "args.temperature = 0.05"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 3,
56
+ "id": "d3815e10-d5a5-4fdf-a98f-ae9050f23b97",
57
+ "metadata": {},
58
+ "outputs": [],
59
+ "source": [
60
+ "def inference(model, tokenizer, context_len, image, args):\n",
61
+ " conv = conv_templates['v1'].copy()\n",
62
+ " roles = conv.roles\n",
63
+ " first = True\n",
64
+ " while True:\n",
65
+ " try:\n",
66
+ " inp = input(f\"{roles[0]}: \")\n",
67
+ " except EOFError:\n",
68
+ " inp = \"\"\n",
69
+ " if not inp:\n",
70
+ " print(\"exit...\")\n",
71
+ " break\n",
72
+ "\n",
73
+ " print(f\"{roles[1]}: \", end=\"\")\n",
74
+ "\n",
75
+ " if first:\n",
76
+ " # first message\n",
77
+ " inp = DEFAULT_IMAGE_TOKEN + '\\n' + inp\n",
78
+ " conv.append_message(conv.roles[0], inp)\n",
79
+ " first = False\n",
80
+ " else:\n",
81
+ " # later messages\n",
82
+ " conv.append_message(conv.roles[0], inp)\n",
83
+ " conv.append_message(conv.roles[1], None)\n",
84
+ " prompt = conv.get_prompt()\n",
85
+ "\n",
86
+ " input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).cuda()\n",
87
+ " stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2 # plain:sep(###) v1:sep2(None)\n",
88
+ " keywords = [stop_str]\n",
89
+ " stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)\n",
90
+ " streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)\n",
91
+ "\n",
92
+ " with torch.inference_mode():\n",
93
+ " output_ids = model.generate(\n",
94
+ " input_ids,\n",
95
+ " images=image[None,].cuda(),\n",
96
+ " do_sample=True,\n",
97
+ " temperature=args.temperature,\n",
98
+ " max_new_tokens=1024,\n",
99
+ " streamer=streamer,\n",
100
+ " use_cache=True,\n",
101
+ " stopping_criteria=[stopping_criteria]\n",
102
+ " )\n",
103
+ "\n",
104
+ " outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:]).strip()\n",
105
+ " conv.messages[-1][-1] = outputs"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": 4,
111
+ "id": "a29e94ff-620e-4c86-adee-47206b67b606",
112
+ "metadata": {},
113
+ "outputs": [
114
+ {
115
+ "name": "stderr",
116
+ "output_type": "stream",
117
+ "text": [
118
+ "You are using a model of type llama to instantiate a model of type VTimeLLM. This is not supported for all configurations of models and can yield errors.\n"
119
+ ]
120
+ },
121
+ {
122
+ "name": "stdout",
123
+ "output_type": "stream",
124
+ "text": [
125
+ "Loading VTimeLLM from base model...\n"
126
+ ]
127
+ },
128
+ {
129
+ "data": {
130
+ "application/vnd.jupyter.widget-view+json": {
131
+ "model_id": "8c13771904c8424abf87e3e2507e4bd8",
132
+ "version_major": 2,
133
+ "version_minor": 0
134
+ },
135
+ "text/plain": [
136
+ "Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
137
+ ]
138
+ },
139
+ "metadata": {},
140
+ "output_type": "display_data"
141
+ },
142
+ {
143
+ "name": "stderr",
144
+ "output_type": "stream",
145
+ "text": [
146
+ "/home/bhuang/miniconda3/envs/vtime/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:381: UserWarning: `do_sample` is set to `False`. However, `temperature` is set to `0.9` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `temperature`. This was detected when initializing the generation config instance, which means the corresponding file may hold incorrect parameterization and should be fixed.\n",
147
+ " warnings.warn(\n",
148
+ "/home/bhuang/miniconda3/envs/vtime/lib/python3.10/site-packages/transformers/generation/configuration_utils.py:386: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.6` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`. This was detected when initializing the generation config instance, which means the corresponding file may hold incorrect parameterization and should be fixed.\n",
149
+ " warnings.warn(\n"
150
+ ]
151
+ },
152
+ {
153
+ "name": "stdout",
154
+ "output_type": "stream",
155
+ "text": [
156
+ "load mlp: /DATA/DATANAS2/bhuang/link/gitlab/vtimellm/docs/../checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin\n",
157
+ "Loading stage2 weights...\n",
158
+ "Loading LoRA weights...\n",
159
+ "Merging stage2 weights...\n",
160
+ "Loading stage3 weights...\n",
161
+ "Loading LoRA weights...\n",
162
+ "Merging stage3 weights...\n"
163
+ ]
164
+ }
165
+ ],
166
+ "source": [
167
+ "disable_torch_init()\n",
168
+ "tokenizer, model, context_len = load_pretrained_model(args, args.stage2, args.stage3)\n",
169
+ "model = model.cuda()\n",
170
+ "model = model.to(torch.float16)"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": 5,
176
+ "id": "f8165baa-775b-4106-88aa-3c723bd97c12",
177
+ "metadata": {},
178
+ "outputs": [
179
+ {
180
+ "name": "stderr",
181
+ "output_type": "stream",
182
+ "text": [
183
+ "/home/bhuang/miniconda3/envs/vtime/lib/python3.10/site-packages/torchvision/transforms/functional.py:1603: UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends. To suppress this warning, directly pass antialias=True (recommended, future default), antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). This also applies if you are using the inference transforms from the models weights: update the call to weights.transforms(antialias=True).\n",
184
+ " warnings.warn(\n"
185
+ ]
186
+ }
187
+ ],
188
+ "source": [
189
+ "clip_model, _ = clip.load(args.clip_path)\n",
190
+ "clip_model.eval()\n",
191
+ "clip_model = clip_model.cuda()\n",
192
+ "\n",
193
+ "video_loader = VideoExtractor(N=100)\n",
194
+ "_, images = video_loader.extract({'id': None, 'video': args.video_path})\n",
195
+ "\n",
196
+ "transform = Compose([\n",
197
+ " Resize(224, interpolation=BICUBIC),\n",
198
+ " CenterCrop(224),\n",
199
+ " Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),\n",
200
+ "])\n",
201
+ "\n",
202
+ "# print(images.shape) # <N, 3, H, W>\n",
203
+ "images = transform(images / 255.0)\n",
204
+ "images = images.to(torch.float16)\n",
205
+ "with torch.no_grad():\n",
206
+ " features = clip_model.encode_image(images.to('cuda'))"
207
+ ]
208
+ },
209
+ {
210
+ "cell_type": "code",
211
+ "execution_count": 8,
212
+ "id": "010a986d-6121-43f2-9971-619472c0732c",
213
+ "metadata": {},
214
+ "outputs": [
215
+ {
216
+ "name": "stdin",
217
+ "output_type": "stream",
218
+ "text": [
219
+ "USER: Explain why this video is funny.\n"
220
+ ]
221
+ },
222
+ {
223
+ "name": "stdout",
224
+ "output_type": "stream",
225
+ "text": [
226
+ "ASSISTANT: The video is funny because the bear is dancing to the music and moving its arms and legs in a funny way. The bear's movements are exaggerated and comical, making it difficult for the person to keep up with the beat. The bear's facial expressions and body language add to the humor of the video.\n"
227
+ ]
228
+ },
229
+ {
230
+ "name": "stdin",
231
+ "output_type": "stream",
232
+ "text": [
233
+ "USER: Is it a real bear?\n"
234
+ ]
235
+ },
236
+ {
237
+ "name": "stdout",
238
+ "output_type": "stream",
239
+ "text": [
240
+ "ASSISTANT: No, it is not a real bear. It is a costume worn by a person.\n"
241
+ ]
242
+ },
243
+ {
244
+ "name": "stdin",
245
+ "output_type": "stream",
246
+ "text": [
247
+ "USER: \n"
248
+ ]
249
+ },
250
+ {
251
+ "name": "stdout",
252
+ "output_type": "stream",
253
+ "text": [
254
+ "exit...\n"
255
+ ]
256
+ }
257
+ ],
258
+ "source": [
259
+ "inference(model, tokenizer, context_len, features, args)"
260
+ ]
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "execution_count": null,
265
+ "id": "ef73e662-cab9-46fa-9df8-b45e2b1d9f5b",
266
+ "metadata": {},
267
+ "outputs": [],
268
+ "source": []
269
+ }
270
+ ],
271
+ "metadata": {
272
+ "kernelspec": {
273
+ "display_name": "Python 3 (ipykernel)",
274
+ "language": "python",
275
+ "name": "python3"
276
+ },
277
+ "language_info": {
278
+ "codemirror_mode": {
279
+ "name": "ipython",
280
+ "version": 3
281
+ },
282
+ "file_extension": ".py",
283
+ "mimetype": "text/x-python",
284
+ "name": "python",
285
+ "nbconvert_exporter": "python",
286
+ "pygments_lexer": "ipython3",
287
+ "version": "3.10.13"
288
+ }
289
+ },
290
+ "nbformat": 4,
291
+ "nbformat_minor": 5
292
+ }
Vtimellm_training_file/docs/inference_for_glm.ipynb ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "6401fb4e-c559-49e5-bc88-874a74dd54c4",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/DATA/DATANAS2/bhuang/link/gitlab/vtimellm/docs/..\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import os\n",
19
+ "os.environ['CUDA_VISIBLE_DEVICES'] = '0'\n",
20
+ "root_dir = os.path.join(os.getcwd(), \"..\")\n",
21
+ "print(root_dir)\n",
22
+ "import sys\n",
23
+ "sys.path.append(root_dir)\n",
24
+ "\n",
25
+ "from vtimellm.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN\n",
26
+ "from vtimellm.conversation import conv_templates, SeparatorStyle\n",
27
+ "from vtimellm.model.builder import load_pretrained_model, load_lora\n",
28
+ "from vtimellm.train.dataset import preprocess_glm\n",
29
+ "from vtimellm.utils import disable_torch_init\n",
30
+ "from vtimellm.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, VideoExtractor\n",
31
+ "from PIL import Image\n",
32
+ "import requests\n",
33
+ "from io import BytesIO\n",
34
+ "from transformers import TextStreamer\n",
35
+ "from easydict import EasyDict as edict\n",
36
+ "try:\n",
37
+ " from torchvision.transforms import InterpolationMode\n",
38
+ " BICUBIC = InterpolationMode.BICUBIC\n",
39
+ "except ImportError:\n",
40
+ " from PIL import Image\n",
41
+ " BICUBIC = Image.BICUBIC\n",
42
+ "from torchvision.transforms import Compose, Resize, CenterCrop, Normalize\n",
43
+ "import numpy as np\n",
44
+ "import clip\n",
45
+ "import torch"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 3,
51
+ "id": "a05c755d-ae5c-4e93-ae6f-4e4a6e795b14",
52
+ "metadata": {},
53
+ "outputs": [],
54
+ "source": [
55
+ "model_version = 'chatglm3-6b' # vicuna-v1-5-7b\n",
56
+ "args = edict()\n",
57
+ "args.model_base = \"/DATA/DATANAS2/bhuang/data/vicuna-7b-v1.5\"\n",
58
+ "if model_version == 'chatglm3-6b':\n",
59
+ " args.model_base = os.path.join(root_dir, 'checkpoints/' + model_version)\n",
60
+ "args.clip_path = os.path.join(root_dir, \"checkpoints/clip/ViT-L-14.pt\")\n",
61
+ "args.pretrain_mm_mlp_adapter = os.path.join(root_dir, f\"checkpoints/vtimellm-{model_version}-stage1/mm_projector.bin\")\n",
62
+ "args.stage2 = os.path.join(root_dir, f\"checkpoints/vtimellm-{model_version}-stage2\")\n",
63
+ "args.stage3 = os.path.join(root_dir, f\"checkpoints/vtimellm-{model_version}-stage3\")\n",
64
+ "args.temperature = 0.05"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": 4,
70
+ "id": "7cb39bb4",
71
+ "metadata": {},
72
+ "outputs": [
73
+ {
74
+ "name": "stderr",
75
+ "output_type": "stream",
76
+ "text": [
77
+ "You are using a model of type chatglm to instantiate a model of type VTimeLLM_ChatGLM. This is not supported for all configurations of models and can yield errors.\n"
78
+ ]
79
+ },
80
+ {
81
+ "name": "stdout",
82
+ "output_type": "stream",
83
+ "text": [
84
+ "Loading VTimeLLM from base model...\n"
85
+ ]
86
+ },
87
+ {
88
+ "data": {
89
+ "application/vnd.jupyter.widget-view+json": {
90
+ "model_id": "20832fd2d2a44b7f8d540c32069df157",
91
+ "version_major": 2,
92
+ "version_minor": 0
93
+ },
94
+ "text/plain": [
95
+ "Loading checkpoint shards: 0%| | 0/7 [00:00<?, ?it/s]"
96
+ ]
97
+ },
98
+ "metadata": {},
99
+ "output_type": "display_data"
100
+ },
101
+ {
102
+ "name": "stdout",
103
+ "output_type": "stream",
104
+ "text": [
105
+ "load mlp: /DATA/DATANAS2/bhuang/link/gitlab/vtimellm/docs/../checkpoints/vtimellm-chatglm3-6b-stage1/mm_projector.bin\n",
106
+ "Loading stage2 weights...\n",
107
+ "Loading LoRA weights...\n",
108
+ "Merging stage2 weights...\n",
109
+ "Loading stage3 weights...\n",
110
+ "Loading LoRA weights...\n",
111
+ "Merging stage3 weights...\n"
112
+ ]
113
+ }
114
+ ],
115
+ "source": [
116
+ "disable_torch_init()\n",
117
+ "tokenizer, model, context_len = load_pretrained_model(args, args.stage2, args.stage3)\n",
118
+ "model = model.cuda()\n",
119
+ "model = model.to(torch.float16)"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 13,
125
+ "id": "f8165baa-775b-4106-88aa-3c723bd97c12",
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "clip_model, _ = clip.load(args.clip_path)\n",
130
+ "clip_model.eval()\n",
131
+ "clip_model = clip_model.cuda()\n",
132
+ "\n",
133
+ "video_loader = VideoExtractor(N=100)\n",
134
+ "\n",
135
+ "transform = Compose([\n",
136
+ " Resize(224, interpolation=BICUBIC),\n",
137
+ " CenterCrop(224),\n",
138
+ " Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),\n",
139
+ "])\n"
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": null,
145
+ "id": "b0038bac",
146
+ "metadata": {},
147
+ "outputs": [],
148
+ "source": [
149
+ "args.video_path = '/DATA/DATANAS2/bhuang/link/1.mp4'\n",
150
+ "_, images = video_loader.extract({'id': None, 'video': args.video_path})\n",
151
+ "# print(images.shape) # <N, 3, H, W>\n",
152
+ "images = transform(images / 255.0)\n",
153
+ "images = images.to(torch.float16)\n",
154
+ "with torch.no_grad():\n",
155
+ " features = clip_model.encode_image(images.to('cuda'))"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 14,
161
+ "id": "7b42d546",
162
+ "metadata": {},
163
+ "outputs": [],
164
+ "source": [
165
+ "def inference(model, tokenizer, context_len, image, args):\n",
166
+ " source = []\n",
167
+ " first = True\n",
168
+ " while True:\n",
169
+ " try:\n",
170
+ " inp = input(f\"USER: \")\n",
171
+ " except EOFError:\n",
172
+ " inp = \"\"\n",
173
+ " if not inp:\n",
174
+ " print(\"exit...\")\n",
175
+ " break\n",
176
+ "\n",
177
+ " print(f\"ASSISTANT:\", end=\"\")\n",
178
+ "\n",
179
+ " if first:\n",
180
+ " # first message\n",
181
+ " inp = DEFAULT_IMAGE_TOKEN + '\\n' + inp\n",
182
+ " first = False\n",
183
+ " \n",
184
+ " source.append({\n",
185
+ " 'from': \"human\",\n",
186
+ " 'value': inp\n",
187
+ " })\n",
188
+ " input_ids = preprocess_glm([source], tokenizer)['input_ids'].cuda()\n",
189
+ " input_ids[0][-1] = tokenizer.get_command(\"<|assistant|>\")\n",
190
+ " streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)\n",
191
+ "\n",
192
+ " with torch.inference_mode():\n",
193
+ " output_ids = model.generate(\n",
194
+ " input_ids,\n",
195
+ " images=image[None,].cuda(),\n",
196
+ " do_sample=True,\n",
197
+ " temperature=args.temperature,\n",
198
+ " max_new_tokens=1024,\n",
199
+ " streamer=streamer,\n",
200
+ " use_cache=True,\n",
201
+ " eos_token_id=[tokenizer.get_command(\"<|user|>\"), tokenizer.eos_token_id],\n",
202
+ " )\n",
203
+ "\n",
204
+ " outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:-1]).strip()\n",
205
+ " # print(outputs)\n",
206
+ " source.append({\n",
207
+ " 'from': \"gpt\",\n",
208
+ " 'value': outputs\n",
209
+ " })"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": 19,
215
+ "id": "010a986d-6121-43f2-9971-619472c0732c",
216
+ "metadata": {},
217
+ "outputs": [
218
+ {
219
+ "name": "stdout",
220
+ "output_type": "stream",
221
+ "text": [
222
+ "ASSISTANT:视频中,一名男子在黑暗的房间里,手里拿着一个装满东西的盒子。他打开盒子,里面装满了各种物品。然后,该男子爬上一座高高的建筑物,并从窗户跳入水中。<|user|>\n",
223
+ "exit...\n"
224
+ ]
225
+ }
226
+ ],
227
+ "source": [
228
+ "inference(model, tokenizer, context_len, features, args)"
229
+ ]
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "execution_count": null,
234
+ "id": "ef73e662-cab9-46fa-9df8-b45e2b1d9f5b",
235
+ "metadata": {},
236
+ "outputs": [],
237
+ "source": []
238
+ }
239
+ ],
240
+ "metadata": {
241
+ "kernelspec": {
242
+ "display_name": "Python 3 (ipykernel)",
243
+ "language": "python",
244
+ "name": "python3"
245
+ },
246
+ "language_info": {
247
+ "codemirror_mode": {
248
+ "name": "ipython",
249
+ "version": 3
250
+ },
251
+ "file_extension": ".py",
252
+ "mimetype": "text/x-python",
253
+ "name": "python",
254
+ "nbconvert_exporter": "python",
255
+ "pygments_lexer": "ipython3",
256
+ "version": "3.10.12"
257
+ }
258
+ },
259
+ "nbformat": 4,
260
+ "nbformat_minor": 5
261
+ }
Vtimellm_training_file/docs/offline_demo.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Running VTimeLLM inference Offline
2
+ Please follow the instructions below to run the VTimeLLM inference on your local GPU machine.
3
+
4
+ Note: Our demo requires approximately 18 GB of GPU memory.
5
+
6
+ ### Clone the VTimeLLM repository
7
+
8
+ ```shell
9
+ conda create --name=vtimellm python=3.10
10
+ conda activate vtimellm
11
+
12
+ git clone https://github.com/huangb23/VTimeLLM.git
13
+ cd VTimeLLM
14
+ pip install -r requirements.txt
15
+ ```
16
+
17
+ ### Download weights
18
+
19
+ * Download clip model and vtimellm model from the [Tsinghua Cloud](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Fcheckpoints&mode=list) and place them into the 'checkpoints' directory.
20
+ * Download [Vicuna v1.5](https://huggingface.co/lmsys/vicuna-7b-v1.5) or [ChatGLM3-6b](https://huggingface.co/THUDM/chatglm3-6b) weights.
21
+
22
+ ### Run the inference code
23
+
24
+
25
+ ```shell
26
+ python -m vtimellm.inference --model_base <path to the Vicuna v1.5 weights>
27
+ ```
28
+
29
+ Alternatively, you can also choose to conduct multi-turn conversations in [Jupyter Notebook](inference.ipynb). Similarly, you need to set 'args.model_base' to the path of Vicuna v1.5.
30
+
31
+ If you want to run the VTimeLLM-ChatGLM version, please refer to the code in [inference_for_glm.ipynb](inference_for_glm.ipynb).
32
+
33
+ ### Run the gradio demo
34
+
35
+ We have provided an offline gradio demo as follows:
36
+
37
+ ```shell
38
+ cd vtimellm
39
+ python demo_gradio.py --model_base <path to the Vicuna v1.5 weights>
40
+ ```
Vtimellm_training_file/docs/train.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Training VTimeLLM
2
+ VTimeLLM adopts a three-stage training strategy. Please follow the instructions below to train VTimeLLM-7B model.
3
+
4
+
5
+ * Download [clip](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Fcheckpoints&mode=list) and [Vicuna v1.5](https://huggingface.co/lmsys/vicuna-7b-v1.5) weights, and place them into the 'checkpoints' directory.
6
+
7
+ * Download stage1 dataset from [this link](https://huggingface.co/datasets/liuhaotian/LLaVA-Pretrain/blob/main/blip_laion_cc_sbu_558k.json), and download stage2 and stage3 dataset from the [Tsinghua Cloud](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Fdata&mode=list). Place them into the 'data' directory.
8
+
9
+ ```markdown
10
+ - VTimeLLM
11
+ - checkpoints
12
+ - clip
13
+ - ViT-L-14.pt
14
+ - vicuna-7b-v1.5
15
+ - pytorch_model-00001-of-00002.bin
16
+ - ...
17
+ - data
18
+ - blip_laion_cc_sbu_558k.json
19
+ - stage2.json
20
+ - stage3.json
21
+ - scripts
22
+ - stage1.sh
23
+ - stage2.sh
24
+ - stage3.sh
25
+ - ...
26
+ - vtimellm
27
+ - ...
28
+ ```
29
+
30
+ If you want to train a Chinese version, you can download the [ChatGLM3-6b](https://huggingface.co/THUDM/chatglm3-6b) model and the translated Chinese [dataset](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Fdata&mode=list).
31
+
32
+ * Download the pre-extracted features from the [Tsinghua Cloud](https://cloud.tsinghua.edu.cn/d/6db5d02883124826aa6f/?p=%2Ffeat&mode=list).
33
+
34
+ ```shell
35
+ tar -xzvf stage1.tar.gz
36
+ cat stage2_part_* > stage2.tar.gz
37
+ tar -xzvf stage2.tar.gz
38
+ tar -xzvf stage3.tar.gz
39
+ ```
40
+
41
+ * Train in three stages sequentially, and make sure to modify '--feat_folder' in the script to the corresponding feature folder for each stage.
42
+
43
+ ```shell
44
+ cd VTimeLLM
45
+ bash scripts/stage1.sh
46
+ bash scripts/stage2.sh
47
+ bash scripts/stage3.sh
48
+ ```
Vtimellm_training_file/final_test_24th_April_1_4data_1test.txt ADDED
@@ -0,0 +1,940 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
2
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
3
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
4
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
5
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
6
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'image': tensor([[ 0.0422, 0.3201, -0.0559, ..., -0.0818, 0.6021, -0.6768],
7
+ [ 0.4595, 0.8301, 0.2019, ..., -0.2246, 0.5537, -0.8135],
8
+ [ 0.2966, 0.7563, 0.1559, ..., -0.3000, 0.4294, -0.8125],
9
+ ...,
10
+ [ 0.2211, 0.7349, -0.0161, ..., -0.4021, 0.0947, -0.4202],
11
+ [ 0.1953, 0.5195, -0.1005, ..., -0.4133, -0.0293, -0.1360],
12
+ [ 0.3845, 0.8208, -0.2043, ..., -0.1575, 0.0444, -0.4380]],
13
+ dtype=torch.float16)}
14
+ torch.Size([137])
15
+ torch.Size([137])
16
+ torch.Size([100, 768])
17
+ #####
18
+ One data instance
19
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame <s1>, a child in white hugs another child in black in the room, positioned at <b0>. The child in white continues to hug the other child until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
20
+ #####
21
+ [('<s0>', '0'), ('<e0>', '385'), ('<s1>', '252'), ('<e1>', '357'), ('<b0>', '[252, 139, 352, 375]'), ('<b1>', '[383, 206, 525, 294]')]
22
+ #####
23
+ One data instance after running through replace set
24
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame 252, a child in white hugs another child in black in the room, positioned at [252, 139, 352, 375]. The child in white continues to hug the other child until frame 357, where the child is positioned at [383, 206, 525, 294].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
25
+ #####
26
+ ######conversation_lib
27
+ SeparatorStyle.TWO
28
+ v1
29
+ ######conversation_lib
30
+ #######
31
+ data_dict
32
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
33
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
34
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
35
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 298,
36
+ 16926, 278, 916, 2278, 297, 4628, 297, 278, 5716, 29973,
37
+ 319, 1799, 9047, 13566, 29901, 512, 3515, 29871, 29906, 29945,
38
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
39
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
40
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
41
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
42
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
43
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
44
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
45
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
46
+ 29906, 29929, 29946, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
47
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
48
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
49
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
50
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
51
+ -100, -100, -100, -100, -100, 512, 3515, 29871, 29906, 29945,
52
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
53
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
54
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
55
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
56
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
57
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
58
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
59
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
60
+ 29906, 29929, 29946, 1822, 2]), 'image': tensor([[ 0.8340, 0.2842, -0.1917, ..., -0.3215, 0.0374, -0.2896],
61
+ [ 0.6167, 0.3005, -0.1210, ..., -0.3838, -0.1924, -0.6260],
62
+ [ 0.5537, 0.2585, -0.1090, ..., -0.4512, -0.2510, -0.3374],
63
+ ...,
64
+ [ 0.4771, 0.1232, 0.3928, ..., 0.1825, 0.0554, 0.3025],
65
+ [ 0.6187, -0.0942, 0.1740, ..., 0.4150, 0.0103, -0.0715],
66
+ [ 0.4312, -0.2664, 0.3335, ..., 0.6445, 0.6592, 0.5059]],
67
+ dtype=torch.float16)}
68
+ torch.Size([145])
69
+ torch.Size([145])
70
+ torch.Size([100, 768])
71
+ {'loss': 0.0, 'learning_rate': 6.5558167183898955e-09, 'epoch': 796.0}
72
+ 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎| 796/800 [06:37<00:01, 2.19it/s]#####
73
+ One data instance
74
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is an adult man in black holding a glass cup at position <b0>. The adult man continues to hold the glass cup until frame <e1>, where he is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
75
+ #####
76
+ [('<s0>', '0'), ('<e0>', '603'), ('<s1>', '127'), ('<e1>', '603'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[93, 27, 187, 239]')]
77
+ #####
78
+ One data instance after running through replace set
79
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame 127, there is an adult man in black holding a glass cup at position [0, 31, 84, 239]. The adult man continues to hold the glass cup until frame 603, where he is positioned at [93, 27, 187, 239].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
80
+ #####
81
+ ######conversation_lib
82
+ SeparatorStyle.TWO
83
+ v1
84
+ ######conversation_lib
85
+ #######
86
+ data_dict
87
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
88
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
89
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
90
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 947,
91
+ 278, 16157, 767, 297, 4628, 4808, 29973, 319, 1799, 9047,
92
+ 13566, 29901, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
93
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
94
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
95
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
96
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
97
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
98
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
99
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
100
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
101
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
102
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
103
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
104
+ -100, -100, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
105
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
106
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
107
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
108
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
109
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
110
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
111
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'image': tensor([[ 1.2549, 0.5737, -0.4932, ..., -0.1276, 0.8149, 0.1995],
112
+ [ 0.7183, 0.5371, -0.0024, ..., 0.0521, 0.5864, 0.4255],
113
+ [ 0.9702, 0.6221, -0.2578, ..., -0.0831, 0.3081, -0.0594],
114
+ ...,
115
+ [ 0.6636, 0.4399, 0.0314, ..., -0.4177, 0.9780, 0.1987],
116
+ [ 0.3945, 0.1537, -0.2203, ..., -0.1005, 0.9824, -0.4868],
117
+ [ 0.0748, 0.4792, -0.4011, ..., -0.0442, 1.0859, -0.4531]],
118
+ dtype=torch.float16)}
119
+ torch.Size([129])
120
+ torch.Size([129])
121
+ torch.Size([100, 768])
122
+ #####
123
+ One data instance
124
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a white horse beneath an adult man in black, positioned at <b0>. The horse remains beneath the adult man until frame <e1>, where it is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
125
+ #####
126
+ [('<s0>', '0'), ('<e0>', '1724'), ('<s1>', '191'), ('<e1>', '1706'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[364, 159, 508, 461]')]
127
+ #####
128
+ One data instance after running through replace set
129
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame 191, there is a white horse beneath an adult man in black, positioned at [0, 31, 84, 239]. The horse remains beneath the adult man until frame 1706, where it is positioned at [364, 159, 508, 461].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
130
+ #####
131
+ ######conversation_lib
132
+ SeparatorStyle.TWO
133
+ v1
134
+ ######conversation_lib
135
+ #######
136
+ data_dict
137
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
138
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
139
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
140
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 338,
141
+ 19540, 278, 16157, 767, 297, 4628, 29973, 319, 1799, 9047,
142
+ 13566, 29901, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
143
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
144
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
145
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
146
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
147
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
148
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
149
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
150
+ 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
151
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
152
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
153
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
154
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
155
+ -100, -100, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
156
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
157
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
158
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
159
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
160
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
161
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
162
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
163
+ 1822, 2]), 'image': tensor([[ 0.9053, -0.1750, 0.1433, ..., -0.3354, -0.1893, -0.4050],
164
+ [ 0.6919, -0.6729, -0.0498, ..., -0.2344, -0.2496, -0.3933],
165
+ [ 0.5737, -0.5757, -0.2644, ..., -0.2742, -0.4312, -0.4548],
166
+ ...,
167
+ [ 0.7729, -0.0404, 0.1102, ..., -0.6523, -0.6045, -0.4050],
168
+ [ 0.9331, -0.0336, -0.0042, ..., -0.7095, -0.4521, -0.5132],
169
+ [ 0.8691, -0.0680, 0.0805, ..., -0.4463, -0.4468, -0.4731]],
170
+ dtype=torch.float16)}
171
+ torch.Size([132])
172
+ torch.Size([132])
173
+ torch.Size([100, 768])
174
+ #####
175
+ One data instance
176
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame <s1>, a child in white hugs another child in black in the room, positioned at <b0>. The child in white continues to hug the other child until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
177
+ #####
178
+ [('<s0>', '0'), ('<e0>', '385'), ('<s1>', '252'), ('<e1>', '357'), ('<b0>', '[252, 139, 352, 375]'), ('<b1>', '[383, 206, 525, 294]')]
179
+ #####
180
+ One data instance after running through replace set
181
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame 252, a child in white hugs another child in black in the room, positioned at [252, 139, 352, 375]. The child in white continues to hug the other child until frame 357, where the child is positioned at [383, 206, 525, 294].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
182
+ #####
183
+ ######conversation_lib
184
+ SeparatorStyle.TWO
185
+ v1
186
+ ######conversation_lib
187
+ #######
188
+ data_dict
189
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
190
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
191
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
192
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 298,
193
+ 16926, 278, 916, 2278, 297, 4628, 297, 278, 5716, 29973,
194
+ 319, 1799, 9047, 13566, 29901, 512, 3515, 29871, 29906, 29945,
195
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
196
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
197
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
198
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
199
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
200
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
201
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
202
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
203
+ 29906, 29929, 29946, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
204
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
205
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
206
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
207
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
208
+ -100, -100, -100, -100, -100, 512, 3515, 29871, 29906, 29945,
209
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
210
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
211
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
212
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
213
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
214
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
215
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
216
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
217
+ 29906, 29929, 29946, 1822, 2]), 'image': tensor([[ 0.8340, 0.2842, -0.1917, ..., -0.3215, 0.0374, -0.2896],
218
+ [ 0.6167, 0.3005, -0.1210, ..., -0.3838, -0.1924, -0.6260],
219
+ [ 0.5537, 0.2585, -0.1090, ..., -0.4512, -0.2510, -0.3374],
220
+ ...,
221
+ [ 0.4771, 0.1232, 0.3928, ..., 0.1825, 0.0554, 0.3025],
222
+ [ 0.6187, -0.0942, 0.1740, ..., 0.4150, 0.0103, -0.0715],
223
+ [ 0.4312, -0.2664, 0.3335, ..., 0.6445, 0.6592, 0.5059]],
224
+ dtype=torch.float16)}
225
+ torch.Size([145])
226
+ torch.Size([145])
227
+ torch.Size([100, 768])
228
+ #####
229
+ One data instance
230
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a child wearing blue pants towards an adult wearing a mask, positioned at <b0>. The child remains towards the adult until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
231
+ #####
232
+ [('<s0>', '0'), ('<e0>', '1823'), ('<s1>', '883'), ('<e1>', '1104'), ('<b0>', '[198, 32, 242, 164]'), ('<b1>', '[0, 79, 27, 243]')]
233
+ #####
234
+ One data instance after running through replace set
235
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame 883, there is a child wearing blue pants towards an adult wearing a mask, positioned at [198, 32, 242, 164]. The child remains towards the adult until frame 1104, where the child is positioned at [0, 79, 27, 243].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
236
+ #####
237
+ ######conversation_lib
238
+ SeparatorStyle.TWO
239
+ v1
240
+ ######conversation_lib
241
+ #######
242
+ data_dict
243
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
244
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
245
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
246
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 338,
247
+ 7113, 278, 16157, 591, 4362, 263, 11105, 29973, 319, 1799,
248
+ 9047, 13566, 29901, 512, 3515, 29871, 29947, 29947, 29941, 29892,
249
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
250
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
251
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
252
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
253
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
254
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
255
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
256
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
257
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
258
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
259
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
260
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
261
+ -100, -100, -100, 512, 3515, 29871, 29947, 29947, 29941, 29892,
262
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
263
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
264
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
265
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
266
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
267
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
268
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
269
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'image': tensor([[ 0.0422, 0.3201, -0.0559, ..., -0.0818, 0.6021, -0.6768],
270
+ [ 0.4595, 0.8301, 0.2019, ..., -0.2246, 0.5537, -0.8135],
271
+ [ 0.2966, 0.7563, 0.1559, ..., -0.3000, 0.4294, -0.8125],
272
+ ...,
273
+ [ 0.2211, 0.7349, -0.0161, ..., -0.4021, 0.0947, -0.4202],
274
+ [ 0.1953, 0.5195, -0.1005, ..., -0.4133, -0.0293, -0.1360],
275
+ [ 0.3845, 0.8208, -0.2043, ..., -0.1575, 0.0444, -0.4380]],
276
+ dtype=torch.float16)}
277
+ torch.Size([137])
278
+ torch.Size([137])
279
+ torch.Size([100, 768])
280
+ {'loss': 0.0, 'learning_rate': 3.6876821611464553e-09, 'epoch': 797.0}
281
+ 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍| 797/800 [06:37<00:01, 2.20it/s]#####
282
+ One data instance
283
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame <s1>, a child in white hugs another child in black in the room, positioned at <b0>. The child in white continues to hug the other child until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
284
+ #####
285
+ [('<s0>', '0'), ('<e0>', '385'), ('<s1>', '252'), ('<e1>', '357'), ('<b0>', '[252, 139, 352, 375]'), ('<b1>', '[383, 206, 525, 294]')]
286
+ #####
287
+ One data instance after running through replace set
288
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame 252, a child in white hugs another child in black in the room, positioned at [252, 139, 352, 375]. The child in white continues to hug the other child until frame 357, where the child is positioned at [383, 206, 525, 294].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
289
+ #####
290
+ ######conversation_lib
291
+ SeparatorStyle.TWO
292
+ v1
293
+ ######conversation_lib
294
+ #######
295
+ data_dict
296
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
297
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
298
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
299
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 298,
300
+ 16926, 278, 916, 2278, 297, 4628, 297, 278, 5716, 29973,
301
+ 319, 1799, 9047, 13566, 29901, 512, 3515, 29871, 29906, 29945,
302
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
303
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
304
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
305
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
306
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
307
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
308
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
309
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
310
+ 29906, 29929, 29946, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
311
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
312
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
313
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
314
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
315
+ -100, -100, -100, -100, -100, 512, 3515, 29871, 29906, 29945,
316
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
317
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
318
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
319
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
320
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
321
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
322
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
323
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
324
+ 29906, 29929, 29946, 1822, 2]), 'image': tensor([[ 0.8340, 0.2842, -0.1917, ..., -0.3215, 0.0374, -0.2896],
325
+ [ 0.6167, 0.3005, -0.1210, ..., -0.3838, -0.1924, -0.6260],
326
+ [ 0.5537, 0.2585, -0.1090, ..., -0.4512, -0.2510, -0.3374],
327
+ ...,
328
+ [ 0.4771, 0.1232, 0.3928, ..., 0.1825, 0.0554, 0.3025],
329
+ [ 0.6187, -0.0942, 0.1740, ..., 0.4150, 0.0103, -0.0715],
330
+ [ 0.4312, -0.2664, 0.3335, ..., 0.6445, 0.6592, 0.5059]],
331
+ dtype=torch.float16)}
332
+ torch.Size([145])
333
+ torch.Size([145])
334
+ torch.Size([100, 768])
335
+ #####
336
+ One data instance
337
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is an adult man in black holding a glass cup at position <b0>. The adult man continues to hold the glass cup until frame <e1>, where he is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
338
+ #####
339
+ [('<s0>', '0'), ('<e0>', '603'), ('<s1>', '127'), ('<e1>', '603'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[93, 27, 187, 239]')]
340
+ #####
341
+ One data instance after running through replace set
342
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame 127, there is an adult man in black holding a glass cup at position [0, 31, 84, 239]. The adult man continues to hold the glass cup until frame 603, where he is positioned at [93, 27, 187, 239].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
343
+ #####
344
+ ######conversation_lib
345
+ SeparatorStyle.TWO
346
+ v1
347
+ ######conversation_lib
348
+ #######
349
+ data_dict
350
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
351
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
352
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
353
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 947,
354
+ 278, 16157, 767, 297, 4628, 4808, 29973, 319, 1799, 9047,
355
+ 13566, 29901, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
356
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
357
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
358
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
359
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
360
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
361
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
362
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
363
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
364
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
365
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
366
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
367
+ -100, -100, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
368
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
369
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
370
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
371
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
372
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
373
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
374
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'image': tensor([[ 1.2549, 0.5737, -0.4932, ..., -0.1276, 0.8149, 0.1995],
375
+ [ 0.7183, 0.5371, -0.0024, ..., 0.0521, 0.5864, 0.4255],
376
+ [ 0.9702, 0.6221, -0.2578, ..., -0.0831, 0.3081, -0.0594],
377
+ ...,
378
+ [ 0.6636, 0.4399, 0.0314, ..., -0.4177, 0.9780, 0.1987],
379
+ [ 0.3945, 0.1537, -0.2203, ..., -0.1005, 0.9824, -0.4868],
380
+ [ 0.0748, 0.4792, -0.4011, ..., -0.0442, 1.0859, -0.4531]],
381
+ dtype=torch.float16)}
382
+ torch.Size([129])
383
+ torch.Size([129])
384
+ torch.Size([100, 768])
385
+ #####
386
+ One data instance
387
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a child wearing blue pants towards an adult wearing a mask, positioned at <b0>. The child remains towards the adult until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
388
+ #####
389
+ [('<s0>', '0'), ('<e0>', '1823'), ('<s1>', '883'), ('<e1>', '1104'), ('<b0>', '[198, 32, 242, 164]'), ('<b1>', '[0, 79, 27, 243]')]
390
+ #####
391
+ One data instance after running through replace set
392
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame 883, there is a child wearing blue pants towards an adult wearing a mask, positioned at [198, 32, 242, 164]. The child remains towards the adult until frame 1104, where the child is positioned at [0, 79, 27, 243].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
393
+ #####
394
+ ######conversation_lib
395
+ SeparatorStyle.TWO
396
+ v1
397
+ ######conversation_lib
398
+ #######
399
+ data_dict
400
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
401
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
402
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
403
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 338,
404
+ 7113, 278, 16157, 591, 4362, 263, 11105, 29973, 319, 1799,
405
+ 9047, 13566, 29901, 512, 3515, 29871, 29947, 29947, 29941, 29892,
406
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
407
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
408
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
409
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
410
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
411
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
412
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
413
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
414
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
415
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
416
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
417
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
418
+ -100, -100, -100, 512, 3515, 29871, 29947, 29947, 29941, 29892,
419
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
420
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
421
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
422
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
423
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
424
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
425
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
426
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'image': tensor([[ 0.0422, 0.3201, -0.0559, ..., -0.0818, 0.6021, -0.6768],
427
+ [ 0.4595, 0.8301, 0.2019, ..., -0.2246, 0.5537, -0.8135],
428
+ [ 0.2966, 0.7563, 0.1559, ..., -0.3000, 0.4294, -0.8125],
429
+ ...,
430
+ [ 0.2211, 0.7349, -0.0161, ..., -0.4021, 0.0947, -0.4202],
431
+ [ 0.1953, 0.5195, -0.1005, ..., -0.4133, -0.0293, -0.1360],
432
+ [ 0.3845, 0.8208, -0.2043, ..., -0.1575, 0.0444, -0.4380]],
433
+ dtype=torch.float16)}
434
+ torch.Size([137])
435
+ torch.Size([137])
436
+ torch.Size([100, 768])
437
+ #####
438
+ One data instance
439
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a white horse beneath an adult man in black, positioned at <b0>. The horse remains beneath the adult man until frame <e1>, where it is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
440
+ #####
441
+ [('<s0>', '0'), ('<e0>', '1724'), ('<s1>', '191'), ('<e1>', '1706'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[364, 159, 508, 461]')]
442
+ #####
443
+ One data instance after running through replace set
444
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame 191, there is a white horse beneath an adult man in black, positioned at [0, 31, 84, 239]. The horse remains beneath the adult man until frame 1706, where it is positioned at [364, 159, 508, 461].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
445
+ #####
446
+ ######conversation_lib
447
+ SeparatorStyle.TWO
448
+ v1
449
+ ######conversation_lib
450
+ #######
451
+ data_dict
452
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
453
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
454
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
455
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 338,
456
+ 19540, 278, 16157, 767, 297, 4628, 29973, 319, 1799, 9047,
457
+ 13566, 29901, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
458
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
459
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
460
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
461
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
462
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
463
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
464
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
465
+ 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
466
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
467
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
468
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
469
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
470
+ -100, -100, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
471
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
472
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
473
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
474
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
475
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
476
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
477
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
478
+ 1822, 2]), 'image': tensor([[ 0.9053, -0.1750, 0.1433, ..., -0.3354, -0.1893, -0.4050],
479
+ [ 0.6919, -0.6729, -0.0498, ..., -0.2344, -0.2496, -0.3933],
480
+ [ 0.5737, -0.5757, -0.2644, ..., -0.2742, -0.4312, -0.4548],
481
+ ...,
482
+ [ 0.7729, -0.0404, 0.1102, ..., -0.6523, -0.6045, -0.4050],
483
+ [ 0.9331, -0.0336, -0.0042, ..., -0.7095, -0.4521, -0.5132],
484
+ [ 0.8691, -0.0680, 0.0805, ..., -0.4463, -0.4468, -0.4731]],
485
+ dtype=torch.float16)}
486
+ torch.Size([132])
487
+ torch.Size([132])
488
+ torch.Size([100, 768])
489
+ {'loss': 0.0, 'learning_rate': 1.6389810421846286e-09, 'epoch': 798.0}
490
+ 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋| 798/800 [06:37<00:00, 2.20it/s]#####
491
+ One data instance
492
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a child wearing blue pants towards an adult wearing a mask, positioned at <b0>. The child remains towards the adult until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
493
+ #####
494
+ [('<s0>', '0'), ('<e0>', '1823'), ('<s1>', '883'), ('<e1>', '1104'), ('<b0>', '[198, 32, 242, 164]'), ('<b1>', '[0, 79, 27, 243]')]
495
+ #####
496
+ One data instance after running through replace set
497
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame 883, there is a child wearing blue pants towards an adult wearing a mask, positioned at [198, 32, 242, 164]. The child remains towards the adult until frame 1104, where the child is positioned at [0, 79, 27, 243].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
498
+ #####
499
+ ######conversation_lib
500
+ SeparatorStyle.TWO
501
+ v1
502
+ ######conversation_lib
503
+ #######
504
+ data_dict
505
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
506
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
507
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
508
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 338,
509
+ 7113, 278, 16157, 591, 4362, 263, 11105, 29973, 319, 1799,
510
+ 9047, 13566, 29901, 512, 3515, 29871, 29947, 29947, 29941, 29892,
511
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
512
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
513
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
514
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
515
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
516
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
517
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
518
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
519
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
520
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
521
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
522
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
523
+ -100, -100, -100, 512, 3515, 29871, 29947, 29947, 29941, 29892,
524
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
525
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
526
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
527
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
528
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
529
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
530
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
531
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'image': tensor([[ 0.0422, 0.3201, -0.0559, ..., -0.0818, 0.6021, -0.6768],
532
+ [ 0.4595, 0.8301, 0.2019, ..., -0.2246, 0.5537, -0.8135],
533
+ [ 0.2966, 0.7563, 0.1559, ..., -0.3000, 0.4294, -0.8125],
534
+ ...,
535
+ [ 0.2211, 0.7349, -0.0161, ..., -0.4021, 0.0947, -0.4202],
536
+ [ 0.1953, 0.5195, -0.1005, ..., -0.4133, -0.0293, -0.1360],
537
+ [ 0.3845, 0.8208, -0.2043, ..., -0.1575, 0.0444, -0.4380]],
538
+ dtype=torch.float16)}
539
+ torch.Size([137])
540
+ torch.Size([137])
541
+ torch.Size([100, 768])
542
+ #####
543
+ One data instance
544
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a white horse beneath an adult man in black, positioned at <b0>. The horse remains beneath the adult man until frame <e1>, where it is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
545
+ #####
546
+ [('<s0>', '0'), ('<e0>', '1724'), ('<s1>', '191'), ('<e1>', '1706'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[364, 159, 508, 461]')]
547
+ #####
548
+ One data instance after running through replace set
549
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame 191, there is a white horse beneath an adult man in black, positioned at [0, 31, 84, 239]. The horse remains beneath the adult man until frame 1706, where it is positioned at [364, 159, 508, 461].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
550
+ #####
551
+ ######conversation_lib
552
+ SeparatorStyle.TWO
553
+ v1
554
+ ######conversation_lib
555
+ #######
556
+ data_dict
557
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
558
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
559
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
560
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 338,
561
+ 19540, 278, 16157, 767, 297, 4628, 29973, 319, 1799, 9047,
562
+ 13566, 29901, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
563
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
564
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
565
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
566
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
567
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
568
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
569
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
570
+ 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
571
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
572
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
573
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
574
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
575
+ -100, -100, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
576
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
577
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
578
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
579
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
580
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
581
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
582
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
583
+ 1822, 2]), 'image': tensor([[ 0.9053, -0.1750, 0.1433, ..., -0.3354, -0.1893, -0.4050],
584
+ [ 0.6919, -0.6729, -0.0498, ..., -0.2344, -0.2496, -0.3933],
585
+ [ 0.5737, -0.5757, -0.2644, ..., -0.2742, -0.4312, -0.4548],
586
+ ...,
587
+ [ 0.7729, -0.0404, 0.1102, ..., -0.6523, -0.6045, -0.4050],
588
+ [ 0.9331, -0.0336, -0.0042, ..., -0.7095, -0.4521, -0.5132],
589
+ [ 0.8691, -0.0680, 0.0805, ..., -0.4463, -0.4468, -0.4731]],
590
+ dtype=torch.float16)}
591
+ torch.Size([132])
592
+ torch.Size([132])
593
+ torch.Size([100, 768])
594
+ #####
595
+ One data instance
596
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame <s1>, a child in white hugs another child in black in the room, positioned at <b0>. The child in white continues to hug the other child until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
597
+ #####
598
+ [('<s0>', '0'), ('<e0>', '385'), ('<s1>', '252'), ('<e1>', '357'), ('<b0>', '[252, 139, 352, 375]'), ('<b1>', '[383, 206, 525, 294]')]
599
+ #####
600
+ One data instance after running through replace set
601
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame 252, a child in white hugs another child in black in the room, positioned at [252, 139, 352, 375]. The child in white continues to hug the other child until frame 357, where the child is positioned at [383, 206, 525, 294].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
602
+ #####
603
+ ######conversation_lib
604
+ SeparatorStyle.TWO
605
+ v1
606
+ ######conversation_lib
607
+ #######
608
+ data_dict
609
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
610
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
611
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
612
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 298,
613
+ 16926, 278, 916, 2278, 297, 4628, 297, 278, 5716, 29973,
614
+ 319, 1799, 9047, 13566, 29901, 512, 3515, 29871, 29906, 29945,
615
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
616
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
617
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
618
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
619
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
620
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
621
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
622
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
623
+ 29906, 29929, 29946, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
624
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
625
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
626
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
627
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
628
+ -100, -100, -100, -100, -100, 512, 3515, 29871, 29906, 29945,
629
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
630
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
631
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
632
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
633
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
634
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
635
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
636
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
637
+ 29906, 29929, 29946, 1822, 2]), 'image': tensor([[ 0.8340, 0.2842, -0.1917, ..., -0.3215, 0.0374, -0.2896],
638
+ [ 0.6167, 0.3005, -0.1210, ..., -0.3838, -0.1924, -0.6260],
639
+ [ 0.5537, 0.2585, -0.1090, ..., -0.4512, -0.2510, -0.3374],
640
+ ...,
641
+ [ 0.4771, 0.1232, 0.3928, ..., 0.1825, 0.0554, 0.3025],
642
+ [ 0.6187, -0.0942, 0.1740, ..., 0.4150, 0.0103, -0.0715],
643
+ [ 0.4312, -0.2664, 0.3335, ..., 0.6445, 0.6592, 0.5059]],
644
+ dtype=torch.float16)}
645
+ torch.Size([145])
646
+ torch.Size([145])
647
+ torch.Size([100, 768])
648
+ #####
649
+ One data instance
650
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is an adult man in black holding a glass cup at position <b0>. The adult man continues to hold the glass cup until frame <e1>, where he is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
651
+ #####
652
+ [('<s0>', '0'), ('<e0>', '603'), ('<s1>', '127'), ('<e1>', '603'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[93, 27, 187, 239]')]
653
+ #####
654
+ One data instance after running through replace set
655
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame 127, there is an adult man in black holding a glass cup at position [0, 31, 84, 239]. The adult man continues to hold the glass cup until frame 603, where he is positioned at [93, 27, 187, 239].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
656
+ #####
657
+ ######conversation_lib
658
+ SeparatorStyle.TWO
659
+ v1
660
+ ######conversation_lib
661
+ #######
662
+ data_dict
663
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
664
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
665
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
666
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 947,
667
+ 278, 16157, 767, 297, 4628, 4808, 29973, 319, 1799, 9047,
668
+ 13566, 29901, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
669
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
670
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
671
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
672
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
673
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
674
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
675
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
676
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
677
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
678
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
679
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
680
+ -100, -100, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
681
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
682
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
683
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
684
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
685
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
686
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
687
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'image': tensor([[ 1.2549, 0.5737, -0.4932, ..., -0.1276, 0.8149, 0.1995],
688
+ [ 0.7183, 0.5371, -0.0024, ..., 0.0521, 0.5864, 0.4255],
689
+ [ 0.9702, 0.6221, -0.2578, ..., -0.0831, 0.3081, -0.0594],
690
+ ...,
691
+ [ 0.6636, 0.4399, 0.0314, ..., -0.4177, 0.9780, 0.1987],
692
+ [ 0.3945, 0.1537, -0.2203, ..., -0.1005, 0.9824, -0.4868],
693
+ [ 0.0748, 0.4792, -0.4011, ..., -0.0442, 1.0859, -0.4531]],
694
+ dtype=torch.float16)}
695
+ torch.Size([129])
696
+ torch.Size([129])
697
+ torch.Size([100, 768])
698
+ {'loss': 0.0, 'learning_rate': 4.0974693947259944e-10, 'epoch': 799.0}
699
+ 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊| 799/800 [06:38<00:00, 2.21it/s]#####
700
+ One data instance
701
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a white horse beneath an adult man in black, positioned at <b0>. The horse remains beneath the adult man until frame <e1>, where it is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
702
+ #####
703
+ [('<s0>', '0'), ('<e0>', '1724'), ('<s1>', '191'), ('<e1>', '1706'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[364, 159, 508, 461]')]
704
+ #####
705
+ One data instance after running through replace set
706
+ {'id': '2769996915', 'conversations': [{'from': 'human', 'value': '<video>\nWhat is beneath the adult man in black?'}, {'from': 'gpt', 'value': 'In frame 191, there is a white horse beneath an adult man in black, positioned at [0, 31, 84, 239]. The horse remains beneath the adult man until frame 1706, where it is positioned at [364, 159, 508, 461].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1724, '<s1>': 191, '<e1>': 1706, '<b0>': [0, 31, 84, 239], '<b1>': [364, 159, 508, 461]}}, 'source': 'anet'}
707
+ #####
708
+ ######conversation_lib
709
+ SeparatorStyle.TWO
710
+ v1
711
+ ######conversation_lib
712
+ #######
713
+ data_dict
714
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
715
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
716
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
717
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 338,
718
+ 19540, 278, 16157, 767, 297, 4628, 29973, 319, 1799, 9047,
719
+ 13566, 29901, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
720
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
721
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
722
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
723
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
724
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
725
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
726
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
727
+ 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
728
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
729
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
730
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
731
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
732
+ -100, -100, 512, 3515, 29871, 29896, 29929, 29896, 29892, 727,
733
+ 338, 263, 4796, 10435, 19540, 385, 16157, 767, 297, 4628,
734
+ 29892, 2602, 287, 472, 518, 29900, 29892, 29871, 29941, 29896,
735
+ 29892, 29871, 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822,
736
+ 450, 10435, 9242, 19540, 278, 16157, 767, 2745, 3515, 29871,
737
+ 29896, 29955, 29900, 29953, 29892, 988, 372, 338, 2602, 287,
738
+ 472, 518, 29941, 29953, 29946, 29892, 29871, 29896, 29945, 29929,
739
+ 29892, 29871, 29945, 29900, 29947, 29892, 29871, 29946, 29953, 29896,
740
+ 1822, 2]), 'image': tensor([[ 0.9053, -0.1750, 0.1433, ..., -0.3354, -0.1893, -0.4050],
741
+ [ 0.6919, -0.6729, -0.0498, ..., -0.2344, -0.2496, -0.3933],
742
+ [ 0.5737, -0.5757, -0.2644, ..., -0.2742, -0.4312, -0.4548],
743
+ ...,
744
+ [ 0.7729, -0.0404, 0.1102, ..., -0.6523, -0.6045, -0.4050],
745
+ [ 0.9331, -0.0336, -0.0042, ..., -0.7095, -0.4521, -0.5132],
746
+ [ 0.8691, -0.0680, 0.0805, ..., -0.4463, -0.4468, -0.4731]],
747
+ dtype=torch.float16)}
748
+ torch.Size([132])
749
+ torch.Size([132])
750
+ torch.Size([100, 768])
751
+ #####
752
+ One data instance
753
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame <s1>, a child in white hugs another child in black in the room, positioned at <b0>. The child in white continues to hug the other child until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
754
+ #####
755
+ [('<s0>', '0'), ('<e0>', '385'), ('<s1>', '252'), ('<e1>', '357'), ('<b0>', '[252, 139, 352, 375]'), ('<b1>', '[383, 206, 525, 294]')]
756
+ #####
757
+ One data instance after running through replace set
758
+ {'id': '4284560730', 'conversations': [{'from': 'human', 'value': '<video>\nWho hugs the other child in black in the room?'}, {'from': 'gpt', 'value': 'In frame 252, a child in white hugs another child in black in the room, positioned at [252, 139, 352, 375]. The child in white continues to hug the other child until frame 357, where the child is positioned at [383, 206, 525, 294].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 385, '<s1>': 252, '<e1>': 357, '<b0>': [252, 139, 352, 375], '<b1>': [383, 206, 525, 294]}}, 'source': 'anet'}
759
+ #####
760
+ ######conversation_lib
761
+ SeparatorStyle.TWO
762
+ v1
763
+ ######conversation_lib
764
+ #######
765
+ data_dict
766
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
767
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
768
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
769
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 298,
770
+ 16926, 278, 916, 2278, 297, 4628, 297, 278, 5716, 29973,
771
+ 319, 1799, 9047, 13566, 29901, 512, 3515, 29871, 29906, 29945,
772
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
773
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
774
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
775
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
776
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
777
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
778
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
779
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
780
+ 29906, 29929, 29946, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
781
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
782
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
783
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
784
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
785
+ -100, -100, -100, -100, -100, 512, 3515, 29871, 29906, 29945,
786
+ 29906, 29892, 263, 2278, 297, 4796, 298, 16926, 1790, 2278,
787
+ 297, 4628, 297, 278, 5716, 29892, 2602, 287, 472, 518,
788
+ 29906, 29945, 29906, 29892, 29871, 29896, 29941, 29929, 29892, 29871,
789
+ 29941, 29945, 29906, 29892, 29871, 29941, 29955, 29945, 1822, 450,
790
+ 2278, 297, 4796, 18172, 304, 298, 688, 278, 916, 2278,
791
+ 2745, 3515, 29871, 29941, 29945, 29955, 29892, 988, 278, 2278,
792
+ 338, 2602, 287, 472, 518, 29941, 29947, 29941, 29892, 29871,
793
+ 29906, 29900, 29953, 29892, 29871, 29945, 29906, 29945, 29892, 29871,
794
+ 29906, 29929, 29946, 1822, 2]), 'image': tensor([[ 0.8340, 0.2842, -0.1917, ..., -0.3215, 0.0374, -0.2896],
795
+ [ 0.6167, 0.3005, -0.1210, ..., -0.3838, -0.1924, -0.6260],
796
+ [ 0.5537, 0.2585, -0.1090, ..., -0.4512, -0.2510, -0.3374],
797
+ ...,
798
+ [ 0.4771, 0.1232, 0.3928, ..., 0.1825, 0.0554, 0.3025],
799
+ [ 0.6187, -0.0942, 0.1740, ..., 0.4150, 0.0103, -0.0715],
800
+ [ 0.4312, -0.2664, 0.3335, ..., 0.6445, 0.6592, 0.5059]],
801
+ dtype=torch.float16)}
802
+ torch.Size([145])
803
+ torch.Size([145])
804
+ torch.Size([100, 768])
805
+ #####
806
+ One data instance
807
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is an adult man in black holding a glass cup at position <b0>. The adult man continues to hold the glass cup until frame <e1>, where he is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
808
+ #####
809
+ [('<s0>', '0'), ('<e0>', '603'), ('<s1>', '127'), ('<e1>', '603'), ('<b0>', '[0, 31, 84, 239]'), ('<b1>', '[93, 27, 187, 239]')]
810
+ #####
811
+ One data instance after running through replace set
812
+ {'id': '2727682922', 'conversations': [{'from': 'human', 'value': '<video>\nWhat does the adult man in black hold?'}, {'from': 'gpt', 'value': 'In frame 127, there is an adult man in black holding a glass cup at position [0, 31, 84, 239]. The adult man continues to hold the glass cup until frame 603, where he is positioned at [93, 27, 187, 239].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 603, '<s1>': 127, '<e1>': 603, '<b0>': [0, 31, 84, 239], '<b1>': [93, 27, 187, 239]}}, 'source': 'anet'}
813
+ #####
814
+ ######conversation_lib
815
+ SeparatorStyle.TWO
816
+ v1
817
+ ######conversation_lib
818
+ #######
819
+ data_dict
820
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
821
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
822
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
823
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 5618, 947,
824
+ 278, 16157, 767, 297, 4628, 4808, 29973, 319, 1799, 9047,
825
+ 13566, 29901, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
826
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
827
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
828
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
829
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
830
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
831
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
832
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
833
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
834
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
835
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
836
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
837
+ -100, -100, 512, 3515, 29871, 29896, 29906, 29955, 29892, 727,
838
+ 338, 385, 16157, 767, 297, 4628, 13587, 263, 12917, 18002,
839
+ 472, 2602, 518, 29900, 29892, 29871, 29941, 29896, 29892, 29871,
840
+ 29947, 29946, 29892, 29871, 29906, 29941, 29929, 1822, 450, 16157,
841
+ 767, 18172, 304, 4808, 278, 12917, 18002, 2745, 3515, 29871,
842
+ 29953, 29900, 29941, 29892, 988, 540, 338, 2602, 287, 472,
843
+ 518, 29929, 29941, 29892, 29871, 29906, 29955, 29892, 29871, 29896,
844
+ 29947, 29955, 29892, 29871, 29906, 29941, 29929, 1822, 2]), 'image': tensor([[ 1.2549, 0.5737, -0.4932, ..., -0.1276, 0.8149, 0.1995],
845
+ [ 0.7183, 0.5371, -0.0024, ..., 0.0521, 0.5864, 0.4255],
846
+ [ 0.9702, 0.6221, -0.2578, ..., -0.0831, 0.3081, -0.0594],
847
+ ...,
848
+ [ 0.6636, 0.4399, 0.0314, ..., -0.4177, 0.9780, 0.1987],
849
+ [ 0.3945, 0.1537, -0.2203, ..., -0.1005, 0.9824, -0.4868],
850
+ [ 0.0748, 0.4792, -0.4011, ..., -0.0442, 1.0859, -0.4531]],
851
+ dtype=torch.float16)}
852
+ torch.Size([129])
853
+ torch.Size([129])
854
+ torch.Size([100, 768])
855
+ #####
856
+ One data instance
857
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame <s1>, there is a child wearing blue pants towards an adult wearing a mask, positioned at <b0>. The child remains towards the adult until frame <e1>, where the child is positioned at <b1>.'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
858
+ #####
859
+ [('<s0>', '0'), ('<e0>', '1823'), ('<s1>', '883'), ('<e1>', '1104'), ('<b0>', '[198, 32, 242, 164]'), ('<b1>', '[0, 79, 27, 243]')]
860
+ #####
861
+ One data instance after running through replace set
862
+ {'id': '4655213495', 'conversations': [{'from': 'human', 'value': '<video>\nWho is towards the adult wearing a mask?'}, {'from': 'gpt', 'value': 'In frame 883, there is a child wearing blue pants towards an adult wearing a mask, positioned at [198, 32, 242, 164]. The child remains towards the adult until frame 1104, where the child is positioned at [0, 79, 27, 243].'}], 'meta': {'token': {'<s0>': 0, '<e0>': 1823, '<s1>': 883, '<e1>': 1104, '<b0>': [198, 32, 242, 164], '<b1>': [0, 79, 27, 243]}}, 'source': 'anet'}
863
+ #####
864
+ ######conversation_lib
865
+ SeparatorStyle.TWO
866
+ v1
867
+ ######conversation_lib
868
+ #######
869
+ data_dict
870
+ {'input_ids': tensor([ 1, 319, 13563, 1546, 263, 12758, 1404, 322, 385, 23116,
871
+ 21082, 20255, 29889, 450, 20255, 4076, 8444, 29892, 13173, 29892,
872
+ 322, 1248, 568, 6089, 304, 278, 1404, 29915, 29879, 5155,
873
+ 29889, 3148, 1001, 29901, 29871, -200, 29871, 13, 22110, 338,
874
+ 7113, 278, 16157, 591, 4362, 263, 11105, 29973, 319, 1799,
875
+ 9047, 13566, 29901, 512, 3515, 29871, 29947, 29947, 29941, 29892,
876
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
877
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
878
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
879
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
880
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
881
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
882
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
883
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'labels': tensor([ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
884
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
885
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
886
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
887
+ -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
888
+ -100, -100, -100, 512, 3515, 29871, 29947, 29947, 29941, 29892,
889
+ 727, 338, 263, 2278, 591, 4362, 7254, 282, 1934, 7113,
890
+ 385, 16157, 591, 4362, 263, 11105, 29892, 2602, 287, 472,
891
+ 518, 29896, 29929, 29947, 29892, 29871, 29941, 29906, 29892, 29871,
892
+ 29906, 29946, 29906, 29892, 29871, 29896, 29953, 29946, 1822, 450,
893
+ 2278, 9242, 7113, 278, 16157, 2745, 3515, 29871, 29896, 29896,
894
+ 29900, 29946, 29892, 988, 278, 2278, 338, 2602, 287, 472,
895
+ 518, 29900, 29892, 29871, 29955, 29929, 29892, 29871, 29906, 29955,
896
+ 29892, 29871, 29906, 29946, 29941, 1822, 2]), 'image': tensor([[ 0.0422, 0.3201, -0.0559, ..., -0.0818, 0.6021, -0.6768],
897
+ [ 0.4595, 0.8301, 0.2019, ..., -0.2246, 0.5537, -0.8135],
898
+ [ 0.2966, 0.7563, 0.1559, ..., -0.3000, 0.4294, -0.8125],
899
+ ...,
900
+ [ 0.2211, 0.7349, -0.0161, ..., -0.4021, 0.0947, -0.4202],
901
+ [ 0.1953, 0.5195, -0.1005, ..., -0.4133, -0.0293, -0.1360],
902
+ [ 0.3845, 0.8208, -0.2043, ..., -0.1575, 0.0444, -0.4380]],
903
+ dtype=torch.float16)}
904
+ torch.Size([137])
905
+ torch.Size([137])
906
+ torch.Size([100, 768])
907
+ {'loss': 0.0, 'learning_rate': 0.0, 'epoch': 800.0}
908
+ 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 800/800 [06:38<00:00, 2.18it/s]You are using a model of type llama to instantiate a model of type VTimeLLM. This is not supported for all configurations of models and can yield errors.
909
+ {'train_runtime': 429.9732, 'train_samples_per_second': 7.442, 'train_steps_per_second': 1.861, 'train_loss': 0.021921285937876858, 'epoch': 800.0}
910
+ 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 800/800 [07:07<00:00, 1.87it/s]
911
+ You are using a model of type llama to instantiate a model of type VTimeLLM. This is not supported for all configurations of models and can yield errors.
912
+ wandb: / 0.122 MB of 0.122 MB uploaded
913
+ wandb: Run history:
914
+ wandb: train/epoch ▁▁▁▁▂▂▂▂▂▃▃▃▃▃▃▄▄▄▄▄▅▅▅▅▅▅▆▆▆▆▆▇▇▇▇▇▇███
915
+ wandb: train/global_step ▁▁▁▁▂▂▂▂▂▃▃▃▃▃▃▄▄▄▄▄▅▅▅▅▅▅▆▆▆▆▆▇▇▇▇▇▇███
916
+ wandb: train/learning_rate ▃███████▇▇▇▇▇▆▆▆▆▅▅▅▅▄▄▄▃▃▃▃▂▂▂▂▂▁▁▁▁▁▁▁
917
+ wandb: train/loss █▆▄▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
918
+ wandb: train/total_flos ▁
919
+ wandb: train/train_loss ▁
920
+ wandb: train/train_runtime ▁
921
+ wandb: train/train_samples_per_second ▁
922
+ wandb: train/train_steps_per_second ▁
923
+ wandb:
924
+ wandb: Run summary:
925
+ wandb: train/epoch 800.0
926
+ wandb: train/global_step 800
927
+ wandb: train/learning_rate 0.0
928
+ wandb: train/loss 0.0
929
+ wandb: train/total_flos 1.88487978450944e+16
930
+ wandb: train/train_loss 0.02192
931
+ wandb: train/train_runtime 429.9732
932
+ wandb: train/train_samples_per_second 7.442
933
+ wandb: train/train_steps_per_second 1.861
934
+ wandb:
935
+ wandb: 🚀 View run tough-pond-17 at: https://wandb.ai/imr165/huggingface/runs/8hkwf2fw
936
+ wandb: ️⚡ View job at https://wandb.ai/imr165/huggingface/jobs/QXJ0aWZhY3RDb2xsZWN0aW9uOjE2NTY1NDY5MQ==/version_details/v3
937
+ wandb: Synced 6 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)
938
+ wandb: Find logs at: ./wandb/run-20240424_092011-8hkwf2fw/logs
939
+ [2024-04-24 09:27:29,661] [INFO] [launch.py:348:main] Process 637937 exits successfully.
940
+ (vtimellm) imr555@iftysDen:~/Downloads/UCF_CV/project_update_2/VTimeLLM$
Vtimellm_training_file/images/demo.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:510e1ce6ff51ccd2427dfd4c4d8e78decef14fbceb5e3c7d7bd658c370496217
3
+ size 1001272
Vtimellm_training_file/images/ex.png ADDED
Vtimellm_training_file/images/ex1.png ADDED
Vtimellm_training_file/images/ex2.png ADDED
Vtimellm_training_file/images/ex3.png ADDED
Vtimellm_training_file/images/framework.png ADDED
Vtimellm_training_file/requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #torch
2
+ decord
3
+ easydict
4
+ einops
5
+ gradio
6
+ numpy
7
+ pandas>=2.0.3
8
+ peft>=0.4.0
9
+ Pillow
10
+ tqdm
11
+ transformers==4.31.0
12
+ git+https://github.com/openai/CLIP.git
13
+ sentencepiece
14
+ protobuf
15
+ wandb
16
+ deepspeed
Vtimellm_training_file/scripts/stage1.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=vicuna-v1-5-7b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
9
+ --deepspeed ./scripts/zero3.json \
10
+ --model_name_or_path ./checkpoints/vicuna-7b-v1.5 \
11
+ --version plain \
12
+ --data_path ./data/blip_laion_cc_sbu_558k.json \
13
+ --feat_folder /path/to/stage1_feat \
14
+ --tune_mm_mlp_adapter True \
15
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage1 \
16
+ --bf16 True \
17
+ --num_train_epochs 1 \
18
+ --per_device_train_batch_size 16 \
19
+ --gradient_accumulation_steps 8 \
20
+ --evaluation_strategy "no" \
21
+ --save_strategy "steps" \
22
+ --save_steps 24000 \
23
+ --save_total_limit 1 \
24
+ --learning_rate 1e-3 \
25
+ --weight_decay 0. \
26
+ --warmup_ratio 0.03 \
27
+ --lr_scheduler_type "cosine" \
28
+ --logging_steps 1 \
29
+ --tf32 True \
30
+ --model_max_length 2048 \
31
+ --gradient_checkpointing True \
32
+ --dataloader_num_workers 4 \
33
+ --lazy_preprocess True \
34
+ --report_to wandb
Vtimellm_training_file/scripts/stage1_glm.sh ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=chatglm3-6b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train.py \
9
+ --deepspeed ./scripts/zero3.json \
10
+ --model_name_or_path ./checkpoints/$MODEL_VERSION \
11
+ --version plain \
12
+ --data_path ./data/blip_laion_cc_sbu_558k_chinese.json \
13
+ --feat_folder /path/to/stage1_feat \
14
+ --tune_mm_mlp_adapter True \
15
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage1 \
16
+ --bf16 True \
17
+ --num_train_epochs 1 \
18
+ --per_device_train_batch_size 16 \
19
+ --gradient_accumulation_steps 8 \
20
+ --evaluation_strategy "no" \
21
+ --save_strategy "steps" \
22
+ --save_steps 24000 \
23
+ --save_total_limit 1 \
24
+ --learning_rate 1e-3 \
25
+ --weight_decay 0. \
26
+ --warmup_ratio 0.03 \
27
+ --lr_scheduler_type "cosine" \
28
+ --logging_steps 1 \
29
+ --tf32 True \
30
+ --model_max_length 2048 \
31
+ --gradient_checkpointing True \
32
+ --dataloader_num_workers 4 \
33
+ --lazy_preprocess True \
34
+ --report_to wandb
Vtimellm_training_file/scripts/stage2.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=vicuna-v1-5-7b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
9
+ --deepspeed ./scripts/zero3.json \
10
+ --lora_enable True \
11
+ --model_name_or_path ./checkpoints/vicuna-7b-v1.5 \
12
+ --version v1 \
13
+ --data_path ./data/stage2.json \
14
+ --feat_folder /path/to/stage2_feat \
15
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
16
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
17
+ --bf16 True \
18
+ --num_train_epochs 2 \
19
+ --per_device_train_batch_size 8 \
20
+ --gradient_accumulation_steps 16 \
21
+ --evaluation_strategy "no" \
22
+ --save_strategy "steps" \
23
+ --save_steps 50000 \
24
+ --save_total_limit 1 \
25
+ --learning_rate 1e-4 \
26
+ --freeze_mm_mlp_adapter True \
27
+ --lora_r 64 \
28
+ --lora_alpha 128 \
29
+ --weight_decay 0. \
30
+ --warmup_ratio 0.03 \
31
+ --lr_scheduler_type "cosine" \
32
+ --logging_steps 1 \
33
+ --tf32 True \
34
+ --model_max_length 2048 \
35
+ --gradient_checkpointing True \
36
+ --dataloader_num_workers 4 \
37
+ --lazy_preprocess True \
38
+ --report_to wandb
Vtimellm_training_file/scripts/stage2_glm.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=chatglm3-6b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train.py \
9
+ --deepspeed ./scripts/zero3.json \
10
+ --lora_enable True \
11
+ --model_name_or_path ./checkpoints/$MODEL_VERSION \
12
+ --version plain \
13
+ --data_path ./data/stage2_chinese.json \
14
+ --feat_folder /path/to/stage2_feat \
15
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
16
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
17
+ --bf16 True \
18
+ --num_train_epochs 2 \
19
+ --per_device_train_batch_size 8 \
20
+ --gradient_accumulation_steps 16 \
21
+ --evaluation_strategy "no" \
22
+ --save_strategy "steps" \
23
+ --save_steps 50000 \
24
+ --save_total_limit 1 \
25
+ --learning_rate 1e-4 \
26
+ --freeze_mm_mlp_adapter True \
27
+ --lora_r 64 \
28
+ --lora_alpha 128 \
29
+ --weight_decay 0. \
30
+ --warmup_ratio 0.03 \
31
+ --lr_scheduler_type "cosine" \
32
+ --logging_steps 1 \
33
+ --tf32 True \
34
+ --model_max_length 2048 \
35
+ --gradient_checkpointing True \
36
+ --dataloader_num_workers 4 \
37
+ --lazy_preprocess True \
38
+ --report_to wandb
Vtimellm_training_file/scripts/stage2_test.sh ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=vicuna-v1-5-7b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
9
+ --deepspeed ./scripts/zero3.json \
10
+ --lora_enable True \
11
+ --model_name_or_path lmsys/vicuna-7b-v1.5 \
12
+ --version v1 \
13
+ --data_path ./data/stage2.json \
14
+ --feat_folder /home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/feat/stage3_clip_feat \
15
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
16
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage2_test_shikra_image \
17
+ --bf16 True \
18
+ --num_train_epochs 2 \
19
+ --per_device_train_batch_size 8 \
20
+ --gradient_accumulation_steps 16 \
21
+ --evaluation_strategy "no" \
22
+ --save_strategy "steps" \
23
+ --save_steps 50000 \
24
+ --save_total_limit 1 \
25
+ --learning_rate 1e-4 \
26
+ --freeze_mm_mlp_adapter True \
27
+ --lora_r 64 \
28
+ --lora_alpha 128 \
29
+ --weight_decay 0. \
30
+ --warmup_ratio 0.03 \
31
+ --lr_scheduler_type "cosine" \
32
+ --logging_steps 1 \
33
+ --tf32 True \
34
+ --model_max_length 2048 \
35
+ --gradient_checkpointing True \
36
+ --dataloader_num_workers 4 \
37
+ --lazy_preprocess True \
38
+ --report_to wandb
Vtimellm_training_file/scripts/stage3.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=vicuna-v1-5-7b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
9
+ --deepspeed ./scripts/zero2.json \
10
+ --lora_enable True \
11
+ --training_stage 3 \
12
+ --model_name_or_path ./checkpoints/vicuna-7b-v1.5 \
13
+ --version v1 \
14
+ --data_path ./data/stage3.json \
15
+ --feat_folder /path/to/stage3_feat \
16
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
17
+ --stage2_path ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
18
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage3 \
19
+ --bf16 True \
20
+ --num_train_epochs 2 \
21
+ --per_device_train_batch_size 8 \
22
+ --gradient_accumulation_steps 16 \
23
+ --evaluation_strategy "no" \
24
+ --save_strategy "steps" \
25
+ --save_steps 50000 \
26
+ --save_total_limit 1 \
27
+ --learning_rate 1e-4 \
28
+ --freeze_mm_mlp_adapter True \
29
+ --lora_r 64 \
30
+ --lora_alpha 128 \
31
+ --weight_decay 0. \
32
+ --warmup_ratio 0.03 \
33
+ --lr_scheduler_type "cosine" \
34
+ --logging_steps 1 \
35
+ --tf32 True \
36
+ --model_max_length 2048 \
37
+ --gradient_checkpointing True \
38
+ --dataloader_num_workers 4 \
39
+ --lazy_preprocess True \
40
+ --report_to wandb
Vtimellm_training_file/scripts/stage3_glm.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=chatglm3-6b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train.py \
9
+ --deepspeed ./scripts/zero2.json \
10
+ --lora_enable True \
11
+ --training_stage 3 \
12
+ --model_name_or_path ./checkpoints/$MODEL_VERSION \
13
+ --version plain \
14
+ --data_path ./data/stage3_chinese.json \
15
+ --feat_folder /path/to/stage3_feat \
16
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
17
+ --stage2_path ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
18
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage3 \
19
+ --bf16 True \
20
+ --num_train_epochs 2 \
21
+ --per_device_train_batch_size 8 \
22
+ --gradient_accumulation_steps 16 \
23
+ --evaluation_strategy "no" \
24
+ --save_strategy "steps" \
25
+ --save_steps 50000 \
26
+ --save_total_limit 1 \
27
+ --learning_rate 1e-4 \
28
+ --freeze_mm_mlp_adapter True \
29
+ --lora_r 64 \
30
+ --lora_alpha 128 \
31
+ --weight_decay 0. \
32
+ --warmup_ratio 0.03 \
33
+ --lr_scheduler_type "cosine" \
34
+ --logging_steps 1 \
35
+ --tf32 True \
36
+ --model_max_length 2048 \
37
+ --gradient_checkpointing True \
38
+ --dataloader_num_workers 4 \
39
+ --lazy_preprocess True \
40
+ --report_to wandb
Vtimellm_training_file/scripts/stage3_test.sh ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ MODEL_VERSION=vicuna-v1-5-7b
4
+ gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
5
+ MASTER_PORT=29570
6
+
7
+
8
+ deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
9
+ --deepspeed ./scripts/zero2.json \
10
+ --lora_enable True \
11
+ --training_stage 3 \
12
+ --model_name_or_path lmsys/vicuna-7b-v1.5 \
13
+ --version v1 \
14
+ --data_path ./data/stage4_2.json \
15
+ --feat_folder /home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/feat/stage4_clip_feat \
16
+ --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
17
+ --stage2_path ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
18
+ --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage3_test \
19
+ --bf16 True \
20
+ --num_train_epochs 800 \
21
+ --per_device_train_batch_size 5 \
22
+ --gradient_accumulation_steps 8 \
23
+ --evaluation_strategy "no" \
24
+ --save_strategy "steps" \
25
+ --save_steps 400 \
26
+ --save_total_limit 2 \
27
+ --learning_rate 1e-4 \
28
+ --freeze_mm_mlp_adapter True \
29
+ --lora_r 64 \
30
+ --lora_alpha 128 \
31
+ --weight_decay 0. \
32
+ --warmup_ratio 0.03 \
33
+ --lr_scheduler_type "cosine" \
34
+ --logging_steps 1 \
35
+ --tf32 True \
36
+ --model_max_length 2048 \
37
+ --gradient_checkpointing True \
38
+ --dataloader_num_workers 4 \
39
+ --lazy_preprocess True \
40
+ #--report_to wandb
41
+
42
+ ################################################################################################################################
43
+ ################################################################################################################################
44
+
45
+
46
+ # MODEL_VERSION=vicuna-v1-5-7b
47
+ # gpu_vis=0 # per_device_train_batch_size * gradient_accumulation_steps * n_gpus = 128
48
+ # MASTER_PORT=29570
49
+
50
+
51
+ # deepspeed --include localhost:$gpu_vis --master_port $MASTER_PORT vtimellm/train/train_mem.py \
52
+ # --deepspeed ./scripts/zero2.json \
53
+ # --lora_enable True \
54
+ # --training_stage 3 \
55
+ # --model_name_or_path lmsys/vicuna-7b-v1.5 \
56
+ # --version v1 \
57
+ # --data_path ./data/stage3.json \
58
+ # --feat_folder /home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/feat/stage3_clip_feat \
59
+ # --pretrain_mm_mlp_adapter ./checkpoints/vtimellm-$MODEL_VERSION-stage1/mm_projector.bin \
60
+ # --stage2_path ./checkpoints/vtimellm-$MODEL_VERSION-stage2 \
61
+ # --output_dir ./checkpoints/vtimellm-$MODEL_VERSION-stage3_test \
62
+ # --bf16 True \
63
+ # --num_train_epochs 2 \
64
+ # --per_device_train_batch_size 5 \
65
+ # --gradient_accumulation_steps 8 \
66
+ # --evaluation_strategy "no" \
67
+ # --save_strategy "steps" \
68
+ # --save_steps 300 \
69
+ # --save_total_limit 1 \
70
+ # --learning_rate 1e-4 \
71
+ # --freeze_mm_mlp_adapter True \
72
+ # --lora_r 64 \
73
+ # --lora_alpha 128 \
74
+ # --weight_decay 0. \
75
+ # --warmup_ratio 0.03 \
76
+ # --lr_scheduler_type "cosine" \
77
+ # --logging_steps 1 \
78
+ # --tf32 True \
79
+ # --model_max_length 2048 \
80
+ # --gradient_checkpointing True \
81
+ # --dataloader_num_workers 4 \
82
+ # --lazy_preprocess True \
83
+ # #--report_to wandb
Vtimellm_training_file/scripts/zero2.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fp16": {
3
+ "enabled": "auto",
4
+ "loss_scale": 0,
5
+ "loss_scale_window": 1000,
6
+ "initial_scale_power": 16,
7
+ "hysteresis": 2,
8
+ "min_loss_scale": 1
9
+ },
10
+ "bf16": {
11
+ "enabled": "auto"
12
+ },
13
+ "train_micro_batch_size_per_gpu": "auto",
14
+ "train_batch_size": "auto",
15
+ "gradient_accumulation_steps": "auto",
16
+ "zero_optimization": {
17
+ "stage": 2,
18
+ "overlap_comm": true,
19
+ "contiguous_gradients": true,
20
+ "sub_group_size": 1e9,
21
+ "reduce_bucket_size": "auto"
22
+ }
23
+ }
Vtimellm_training_file/scripts/zero3.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fp16": {
3
+ "enabled": "auto",
4
+ "loss_scale": 0,
5
+ "loss_scale_window": 1000,
6
+ "initial_scale_power": 16,
7
+ "hysteresis": 2,
8
+ "min_loss_scale": 1
9
+ },
10
+ "bf16": {
11
+ "enabled": "auto"
12
+ },
13
+ "train_micro_batch_size_per_gpu": "auto",
14
+ "train_batch_size": "auto",
15
+ "gradient_accumulation_steps": "auto",
16
+ "zero_optimization": {
17
+ "stage": 3,
18
+ "overlap_comm": true,
19
+ "contiguous_gradients": true,
20
+ "sub_group_size": 1e9,
21
+ "reduce_bucket_size": "auto",
22
+ "stage3_prefetch_bucket_size": "auto",
23
+ "stage3_param_persistence_threshold": "auto",
24
+ "stage3_max_live_parameters": 1e9,
25
+ "stage3_max_reuse_distance": 1e9,
26
+ "stage3_gather_16bit_weights_on_model_save": true
27
+ }
28
+ }
Vtimellm_training_file/scripts/zero3_offload.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fp16": {
3
+ "enabled": "auto",
4
+ "loss_scale": 0,
5
+ "loss_scale_window": 1000,
6
+ "initial_scale_power": 16,
7
+ "hysteresis": 2,
8
+ "min_loss_scale": 1
9
+ },
10
+ "bf16": {
11
+ "enabled": "auto"
12
+ },
13
+ "optimizer": {
14
+ "type": "AdamW",
15
+ "params": {
16
+ "lr": "auto",
17
+ "betas": "auto",
18
+ "eps": "auto",
19
+ "weight_decay": "auto"
20
+ }
21
+ },
22
+ "scheduler": {
23
+ "type": "WarmupLR",
24
+ "params": {
25
+ "warmup_min_lr": "auto",
26
+ "warmup_max_lr": "auto",
27
+ "warmup_num_steps": "auto"
28
+ }
29
+ },
30
+ "zero_optimization": {
31
+ "stage": 3,
32
+ "offload_optimizer": {
33
+ "device": "cpu",
34
+ "pin_memory": true
35
+ },
36
+ "offload_param": {
37
+ "device": "cpu",
38
+ "pin_memory": true
39
+ },
40
+ "overlap_comm": true,
41
+ "contiguous_gradients": true,
42
+ "sub_group_size": 1e9,
43
+ "reduce_bucket_size": "auto",
44
+ "stage3_prefetch_bucket_size": "auto",
45
+ "stage3_param_persistence_threshold": "auto",
46
+ "stage3_max_live_parameters": 1e9,
47
+ "stage3_max_reuse_distance": 1e9,
48
+ "gather_16bit_weights_on_model_save": true
49
+ },
50
+ "gradient_accumulation_steps": "auto",
51
+ "gradient_clipping": "auto",
52
+ "train_batch_size": "auto",
53
+ "train_micro_batch_size_per_gpu": "auto",
54
+ "steps_per_print": 1e5,
55
+ "wall_clock_breakdown": false
56
+ }
Vtimellm_training_file/stage3_test_1_backup.txt ADDED
The diff for this file is too large to render. See raw diff
 
Vtimellm_training_file/video_read_test_1.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+
4
+ """
5
+ Adapted from: https://github.com/Vision-CAIR/MiniGPT-4/blob/main/demo.py
6
+ """
7
+ import argparse
8
+ import os
9
+ root_dir = os.path.join(os.getcwd(), "..")
10
+ import sys
11
+ sys.path.append(root_dir)
12
+
13
+
14
+ import torch
15
+ import gradio as gr
16
+
17
+ import decord
18
+ #decord.bridge.set_bridge('torch')
19
+
20
+ from vtimellm.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
21
+ from vtimellm.conversation import conv_templates, SeparatorStyle
22
+ from vtimellm.model.builder import load_pretrained_model
23
+ from vtimellm.utils import disable_torch_init
24
+ from vtimellm.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, VideoExtractor
25
+ from PIL import Image
26
+ from transformers import TextStreamer
27
+ try:
28
+ from torchvision.transforms import InterpolationMode
29
+ BICUBIC = InterpolationMode.BICUBIC
30
+ except ImportError:
31
+ from PIL import Image
32
+ BICUBIC = Image.BICUBIC
33
+ from torchvision.transforms import Compose, Resize, CenterCrop, Normalize
34
+ import clip
35
+
36
+
37
+ import numpy as np
38
+ import torch
39
+
40
+
41
+ # ========================================
42
+ # Model Initialization
43
+ # ========================================
44
+
45
+ #args = parse_args()
46
+ device = f'cuda:{0}'
47
+
48
+ disable_torch_init()
49
+ # tokenizer, model, context_len = load_pretrained_model(args, args.stage2, args.stage3)
50
+ # model = model.to(torch.float16).to(device)
51
+
52
+ #clip_model, _ = clip.load(os.path.join(root_dir, "checkpoints/clip/ViT-L-14.pt"))
53
+ clip_model, _ = clip.load("/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/clip/ViT-L-14.pt")
54
+ #/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/clip
55
+
56
+ clip_model.eval()
57
+ clip_model = clip_model.to(device)
58
+
59
+ transform = Compose([
60
+ Resize(224, interpolation=BICUBIC),
61
+ CenterCrop(224),
62
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
63
+ ])
64
+
65
+ print('Initialization Finished')
66
+
67
+
68
+
69
+ class VideoExtractor():
70
+ """Dataset for supervised fine-tuning."""
71
+
72
+ def __init__(self, N=100):
73
+ self.N = N
74
+
75
+ def extract(self, data):
76
+ video_path = data['video']
77
+ id = data['id']
78
+
79
+ try:
80
+ video_reader = decord.VideoReader(video_path)
81
+ total_frames = len(video_reader)
82
+ print("total_frames")
83
+ print(total_frames)
84
+ start = 0
85
+ end = total_frames - 1
86
+ print(end)
87
+
88
+ split = data.get('split', None)
89
+ if split is not None:
90
+ fps = video_reader.get_avg_fps()
91
+ print("fps")
92
+ print(fps)
93
+ start = max(int(fps * split[0]), 0)
94
+ end = min(int(fps * split[1]), total_frames - 1)
95
+
96
+ sampled_indices = np.linspace(start, end, self.N, dtype=np.int32)
97
+ sampled_frames = video_reader.get_batch(sampled_indices).asnumpy()
98
+
99
+ #Start_END
100
+ ##/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2727682922.mp4
101
+ #start_end = video_reader.get_batch([127, 603]).asnumpy()
102
+ ##/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2769996915.mp4
103
+ #174 191(180), 1706 1724(1710)
104
+ #start_end = video_reader.get_batch([191, 1706]).asnumpy()
105
+ ##/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4284560730.mp4
106
+ #252(252), 357 361(359)
107
+ #start_end = video_reader.get_batch([252, 361]).asnumpy()
108
+ ##/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4598213889.mp4
109
+ #517(515), 569(569)
110
+ #start_end = video_reader.get_batch([517, 569]).asnumpy()
111
+ ##/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4655213495.mp4
112
+ #865 883(869), 1104 1123(1109)
113
+ #start_end = video_reader.get_batch([865, 1104]).asnumpy()
114
+
115
+
116
+
117
+ print(sampled_indices)
118
+ print(sampled_indices.shape)
119
+ print(sampled_frames.shape)
120
+
121
+ except Exception as e:
122
+ print(e)
123
+ return None, torch.zeros(1)
124
+
125
+ images = torch.from_numpy(sampled_frames.transpose((0, 3, 1, 2)))
126
+ return id, images
127
+
128
+
129
+ video_loader = VideoExtractor(N=100)
130
+ #Path
131
+ #/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2727682922.mp4
132
+ #/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2769996915.mp4
133
+ #/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4284560730.mp4
134
+ #/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4598213889.mp4
135
+ #/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4655213495.mp4
136
+
137
+
138
+ gr_video = "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4655213495.mp4"
139
+
140
+ #/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/vtimellm/video_read_test_1.py
141
+ #/home/imr555/miniconda3/envs/vtimellm/lib/python3.10/site-packages/decord/video_reader.py
142
+
143
+ _, images = video_loader.extract({'id': None, 'video': gr_video})
144
+
145
+
146
+
147
+
148
+ video_loader = VideoExtractor(N=100)
149
+
150
+ vid_list = [
151
+ "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2727682922.mp4",
152
+ "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/2769996915.mp4",
153
+ "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4284560730.mp4",
154
+ "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4598213889.mp4",
155
+ "/home/imr555/Downloads/UCF_CV/project_update_2/cap6412-Project/Processed_Dataset/4655213495.mp4"
156
+ ]
157
+
158
+ stage4_feat_path = "/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/feat/stage4_clip_feat"
159
+
160
+ for vid_path in vid_list:
161
+
162
+ #Video ID
163
+ vid_id = vid_path.split("/")[-1][:-4]
164
+
165
+ _, images = video_loader.extract({'id': None, 'video': vid_path})
166
+ print(images.shape)
167
+
168
+ transform = Compose([
169
+ Resize(224, interpolation=BICUBIC),
170
+ CenterCrop(224),
171
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
172
+ ])
173
+
174
+ # print(images.shape) # <N, 3, H, W>
175
+ images = transform(images / 255.0)
176
+ images = images.to(torch.float16)
177
+ with torch.no_grad():
178
+ video_features_state = clip_model.encode_image(images.to('cuda'))
179
+
180
+ print(video_features_state.shape)
181
+
182
+ video_feat_npy = video_features_state.cpu().detach().numpy()
183
+
184
+ np.save( stage4_feat_path+"/"+vid_id+'.npy', video_feat_npy)
185
+
186
+
187
+
188
+ #Save feats to
189
+ #/home/imr555/Downloads/UCF_CV/project_update_2/VTimeLLM/checkpoints/feat/stage4_clip_feat
190
+
191
+
192
+
Vtimellm_training_file/vtimellm/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .model import VTimeLLMLlamaForCausalLM
Vtimellm_training_file/vtimellm/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (223 Bytes). View file
 
Vtimellm_training_file/vtimellm/__pycache__/constants.cpython-310.pyc ADDED
Binary file (357 Bytes). View file
 
Vtimellm_training_file/vtimellm/__pycache__/conversation.cpython-310.pyc ADDED
Binary file (10.4 kB). View file
 
Vtimellm_training_file/vtimellm/__pycache__/inference.cpython-310.pyc ADDED
Binary file (3.51 kB). View file
 
Vtimellm_training_file/vtimellm/__pycache__/mm_utils.cpython-310.pyc ADDED
Binary file (4.99 kB). View file
 
Vtimellm_training_file/vtimellm/__pycache__/utils.cpython-310.pyc ADDED
Binary file (4.05 kB). View file
 
Vtimellm_training_file/vtimellm/constants.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ CONTROLLER_HEART_BEAT_EXPIRATION = 30
2
+ WORKER_HEART_BEAT_INTERVAL = 15
3
+
4
+ LOGDIR = "."
5
+
6
+ # Model Constants
7
+ IGNORE_INDEX = -100
8
+ IMAGE_TOKEN_INDEX = -200
9
+ DEFAULT_IMAGE_TOKEN = "<video>"
10
+
Vtimellm_training_file/vtimellm/conversation.py ADDED
@@ -0,0 +1,384 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dataclasses
2
+ from enum import auto, Enum
3
+ from typing import List, Tuple
4
+
5
+
6
+ class SeparatorStyle(Enum):
7
+ """Different separator style."""
8
+ SINGLE = auto()
9
+ TWO = auto()
10
+ MPT = auto()
11
+ PLAIN = auto()
12
+ LLAMA_2 = auto()
13
+
14
+
15
+ @dataclasses.dataclass
16
+ class Conversation:
17
+ """A class that keeps all conversation history."""
18
+ system: str
19
+ roles: List[str]
20
+ messages: List[List[str]]
21
+ offset: int
22
+ sep_style: SeparatorStyle = SeparatorStyle.SINGLE
23
+ sep: str = "###"
24
+ sep2: str = None
25
+ version: str = "Unknown"
26
+
27
+ skip_next: bool = False
28
+
29
+ def get_prompt(self):
30
+ messages = self.messages
31
+ if len(messages) > 0 and type(messages[0][1]) is tuple:
32
+ messages = self.messages.copy()
33
+ init_role, init_msg = messages[0].copy()
34
+ init_msg = init_msg[0].replace("<image>", "").strip()
35
+ if 'mmtag' in self.version:
36
+ messages[0] = (init_role, init_msg)
37
+ messages.insert(0, (self.roles[0], "<Image><image></Image>"))
38
+ messages.insert(1, (self.roles[1], "Received."))
39
+ else:
40
+ messages[0] = (init_role, "<image>\n" + init_msg)
41
+
42
+ if self.sep_style == SeparatorStyle.SINGLE:
43
+ ret = self.system + self.sep
44
+ for role, message in messages:
45
+ if message:
46
+ if type(message) is tuple:
47
+ message, _, _ = message
48
+ ret += role + ": " + message + self.sep
49
+ else:
50
+ ret += role + ":"
51
+ elif self.sep_style == SeparatorStyle.TWO:
52
+ seps = [self.sep, self.sep2]
53
+ ret = self.system + seps[0]
54
+ for i, (role, message) in enumerate(messages):
55
+ if message:
56
+ if type(message) is tuple:
57
+ message, _, _ = message
58
+ ret += role + ": " + message + seps[i % 2]
59
+ else:
60
+ ret += role + ":"
61
+ elif self.sep_style == SeparatorStyle.MPT:
62
+ ret = self.system + self.sep
63
+ for role, message in messages:
64
+ if message:
65
+ if type(message) is tuple:
66
+ message, _, _ = message
67
+ ret += role + message + self.sep
68
+ else:
69
+ ret += role
70
+ elif self.sep_style == SeparatorStyle.LLAMA_2:
71
+ wrap_sys = lambda msg: f"<<SYS>>\n{msg}\n<</SYS>>\n\n"
72
+ wrap_inst = lambda msg: f"[INST] {msg} [/INST]"
73
+ ret = ""
74
+
75
+ for i, (role, message) in enumerate(messages):
76
+ if i == 0:
77
+ assert message, "first message should not be none"
78
+ assert role == self.roles[0], "first message should come from user"
79
+ if message:
80
+ if type(message) is tuple:
81
+ message, _, _ = message
82
+ if i == 0: message = wrap_sys(self.system) + message
83
+ if i % 2 == 0:
84
+ message = wrap_inst(message)
85
+ ret += self.sep + message
86
+ else:
87
+ ret += " " + message + " " + self.sep2
88
+ else:
89
+ ret += ""
90
+ ret = ret.lstrip(self.sep)
91
+ elif self.sep_style == SeparatorStyle.PLAIN:
92
+ seps = [self.sep, self.sep2]
93
+ ret = self.system
94
+ for i, (role, message) in enumerate(messages):
95
+ if message:
96
+ if type(message) is tuple:
97
+ message, _, _ = message
98
+ ret += message + seps[i % 2]
99
+ else:
100
+ ret += ""
101
+ else:
102
+ raise ValueError(f"Invalid style: {self.sep_style}")
103
+
104
+ return ret
105
+
106
+ def append_message(self, role, message):
107
+ self.messages.append([role, message])
108
+
109
+ def get_images(self, return_pil=False):
110
+ images = []
111
+ for i, (role, msg) in enumerate(self.messages[self.offset:]):
112
+ if i % 2 == 0:
113
+ if type(msg) is tuple:
114
+ import base64
115
+ from io import BytesIO
116
+ from PIL import Image
117
+ msg, image, image_process_mode = msg
118
+ if image_process_mode == "Pad":
119
+ def expand2square(pil_img, background_color=(122, 116, 104)):
120
+ width, height = pil_img.size
121
+ if width == height:
122
+ return pil_img
123
+ elif width > height:
124
+ result = Image.new(pil_img.mode, (width, width), background_color)
125
+ result.paste(pil_img, (0, (width - height) // 2))
126
+ return result
127
+ else:
128
+ result = Image.new(pil_img.mode, (height, height), background_color)
129
+ result.paste(pil_img, ((height - width) // 2, 0))
130
+ return result
131
+ image = expand2square(image)
132
+ elif image_process_mode == "Crop":
133
+ pass
134
+ elif image_process_mode == "Resize":
135
+ image = image.resize((336, 336))
136
+ else:
137
+ raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
138
+ max_hw, min_hw = max(image.size), min(image.size)
139
+ aspect_ratio = max_hw / min_hw
140
+ max_len, min_len = 800, 400
141
+ shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
142
+ longest_edge = int(shortest_edge * aspect_ratio)
143
+ W, H = image.size
144
+ if H > W:
145
+ H, W = longest_edge, shortest_edge
146
+ else:
147
+ H, W = shortest_edge, longest_edge
148
+ image = image.resize((W, H))
149
+ if return_pil:
150
+ images.append(image)
151
+ else:
152
+ buffered = BytesIO()
153
+ image.save(buffered, format="PNG")
154
+ img_b64_str = base64.b64encode(buffered.getvalue()).decode()
155
+ images.append(img_b64_str)
156
+ return images
157
+
158
+ def to_gradio_chatbot(self):
159
+ ret = []
160
+ for i, (role, msg) in enumerate(self.messages[self.offset:]):
161
+ if i % 2 == 0:
162
+ if type(msg) is tuple:
163
+ import base64
164
+ from io import BytesIO
165
+ msg, image, image_process_mode = msg
166
+ max_hw, min_hw = max(image.size), min(image.size)
167
+ aspect_ratio = max_hw / min_hw
168
+ max_len, min_len = 800, 400
169
+ shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
170
+ longest_edge = int(shortest_edge * aspect_ratio)
171
+ W, H = image.size
172
+ if H > W:
173
+ H, W = longest_edge, shortest_edge
174
+ else:
175
+ H, W = shortest_edge, longest_edge
176
+ image = image.resize((W, H))
177
+ buffered = BytesIO()
178
+ image.save(buffered, format="JPEG")
179
+ img_b64_str = base64.b64encode(buffered.getvalue()).decode()
180
+ img_str = f'<img src="data:image/png;base64,{img_b64_str}" alt="user upload image" />'
181
+ ret.append([img_str, None])
182
+ msg = msg.replace('<image>', '').strip()
183
+ if len(msg) > 0:
184
+ ret.append([msg, None])
185
+ else:
186
+ ret.append([msg, None])
187
+ else:
188
+ ret[-1][-1] = msg
189
+ return ret
190
+
191
+ def copy(self):
192
+ return Conversation(
193
+ system=self.system,
194
+ roles=self.roles,
195
+ messages=[[x, y] for x, y in self.messages],
196
+ offset=self.offset,
197
+ sep_style=self.sep_style,
198
+ sep=self.sep,
199
+ sep2=self.sep2,
200
+ version=self.version)
201
+
202
+ def dict(self):
203
+ if len(self.get_images()) > 0:
204
+ return {
205
+ "system": self.system,
206
+ "roles": self.roles,
207
+ "messages": [[x, y[0] if type(y) is tuple else y] for x, y in self.messages],
208
+ "offset": self.offset,
209
+ "sep": self.sep,
210
+ "sep2": self.sep2,
211
+ }
212
+ return {
213
+ "system": self.system,
214
+ "roles": self.roles,
215
+ "messages": self.messages,
216
+ "offset": self.offset,
217
+ "sep": self.sep,
218
+ "sep2": self.sep2,
219
+ }
220
+
221
+
222
+ conv_vicuna_v0 = Conversation(
223
+ system="A chat between a curious human and an artificial intelligence assistant. "
224
+ "The assistant gives helpful, detailed, and polite answers to the human's questions.",
225
+ roles=("Human", "Assistant"),
226
+ messages=(
227
+ ("Human", "What are the key differences between renewable and non-renewable energy sources?"),
228
+ ("Assistant",
229
+ "Renewable energy sources are those that can be replenished naturally in a relatively "
230
+ "short amount of time, such as solar, wind, hydro, geothermal, and biomass. "
231
+ "Non-renewable energy sources, on the other hand, are finite and will eventually be "
232
+ "depleted, such as coal, oil, and natural gas. Here are some key differences between "
233
+ "renewable and non-renewable energy sources:\n"
234
+ "1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable "
235
+ "energy sources are finite and will eventually run out.\n"
236
+ "2. Environmental impact: Renewable energy sources have a much lower environmental impact "
237
+ "than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, "
238
+ "and other negative effects.\n"
239
+ "3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically "
240
+ "have lower operational costs than non-renewable sources.\n"
241
+ "4. Reliability: Renewable energy sources are often more reliable and can be used in more remote "
242
+ "locations than non-renewable sources.\n"
243
+ "5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different "
244
+ "situations and needs, while non-renewable sources are more rigid and inflexible.\n"
245
+ "6. Sustainability: Renewable energy sources are more sustainable over the long term, while "
246
+ "non-renewable sources are not, and their depletion can lead to economic and social instability.\n")
247
+ ),
248
+ offset=2,
249
+ sep_style=SeparatorStyle.SINGLE,
250
+ sep="###",
251
+ )
252
+
253
+ conv_vicuna_v1 = Conversation(
254
+ system="A chat between a curious user and an artificial intelligence assistant. "
255
+ "The assistant gives helpful, detailed, and polite answers to the user's questions.",
256
+ roles=("USER", "ASSISTANT"),
257
+ version="v1",
258
+ messages=(),
259
+ offset=0,
260
+ sep_style=SeparatorStyle.TWO,
261
+ sep=" ",
262
+ sep2="</s>",
263
+ )
264
+
265
+ conv_llama_2 = Conversation(
266
+ system="""You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
267
+
268
+ If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""",
269
+ roles=("USER", "ASSISTANT"),
270
+ version="llama_v2",
271
+ messages=(),
272
+ offset=0,
273
+ sep_style=SeparatorStyle.LLAMA_2,
274
+ sep="<s>",
275
+ sep2="</s>",
276
+ )
277
+
278
+ conv_llava_llama_2 = Conversation(
279
+ system="You are a helpful language and vision assistant. "
280
+ "You are able to understand the visual content that the user provides, "
281
+ "and assist the user with a variety of tasks using natural language.",
282
+ roles=("USER", "ASSISTANT"),
283
+ version="llama_v2",
284
+ messages=(),
285
+ offset=0,
286
+ sep_style=SeparatorStyle.LLAMA_2,
287
+ sep="<s>",
288
+ sep2="</s>",
289
+ )
290
+
291
+ conv_mpt = Conversation(
292
+ system="""<|im_start|>system
293
+ A conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.""",
294
+ roles=("<|im_start|>user\n", "<|im_start|>assistant\n"),
295
+ version="mpt",
296
+ messages=(),
297
+ offset=0,
298
+ sep_style=SeparatorStyle.MPT,
299
+ sep="<|im_end|>",
300
+ )
301
+
302
+ conv_llava_plain = Conversation(
303
+ system="",
304
+ roles=("", ""),
305
+ messages=(
306
+ ),
307
+ offset=0,
308
+ sep_style=SeparatorStyle.PLAIN,
309
+ sep="\n",
310
+ )
311
+
312
+ conv_llava_v0 = Conversation(
313
+ system="A chat between a curious human and an artificial intelligence assistant. "
314
+ "The assistant gives helpful, detailed, and polite answers to the human's questions.",
315
+ roles=("Human", "Assistant"),
316
+ messages=(
317
+ ("Human", "Hi!"),
318
+ ("Assistant", "Hi there! How can I help you today?")
319
+ ),
320
+ offset=2,
321
+ sep_style=SeparatorStyle.SINGLE,
322
+ sep="###",
323
+ )
324
+
325
+ conv_llava_v0_mmtag = Conversation(
326
+ system="A chat between a curious user and an artificial intelligence assistant. "
327
+ "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
328
+ "The visual content will be provided with the following format: <Image>visual content</Image>.",
329
+ roles=("Human", "Assistant"),
330
+ messages=(
331
+ ),
332
+ offset=0,
333
+ sep_style=SeparatorStyle.SINGLE,
334
+ sep="###",
335
+ version="v0_mmtag",
336
+ )
337
+
338
+ conv_llava_v1 = Conversation(
339
+ system="A chat between a curious human and an artificial intelligence assistant. "
340
+ "The assistant gives helpful, detailed, and polite answers to the human's questions.",
341
+ roles=("USER", "ASSISTANT"),
342
+ version="v1",
343
+ messages=(),
344
+ offset=0,
345
+ sep_style=SeparatorStyle.TWO,
346
+ sep=" ",
347
+ sep2="</s>",
348
+ )
349
+
350
+ conv_llava_v1_mmtag = Conversation(
351
+ system="A chat between a curious user and an artificial intelligence assistant. "
352
+ "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language."
353
+ "The visual content will be provided with the following format: <Image>visual content</Image>.",
354
+ roles=("USER", "ASSISTANT"),
355
+ messages=(),
356
+ offset=0,
357
+ sep_style=SeparatorStyle.TWO,
358
+ sep=" ",
359
+ sep2="</s>",
360
+ version="v1_mmtag",
361
+ )
362
+
363
+ default_conversation = conv_vicuna_v1
364
+ conv_templates = {
365
+ "default": conv_vicuna_v0,
366
+ "v0": conv_vicuna_v0,
367
+ "v1": conv_vicuna_v1,
368
+ "vicuna_v1": conv_vicuna_v1,
369
+ "llama_2": conv_llama_2,
370
+
371
+ "plain": conv_llava_plain,
372
+ "v0_plain": conv_llava_plain,
373
+ "llava_v0": conv_llava_v0,
374
+ "v0_mmtag": conv_llava_v0_mmtag,
375
+ "llava_v1": conv_llava_v1,
376
+ "v1_mmtag": conv_llava_v1_mmtag,
377
+ "llava_llama_2": conv_llava_llama_2,
378
+
379
+ "mpt": conv_mpt,
380
+ }
381
+
382
+
383
+ if __name__ == "__main__":
384
+ print(default_conversation.get_prompt())
Vtimellm_training_file/vtimellm/demo_gradio.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Adapted from: https://github.com/Vision-CAIR/MiniGPT-4/blob/main/demo.py
3
+ """
4
+ import argparse
5
+ import os
6
+ root_dir = os.path.join(os.getcwd(), "..")
7
+ import sys
8
+ sys.path.append(root_dir)
9
+
10
+ import torch
11
+ import gradio as gr
12
+
13
+ import decord
14
+ decord.bridge.set_bridge('torch')
15
+
16
+ from vtimellm.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN
17
+ from vtimellm.conversation import conv_templates, SeparatorStyle
18
+ from vtimellm.model.builder import load_pretrained_model
19
+ from vtimellm.utils import disable_torch_init
20
+ from vtimellm.mm_utils import tokenizer_image_token, KeywordsStoppingCriteria, VideoExtractor
21
+ from PIL import Image
22
+ from transformers import TextStreamer
23
+ try:
24
+ from torchvision.transforms import InterpolationMode
25
+ BICUBIC = InterpolationMode.BICUBIC
26
+ except ImportError:
27
+ from PIL import Image
28
+ BICUBIC = Image.BICUBIC
29
+ from torchvision.transforms import Compose, Resize, CenterCrop, Normalize
30
+ import clip
31
+
32
+ def parse_args():
33
+ parser = argparse.ArgumentParser()
34
+ parser.add_argument("--gpu_id", type=int, default=0, help="specify the gpu to load the model.")
35
+ parser.add_argument("--model_base", type=str, required=True, help="Path to your vicuna-7b-v1.5 huggingface checkpoint")
36
+ parser.add_argument("--clip_path", type=str, default=os.path.join(root_dir, "checkpoints/clip/ViT-L-14.pt"))
37
+ parser.add_argument("--pretrain_mm_mlp_adapter", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage1/mm_projector.bin"))
38
+ parser.add_argument("--stage2", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage2"))
39
+ parser.add_argument("--stage3", type=str, default=os.path.join(root_dir, "checkpoints/vtimellm-vicuna-v1-5-7b-stage3_test"))
40
+ parser.add_argument("--share", action='store_true')
41
+ args = parser.parse_args()
42
+ return args
43
+
44
+ # ========================================
45
+ # Model Initialization
46
+ # ========================================
47
+
48
+ args = parse_args()
49
+ device = f'cuda:{args.gpu_id}'
50
+
51
+ disable_torch_init()
52
+ tokenizer, model, context_len = load_pretrained_model(args, args.stage2, args.stage3)
53
+ model = model.to(torch.float16).to(device)
54
+
55
+ clip_model, _ = clip.load(args.clip_path)
56
+ clip_model.eval()
57
+ clip_model = clip_model.to(device)
58
+
59
+ transform = Compose([
60
+ Resize(224, interpolation=BICUBIC),
61
+ CenterCrop(224),
62
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
63
+ ])
64
+
65
+ print('Initialization Finished')
66
+
67
+ # ========================================
68
+ # Gradio Setting
69
+ # ========================================
70
+
71
+ TEXT_PLACEHOLDER = 'Upload your video first, or directly click the examples at the bottom of the page.'
72
+
73
+ def gradio_reset(chat_state, video_features_state, conv_state):
74
+ if chat_state is not None:
75
+ chat_state.messages = []
76
+ video_features_state = None
77
+ conv_state = {}
78
+ return None, gr.update(value=None, interactive=True), gr.update(value='', placeholder=TEXT_PLACEHOLDER, interactive=False), gr.update(value="Upload & Start Chat", interactive=True), chat_state, video_features_state, conv_state
79
+
80
+ def upload_video(gr_video, chat_state, video_features_state, conv_state, chatbot):
81
+ if not gr_video:
82
+ return None, None, gr.update(interactive=True), chat_state, video_features_state, conv_state, None
83
+ else:
84
+ print(gr_video)
85
+ video_loader = VideoExtractor(N=100)
86
+ _, images = video_loader.extract({'id': None, 'video': gr_video})
87
+
88
+ transform = Compose([
89
+ Resize(224, interpolation=BICUBIC),
90
+ CenterCrop(224),
91
+ Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
92
+ ])
93
+
94
+ # print(images.shape) # <N, 3, H, W>
95
+ images = transform(images / 255.0)
96
+ images = images.to(torch.float16)
97
+ with torch.no_grad():
98
+ video_features_state = clip_model.encode_image(images.to('cuda'))
99
+
100
+ chatbot = chatbot + [((gr_video,), None)]
101
+ chat_state = conv_templates["v1"].copy()
102
+ conv_state['first'] = True
103
+
104
+ return gr.update(interactive=False), gr.update(interactive=True, placeholder='Type and press Enter'), gr.update(value="Start Chatting", interactive=False), chat_state, video_features_state, conv_state, chatbot
105
+
106
+ def gradio_ask(user_message, chatbot, chat_state, conv_state):
107
+ if len(user_message) == 0:
108
+ conv_state['should_answer'] = False
109
+ return gr.update(interactive=True, placeholder='Input should not be empty!'), chatbot, chat_state, conv_state
110
+ conv_state['should_answer'] = True
111
+ chatbot = chatbot + [[user_message, None]]
112
+ if conv_state['first']:
113
+ user_message = DEFAULT_IMAGE_TOKEN + '\n' + user_message
114
+ conv_state['first'] = False
115
+ chat_state.append_message(chat_state.roles[0], user_message)
116
+ chat_state.append_message(chat_state.roles[1], None)
117
+ return '', chatbot, chat_state, conv_state
118
+
119
+
120
+ def gradio_answer(chatbot, chat_state, video_features_state, conv_state, temperature):
121
+ if not conv_state['should_answer']:
122
+ return chatbot, chat_state
123
+ prompt = chat_state.get_prompt()
124
+ input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt').unsqueeze(0).to(device)
125
+ stop_str = chat_state.sep if chat_state.sep_style != SeparatorStyle.TWO else chat_state.sep2 # plain:sep(###) v1:sep2(None)
126
+ keywords = [stop_str]
127
+ stopping_criteria = KeywordsStoppingCriteria(keywords, tokenizer, input_ids)
128
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
129
+
130
+ with torch.inference_mode():
131
+ output_ids = model.generate(
132
+ input_ids,
133
+ images=video_features_state[None,].to(device),
134
+ do_sample=True,
135
+ temperature=temperature,
136
+ max_new_tokens=1024,
137
+ streamer=streamer,
138
+ use_cache=True,
139
+ stopping_criteria=[stopping_criteria]
140
+ )
141
+
142
+ outputs = tokenizer.decode(output_ids[0, input_ids.shape[1]:]).strip()
143
+ chat_state.messages[-1][-1] = outputs
144
+
145
+ chatbot[-1][1] = outputs
146
+ print(chat_state.get_prompt())
147
+ print(chat_state)
148
+ return chatbot, chat_state
149
+
150
+ with gr.Blocks() as demo:
151
+ gr.Markdown('''# Demo for VTimeLLM''')
152
+
153
+ with gr.Row():
154
+ with gr.Column(scale=0.5):
155
+ video = gr.Video()
156
+
157
+ upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
158
+ clear = gr.Button("Reset")
159
+
160
+ temperature = gr.Slider(
161
+ minimum=0,
162
+ maximum=2.0,
163
+ value=0.05,
164
+ step=0.01,
165
+ interactive=True,
166
+ label="Temperature",
167
+ )
168
+ with gr.Column():
169
+ chat_state = gr.State()
170
+ video_features_state = gr.State()
171
+ conv_state = gr.State({})
172
+ chatbot = gr.Chatbot(label='VTimeLLM')
173
+ text_input = gr.Textbox(label='User', placeholder=TEXT_PLACEHOLDER, interactive=False)
174
+
175
+
176
+ with gr.Column():
177
+ gr.Examples(examples=[
178
+ [os.path.join(root_dir, f"images/demo.mp4"), "Explain why the video is funny."],
179
+ ], inputs=[video, text_input])
180
+
181
+ upload_button.click(upload_video, [video, chat_state, video_features_state, conv_state, chatbot], [video, text_input, upload_button, chat_state, video_features_state, conv_state, chatbot])
182
+ text_input.submit(gradio_ask, [text_input, chatbot, chat_state, conv_state], [text_input, chatbot, chat_state, conv_state]).then(gradio_answer, [chatbot, chat_state, video_features_state, conv_state, temperature], [chatbot, chat_state])
183
+ clear.click(gradio_reset, [chat_state, video_features_state, conv_state], [chatbot, video, text_input, upload_button, chat_state, video_features_state, conv_state], queue=False)
184
+
185
+ demo.queue().launch(share=args.share)
Vtimellm_training_file/vtimellm/eval/data_example.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "v_bXdq2zI1Ms0": {
3
+ "duration": 73.1,
4
+ "timestamps": [
5
+ [6.94, 69.08],
6
+ [37.28, 43.49],
7
+ [43.13, 55.55]
8
+ ],
9
+ "sentences": ["Three men are standing on a mat.", " The man in front begins to do karate on the mat.", " He gets down on the ground and flips around."]
10
+ },
11
+ "v_CN01Gm2Yc4k": {
12
+ "duration": 17.56,
13
+ "timestamps": [
14
+ [0, 5],
15
+ [5, 12.2],
16
+ [12.2, 17.56]
17
+ ],
18
+ "sentences": ["A young lady is gripping a black and silver punching bag between her legs.", "Once she has secured herself on the bag,she begins doing a set of crunches by pulling herself up.", "In between the crunches,she sits up and makes punches out into the air,before going back down."]
19
+ }
20
+ }
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/LICENSE ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ SOFTWARE LICENSE AGREEMENT FOR EVALUATION
2
+
3
+ This SOFTWARE EVALUATION LICENSE AGREEMENT (this "Agreement") is a legal contract between a person who uses or otherwise accesses or installs the Software ("User(s)"), and Nippon Telegraph and Telephone corporation ("NTT").
4
+ READ THE TERMS AND CONDITIONS OF THIS AGREEMENT CAREFULLY BEFORE INSTALLING OR OTHERWISE ACCESSING OR USING NTT'S PROPRIETARY SOFTWARE ACCOMPANIED BY THIS AGREEMENT (the "SOFTWARE"). THE SOFTWARE IS COPYRIGHTED AND IT IS LICENSED TO USER UNDER THIS AGREEMENT, NOT SOLD TO USER. BY INSTALLING OR OTHERWISE ACCESSING OR USING THE SOFTWARE, USER ACKNOWLEDGES THAT USER HAS READ THIS AGREEMENT, THAT USER UNDERSTANDS IT, AND THAT USER ACCEPTS AND AGREES TO BE BOUND BY ITS TERMS. IF AT ANY TIME USER IS NOT WILLING TO BE BOUND BY THE TERMS OF THIS AGREEMENT, USER SHOULD TERMINATE THE INSTALLATION PROCESS, IMMEDIATELY CEASE AND REFRAIN FROM ACCESSING OR USING THE SOFTWARE AND DELETE ANY COPIES USER MAY HAVE. THIS AGREEMENT REPRESENTS THE ENTIRE AGREEMENT BETWEEN USER AND NTT CONCERNING THE SOFTWARE.
5
+
6
+
7
+ BACKGROUND
8
+ A. NTT is the owner of all rights, including all patent rights, copyrights and trade secret rights, in and to the Software and related documentation listed in Exhibit A to this Agreement.
9
+ B. User wishes to obtain a royalty free license to use the Software to enable User to evaluate, and NTT wishes to grant such a license to User, pursuant and subject to the terms and conditions of this Agreement.
10
+ C. As a condition to NTT's provision of the Software to User, NTT has required User to execute this Agreement.
11
+ In consideration of these premises, and the mutual promises and conditions in this Agreement, the parties hereby agree as follows:
12
+ 1. Grant of Evaluation License. NTT hereby grants to User, and User hereby accepts, under the terms and conditions of this Agreement, a royalty free, nontransferable and nonexclusive license to use the Software internally for the purposes of testing, analyzing, and evaluating the methods or mechanisms as shown in the research paper submitted by NTT to a certain academy. User may make a reasonable number of backup copies of the Software solely for User's internal use pursuant to the license granted in this Section 1.
13
+ 2. Shipment and Installation. NTT will ship or deliver the Software by any method that NTT deems appropriate. User shall be solely responsible for proper installation of the Software.
14
+ 3. Term. This Agreement is effective whichever is earlier (i) upon User's acceptance of the Agreement, or (ii) upon User's installing, accessing, and using the Software, even if User has not expressly accepted this Agreement. Without prejudice to any other rights, NTT may terminate this Agreement without notice to User (i) if User breaches or fails to comply with any of the limitations or other requirements described herein, and (ii) if NTT receives a notice from the academy stating that the research paper would not be published, and in any such case User agrees that NTT may, in addition to any other remedies it may have at law or in equity, remotely disable the Software. User may terminate this Agreement at any time by User�fs decision to terminate the Agreement to NTT and ceasing use of the Software. Upon any termination or expiration of this Agreement for any reason, User agrees to uninstall the Software and either return to NTT the Software and all copies thereof, or to destroy all such materials and provide written verification of such destruction to NTT.
15
+ 4. Proprietary Rights
16
+ (a) The Software is the valuable, confidential, and proprietary property of NTT, and NTT shall retain exclusive title to this property both during the term and after the termination of this Agreement. Without limitation, User acknowledges that all patent rights, copyrights and trade secret rights in the Software shall remain the exclusive property of NTT at all times. User shall use not less than reasonable care in safeguarding the confidentiality of the Software.
17
+ (b) USER SHALL NOT, IN WHOLE OR IN PART, AT ANY TIME DURING THE TERM OF OR AFTER THE TERMINATION OF THIS AGREEMENT: (i)?SELL, ASSIGN, LEASE, DISTRIBUTE, OR OTHERWISE TRANSFER THE SOFTWARE TO ANY THIRD PARTY; (ii) EXCEPT AS OTHERWISE PROVIDED HEREIN, COPY OR REPRODUCE THE SOFTWARE IN ANY MANNER; (iii) DISCLOSE THE SOFTWARE TO ANY THIRD PARTY, EXCEPT TO USER'S EMPLOYEES WHO REQUIRE ACCESS TO THE SOFTWARE FOR THE PURPOSES OF THIS AGREEMENT; (iv) MODIFY, DISASSEMBLE, DECOMPILE, REVERSE ENGINEER OR TRANSLATE THE SOFTWARE; OR (v) ALLOW ANY PERSON OR ENTITY TO COMMIT ANY OF THE ACTIONS DESCRIBED IN (i) THROUGH (iv) ABOVE.
18
+ (c) User shall take appropriate action, by instruction, agreement, or otherwise, with respect to its employees permitted under this Agreement to have access to the Software to ensure that all of User's obligations under this Section 4 shall be satisfied.
19
+ 5. Indemnity. User shall defend, indemnify and hold harmless NTT, its agents and employees, from any loss, damage, or liability arising in connection with User's improper or unauthorized use of the Software. NTT SHALL HAVE THE SOLE RIGHT TO CONDUCT DEFEND ANY ACTTION RELATING TO THE SOFTWARE.
20
+ 6. Disclaimer. THE SOFTWARE IS LICENSED TO USER "AS IS," WITHOUT ANY TRAINING, MAINTENANCE, OR SERVICE OBLIGATIONS WHATSOEVER ON THE PART OF NTT. NTT MAKES NO EXPRESS OR IMPLIED WARRANTIES OF ANY TYPE WHATSOEVER, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE AND OF NON-INFRINGEMENT ON COPYRIGHT OR ANY OTHER RIGHT OF THIRD PARTIES. USER ASSUMES ALL RISKS ASSOCIATED WITH ITS USE OF THE SOFTWARE, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, PERFORMANCE, DATA LOSS, AND UTILITY IN A PRODUCTION ENVIRONMENT.
21
+ 7. Limitation of Liability. IN NO EVENT SHALL NTT BE LIABLE TO USER OR TO ANY THIRD PARTY FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING BUT NOT LIMITED TO DAMAGES FOR PERSONAL INJURY, PROPERTY DAMAGE, LOST PROFITS, OR OTHER ECONOMIC LOSS, ARISING IN CONNECTION WITH USER'S USE OF OR INABILITY TO USE THE SOFTWARE, IN CONNECTION WITH NTT'S PROVISION OF OR FAILURE TO PROVIDE SERVICES PERTAINING TO THE SOFTWARE, OR AS A RESULT OF ANY DEFECT IN THE SOFTWARE. THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT MAY BE BROUGHT AGAINST NTT, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT LIMITATION ANY ACTION FOR NEGLIGENCE. USER'S SOLE REMEDY IN THE EVENT OF ANY BREACH OF THIS AGREEMENT BY NTT SHALL BE TERMINATION PURSUANT TO SECTION 3.
22
+ 8. No Assignment or Sublicense. Neither this Agreement nor any right or license under this Agreement, nor the Software, may be sublicensed, assigned, or otherwise transferred by User without NTT's prior written consent.
23
+ 9. General
24
+ (a) If any provision, or part of a provision, of this Agreement is or becomes illegal, unenforceable, or invalidated, by operation of law or otherwise, that provision or part shall to that extent be deemed omitted, and the remainder of this Agreement shall remain in full force and effect.
25
+ (b) This Agreement is the complete and exclusive statement of the agreement between the parties with respect to the subject matter hereof, and supersedes all written and oral contracts, proposals, and other communications between the parties relating to that subject matter.
26
+ (c) Subject to Section 8, this Agreement shall be binding on, and shall inure to the benefit of, the respective successors and assigns of NTT and User.
27
+ (d) If either party to this Agreement initiates a legal action or proceeding to enforce or interpret any part of this Agreement, the prevailing party in such action shall be entitled to recover, as an element of the costs of such action and not as damages, its attorneys' fees and other costs associated with such action or proceeding.
28
+ (e) This Agreement shall be governed by and interpreted under the laws of Japan, without reference to conflicts of law principles. All disputes arising out of or in connection with this Agreement shall be finally settled by arbitration in Tokyo in accordance with the Commercial Arbitration Rules of the Japan Commercial Arbitration Association. The arbitration shall be conducted by three (3) arbitrators and in Japanese. The award rendered by the arbitrators shall be final and binding upon the parties. Judgment upon the award may be entered in any court having jurisdiction thereof.
29
+ (f) NTT shall not be liable to the User or to any third party for any delay or failure to perform NTT's obligation set forth under this Agreement due to any cause beyond NTT�fs reasonable control.
30
+
31
+
32
+ EXHIBIT A
33
+
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/README.md ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SODA
2
+ This repository is the imprimentation of "SODA: Story Oriented Dense Video Captioning Evaluation Flamework" published at ECCV 2020 [pdf](https://fujiso.github.io/publications/ECCV2020_soda.pdf).
3
+ SODA measures the performance of video story description systems.
4
+
5
+ ## Update
6
+ v1.1 (2021/5)
7
+ * Added new option "--multi_reference" to deal with multiple reference.
8
+ SODA selects the reference that has the maximum f1 for each video, and returns macro averaged scores.
9
+ * Fixed BertScore import
10
+
11
+ ## Requirements
12
+ python 3.6+ (developed with 3.7)
13
+ * Numpy
14
+ * tqdm
15
+ * [pycocoevalcap (Python3 version)](https://github.com/salaniz/pycocoevalcap)
16
+ * BERTScore (optional)
17
+
18
+ ## Usage
19
+ You can run SODA by specifying the path of system output and that of ground truth.
20
+ Both files should be the json format for ActivityNet Captions.
21
+ ```bash
22
+ python soda.py -s path/to/submission.json -r path/to/ground_truth.json
23
+ ```
24
+
25
+ You can run on the multiple reference setting, with `--multi_reference` option.
26
+ ```bash
27
+ python soda.py --multi_reference -s path/to/submission.json -r path/to/ground_truth1.json path/to/ground_truth2.json
28
+ ```
29
+
30
+ You can try other sentence evaluation metrics, e.g. CIDEr and BERTScore, with `-m` option.
31
+ ```bash
32
+ python soda.py -s path/to/submission.json -m BERTScore
33
+ ```
34
+
35
+ ## Sample input file
36
+ Please use the same format as [ActivityNet Challenge](http://activity-net.org/index.html)
37
+ ```
38
+ {
39
+ version: "VERSION 1.0",
40
+ results: {
41
+ "sample_id" : [
42
+ {
43
+ sentence: "This is a sample caption.",
44
+ timestamp: [1.23, 4.56]
45
+ },
46
+ {
47
+ sentence: "This is a sample caption 2.",
48
+ timestamp: [7.89, 19.87]
49
+ }
50
+ ]
51
+ }
52
+ external_data: {
53
+ used: False,
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## Reference
59
+ ```
60
+ @inproceedings{Fujita2020soda,
61
+ title={SODA: Story Oriented Dense Video Captioning Evaluation Flamework},
62
+ author={Soichiro Fujita and Tsutomu Hirao and Hidetaka Kamigaito and Manabu Okumura and Masaaki Nagata},
63
+ booktitle={Proceedings of the European Conference on Computer Vision (ECCV)},
64
+ month={August},
65
+ year={2020},
66
+ }
67
+ ```
68
+
69
+ ## LICENSE
70
+ NTT License
71
+
72
+ According to the license, it is not allowed to create pull requests.
73
+ Please feel free to send issues.
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/dataset.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import json
3
+ from collections import defaultdict
4
+ from pycocoevalcap.tokenizer.ptbtokenizer import PTBTokenizer
5
+ from .utils import iou, remove_nonascii
6
+
7
+
8
+ class ANETCaptions:
9
+ def __init__(self, preds, gts, gt_vid, verbose=False):
10
+ self.pred_keys = ['results']
11
+ # self.pred_keys = ['results', 'version', 'external_data']
12
+ self.verbose = verbose
13
+ self.preds = preds
14
+ self.gts = gts
15
+ self.gt_vids = gt_vid
16
+ self.tokenizer = PTBTokenizer()
17
+
18
+ @classmethod
19
+ def from_load_files(cls, gt_file, pred_file, multi_reference=True, verbose=False):
20
+ gts, gt_vid = cls.load_ground_truth(gt_file, multi_reference=multi_reference, verbose=verbose)
21
+ preds = cls.load_prediction(pred_file, verbose=verbose)
22
+ # missing video
23
+ gt_vid = [x for x in gt_vid if x in preds]
24
+ gt_vid = cls.check_videos(gt_vid, preds.keys(),verbose=verbose)
25
+ return cls(preds, gts, gt_vid, verbose=verbose)
26
+
27
+ @classmethod
28
+ def from_prediction(cls, gt_file, preds, multi_reference=True, verbose=False):
29
+ results = {}
30
+ for vid in preds['results']:
31
+ results[vid] = sorted(preds["results"][vid], key=lambda x: x["timestamp"][0])
32
+ gts, gt_vid = cls.load_ground_truth(gt_file, multi_reference=multi_reference)
33
+ gt_vid = cls.check_videos(gt_vid, results.keys(),verbose=verbose)
34
+
35
+ return cls(results, gts, gt_vid, verbose=verbose)
36
+
37
+ @staticmethod
38
+ def load_ground_truth(filenames, multi_reference=False, verbose=False):
39
+ if verbose:
40
+ print(f"| Loading ground truths: {filenames}.")
41
+ if isinstance(filenames, str):
42
+ filenames = [filenames]
43
+ gt_vids = set()
44
+ gt = defaultdict(dict)
45
+ gts = []
46
+ for filename in filenames:
47
+ if isinstance(filename, dict):
48
+ _gt = filename
49
+ else:
50
+ with open(filename, "r") as f:
51
+ _gt = json.load(f)
52
+ gt_vids.update(_gt.keys())
53
+ gts.append(_gt)
54
+ if multi_reference is False:
55
+ for vid in gt_vids:
56
+ t, s = [], []
57
+ for _g in gts:
58
+ if vid not in _g:
59
+ continue
60
+ t += _g[vid]["timestamps"]
61
+ s += _g[vid]["sentences"]
62
+ sort_t, sort_s = list(zip(*sorted(zip(t, s), key=lambda x: x[0][0])))
63
+ gt[vid]["timestamps"] = sort_t
64
+ gt[vid]["sentences"] = sort_s
65
+ gts = [gt]
66
+ if verbose:
67
+ print(f"stats:\n\t n_files: {len(filenames)}, n_videos: {len(gt_vids)}")
68
+ return gts, gt_vids
69
+
70
+ @staticmethod
71
+ def load_prediction(filename, verbose=False):
72
+ if verbose: print(f"\n| Loading predictions: {filename}.")
73
+ if isinstance(filename, dict):
74
+ pred = filename
75
+ else:
76
+ with open(filename, 'r') as f:
77
+ pred = json.load(f)
78
+ # If the json file doesn’t have enough attribute
79
+ # if not all([key in pred.keys() for key in ["results"]]):
80
+ # raise IOError('Please input a correct format prediction file.')
81
+ results = {}
82
+ for vid in pred['results']:
83
+ # if vid not in self.gt_vids: continue
84
+ results[vid] = sorted(pred["results"][vid], key=lambda x: x["timestamp"][0])
85
+ return results
86
+
87
+ def preprocess(self):
88
+ if self.verbose: print("\n| Preprocessing captions...")
89
+ n_ref = len(self.gts)
90
+ p_spliter = [0]
91
+ g_spliter = [[0] for i in range(n_ref)]
92
+ times = {}
93
+ cur_preds = {}
94
+ cur_gts = [{} for i in range(n_ref)]
95
+ for i, vid in enumerate(self.gt_vids):
96
+ cur_preds.update({j+p_spliter[-1]:[{"caption": remove_nonascii(p["sentence"])}] for j,p in enumerate(self.preds[vid])})
97
+ times[i] = [p["timestamp"] for p in self.preds[vid]]
98
+ p_spliter.append(p_spliter[-1] + len(times[i]))
99
+ for n in range(n_ref):
100
+ if vid not in self.gts[n]:
101
+ g_spliter[n].append(g_spliter[n][-1])
102
+ continue
103
+ cur_gts[n].update({j+g_spliter[n][-1]:[{"caption": remove_nonascii(p)}] for j,p in enumerate(self.gts[n][vid]["sentences"])})
104
+ g_spliter[n].append(g_spliter[n][-1] + len(self.gts[n][vid]["sentences"]))
105
+ tokenize_preds = self.tokenizer.tokenize(cur_preds)
106
+ tokenize_gts = [self.tokenizer.tokenize(j) for j in cur_gts]
107
+ for i, vid in enumerate(self.gt_vids):
108
+ _p = [tokenize_preds[j] for j in range(p_spliter[i],p_spliter[i+1])]
109
+ self.preds[vid] = {"timestamps":times[i], "sentences":_p}
110
+ for n in range(n_ref):
111
+ if vid not in self.gts[n]: continue
112
+ _g = [tokenize_gts[n][j] for j in range(g_spliter[n][i],g_spliter[n][i+1])]
113
+ self.gts[n][vid]["sentences"] = _g
114
+
115
+ @staticmethod
116
+ def check_videos(gold_vid, pred_vid, verbose=True):
117
+ not_appear = set(gold_vid) - set(pred_vid)
118
+ if len(not_appear) > 0 and verbose:
119
+ print((f"Warning: some videos in ground truth file are not appeared in prediction file!\n"
120
+ f"\t{len(not_appear)} videos are not predicted: {not_appear}"))
121
+ return list(set(gold_vid) & set(pred_vid))
122
+
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/bert_f_score.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ from bert_score.scorer import BERTScorer
3
+
4
+
5
+ class BertScore:
6
+ # def __init__(self, lang="en", model_type="bert-large-uncased"):
7
+ def __init__(self, lang="en", model_type=None):
8
+ self.lang = lang
9
+ self.model_type = model_type
10
+ self.bert = BERTScorer(model_type=model_type, lang=lang)
11
+
12
+ def compute_score(self, gts, res):
13
+ assert gts.keys() == res.keys()
14
+ # convert dict to list of str
15
+ cands = list(map(lambda x: x[0], res.values()))
16
+ refs = list(map(lambda x: x[0], gts.values()))
17
+ (P, R, F), hashname = self.bert.score(cands, refs, return_hash=True)
18
+ # print(f'{hashname}: P={P.mean().item():.6f} R={R.mean().item():.6f} F={F.mean().item():.6f}')
19
+ F = F.numpy()
20
+ return F.mean(), F
21
+
22
+ def method(self):
23
+ return "BertScore"
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/bert_r_score.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ from bert_score.scorer import BERTScorer
4
+
5
+
6
+ class BertScore:
7
+ def __init__(self, lang="en", model_type="roberta-large"):
8
+ self.lang = lang
9
+ self.model_type = model_type
10
+ self.bert = BERTScorer(model_type=model_type, lang=lang)
11
+
12
+ def compute_score(self, gts, res):
13
+ assert gts.keys() == res.keys()
14
+ # convert dict to list of str
15
+ cands = list(map(lambda x: x[0], res.values()))
16
+ refs = list(map(lambda x: x[0], gts.values()))
17
+ (P, R, F), hashname = self.bert.score(cands, refs, return_hash=True)
18
+ #print(f'{hashname}: P={P.mean().item():.6f} R={R.mean().item():.6f} F={F.mean().item():.6f}')
19
+ R = R.numpy()
20
+ return R.mean(), R
21
+
22
+ def method(self):
23
+ return "BertScore"
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/nlpeval/mover.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ import numpy as np
3
+ #from moverscore_v2 import get_idf_dict, word_mover_score
4
+ from moverscore import get_idf_dict, word_mover_score
5
+ from collections import defaultdict
6
+
7
+ class MoverScore:
8
+ def __init__(self, lang="en", model_type=None):
9
+ self.lang = lang
10
+ self.model_type=model_type
11
+ #self.model = load_model(model_type=model_type, lang=lang)
12
+ self.idf_dict_ref = None
13
+ self.idf_dict_hyp = None
14
+
15
+ def compute_score(self, gts, res):
16
+ assert gts.keys()==res.keys()
17
+ assert self.idf_dict_hyp is not None and self.idf_dict_hyp is not None
18
+ # convert dict to list of str
19
+ cands = list(map(lambda x:x[0], res.values()))
20
+ refs = list(map(lambda x:x[0], gts.values()))
21
+
22
+ scores = word_mover_score(refs, cands, self.idf_dict_ref, self.idf_dict_hyp, \
23
+ stop_words=[], n_gram=1, remove_subwords=True)
24
+ #print(np.mean(scores), max(scores))
25
+ return np.mean(scores), scores
26
+
27
+ def make_dict(self, all_gts, all_res, vids):
28
+ gold = []
29
+ pred = []
30
+ for vid in vids:
31
+ gold.extend(all_gts[vid]["sentences"])
32
+ pred.extend([pred["sentence"] for pred in all_res[vid]])
33
+ self.idf_dict_ref = get_idf_dict(gold)
34
+ self.idf_dict_hyp = get_idf_dict(pred)
35
+ #print(self.idf_dict_hyp)
36
+
37
+ def method(self):
38
+ return "MoverScore"
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ numpy==1.19.1
2
+ tqdm==4.48.2
Vtimellm_training_file/vtimellm/eval/dvc_eval/SODA/soda.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/uer/bin/env python
2
+ import argparse
3
+ import json
4
+ from tqdm import tqdm
5
+ import numpy as np
6
+
7
+ from pycocoevalcap.tokenizer.ptbtokenizer import PTBTokenizer
8
+ from pycocoevalcap.meteor.meteor import Meteor
9
+ from pycocoevalcap.cider.cider import Cider
10
+
11
+ from .dataset import ANETCaptions
12
+ from .utils import iou, remove_nonascii
13
+
14
+
15
+ class SODA:
16
+ def __init__(self, data, soda_type="c", tious=None, scorer="Meteor", verbose=False):
17
+ #self.data = data
18
+ self.preds = data.preds
19
+ self.gts = data.gts
20
+ self.gt_vids = data.gt_vids
21
+ self.soda_type = soda_type
22
+ self.tious = [0.0] if tious is None else tious
23
+ self.tokenizer = PTBTokenizer()
24
+ if scorer == "BertScore":
25
+ from nlpeval.bert_r_score import BertScore
26
+ self.scorer = eval(scorer)()
27
+ self.scorer_name = scorer
28
+ self.verbose = verbose
29
+
30
+ if soda_type == "a": # averaging F-measure scores with IoU threshold = 0.9, 0.7, 0.5, 0.3
31
+ self.soda_func = self.soda_a
32
+ elif soda_type == "b": # F-measure, where IoU threshold is set to 0.
33
+ self.soda_func = self.soda_b
34
+ elif soda_type == "c": # F-measure, utilizing the IoU x METEOR score
35
+ self.soda_func = self.soda_c
36
+ elif soda_type == "d": # F-measure of IoU score
37
+ self.soda_func = self.soda_d
38
+
39
+ class Dummy:
40
+ def compute_score(self, x, y):
41
+ return [0, 0]
42
+
43
+ self.scorer = Dummy()
44
+ else:
45
+ raise NotImplementedError
46
+
47
+ @classmethod
48
+ def build(cls, preds, gts, gt_vids, soda_type="c", tious=[0.0], scorer="Meteor", verbose=False):
49
+ data = ANETCaptions(preds, gts, gt_vids)
50
+ data.preprocess()
51
+ return cls(data, soda_type, tious, scorer, verbose)
52
+
53
+ @classmethod
54
+ def build_from_prediction(cls, preds, gt_files, soda_type="c", tious=[0.0], scorer="Meteor", verbose=False):
55
+ data = ANETCaptions.from_prediction(gt_files, preds)
56
+ data.preprocess()
57
+ return cls(data, soda_type, tious, scorer, verbose)
58
+
59
+ def calc_iou_matrix(self, preds, golds):
60
+ #print(preds["timestamps"], gt["timestamps"])
61
+ return np.array([[iou(pred, ct) for pred in preds["timestamps"]] for ct in golds['timestamps']])
62
+
63
+ def calc_score_matrix(self, preds, golds):
64
+ # Reformat to fit the input of pycocoevalcap scorers.
65
+ p_sent, g_sent = preds["sentences"], golds["sentences"]
66
+ res = {index: p for index, p in enumerate(p_sent)}
67
+ gts = [{index: g for index in range(len(p_sent))} for i, g in enumerate(g_sent)]
68
+ return np.array([self.scorer.compute_score(res, gt)[1] for gt in gts])
69
+
70
+ def evaluate(self,):
71
+ if self.verbose:
72
+ print(f"\n| Running SODA {self.soda_type}.")
73
+ tious = self.tious
74
+ p_best = [[] for i in range(len(tious))]
75
+ r_best = [[] for i in range(len(tious))]
76
+ f_best = [[] for i in range(len(tious))]
77
+ n_pred = []
78
+ for vid in tqdm(self.gt_vids, disable=not self.verbose):
79
+ _p = [[] for i in range(len(tious))]
80
+ _r = [[] for i in range(len(tious))]
81
+ _f = [[] for i in range(len(tious))]
82
+ pred = self.preds[vid]
83
+ n_pred.append(len(pred["sentences"]))
84
+ # empty pred
85
+ if not pred['sentences']:
86
+ for i, tiou in enumerate(tious):
87
+ p_best[i].append(0)
88
+ r_best[i].append(0)
89
+ f_best[i].append(0)
90
+ continue
91
+ for gt in self.gts:
92
+ if vid not in gt:
93
+ continue
94
+ gold = gt[vid]
95
+ # create matrix
96
+ _iou = self.calc_iou_matrix(pred, gold)
97
+ scores = self.calc_score_matrix(pred, gold)
98
+ for i, tiou in enumerate(tious):
99
+ iou = np.copy(_iou)
100
+ iou[iou < tiou] = 0.0
101
+ try:
102
+ max_score, pairs = self.soda_func(iou, scores)
103
+ except: # RecursionError
104
+ max_score, pairs = 0., None
105
+ (n_g, n_p) = iou.shape
106
+ p = max_score / n_p
107
+ r = max_score / n_g
108
+ _p[i].append(p)
109
+ _r[i].append(r)
110
+ _f[i].append(2 * p * r / (p + r) if p+r > 0 else 0)
111
+ best_idx = np.argmax(_f, axis=1)
112
+ for i, tiou in enumerate(tious):
113
+ p_best[i].append(_p[i][best_idx[i]])
114
+ r_best[i].append(_r[i][best_idx[i]])
115
+ f_best[i].append(_f[i][best_idx[i]])
116
+ precision = np.mean(p_best, axis=1)
117
+ recall = np.mean(r_best, axis=1)
118
+ f1 = np.mean(f_best, axis=1)
119
+ print(f"avg. outputs: {np.mean(n_pred)}")
120
+ # average scores across all the tIoUs
121
+ if self.verbose:
122
+ for i, tiou in enumerate(tious):
123
+ partial_result = {self.scorer_name: [precision[i], recall[i], f1[i]]}
124
+ print_score(partial_result, description=f"tIoU: {tiou}")
125
+
126
+ final_scores = [np.mean(precision), np.mean(recall), np.mean(f1)]
127
+ result = {self.scorer_name: final_scores}
128
+ return result
129
+
130
+ def soda_a(self, iou, scores):
131
+ _, pairs = self.chased_dp_assignment(iou)
132
+ r, c = (*zip(*pairs),)
133
+ max_score = np.sum(scores[r, c])
134
+ return max_score, pairs
135
+
136
+ def soda_b(self, iou, scores):
137
+ # same as soda_a
138
+ _, pairs = self.chased_dp_assignment(iou)
139
+ r, c = (*zip(*pairs),)
140
+ max_score = np.sum(scores[r, c])
141
+ return max_score, pairs
142
+
143
+ def soda_c(self, iou, scores):
144
+ max_score, pairs = self.chased_dp_assignment(iou*scores)
145
+ return max_score, pairs
146
+
147
+ def soda_d(self, iou, scores):
148
+ max_score, pairs = self.chased_dp_assignment(iou)
149
+ return max_score, pairs
150
+
151
+ def chased_dp_assignment(self, scores):
152
+ """
153
+ Run dp matching
154
+ Recurrence:
155
+ dp[i,j] =
156
+ max(dp[i-1,j], dp[i-1,j-1] + scores[i,j], dp[i,j-1])
157
+ """
158
+ M, N = scores.shape
159
+ dp = - np.ones((M, N))
160
+ path = np.zeros((M, N))
161
+
162
+ def transition(i, j):
163
+ if dp[i, j] >= 0:
164
+ return dp[i, j]
165
+ elif i == 0 and j == 0:
166
+ state = [-1, -1, scores[i, j]]
167
+ elif i == 0:
168
+ state = [-1, transition(i, j-1), scores[i, j]]
169
+ elif j == 0:
170
+ state = [transition(i-1, j), -1, scores[i, j]]
171
+ else:
172
+ state = [transition(i-1, j), transition(i, j-1), transition(i-1, j-1) + scores[i, j]]
173
+ dp[i, j] = np.max(state)
174
+ path[i, j] = np.argmax(state)
175
+ return dp[i, j]
176
+
177
+ def get_pairs(i, j):
178
+ p = np.where(path[i][:j+1] == 2)[0]
179
+ if i != 0 and len(p) == 0:
180
+ return get_pairs(i-1, j)
181
+ elif i == 0 or p[-1] == 0:
182
+ return [(i, p[-1])]
183
+ else:
184
+ return get_pairs(i-1, p[-1]-1) + [(i, p[-1])]
185
+ N, M = scores.shape
186
+ max_score = transition(N-1, M-1)
187
+ pairs = get_pairs(N-1, M-1)
188
+ return max_score, pairs
189
+
190
+
191
+ def print_score(result, description="SODA result"):
192
+ prf = ["precision", "recall", "f1_score"]
193
+ print('-' * 80)
194
+ print(description)
195
+ print('-' * 80)
196
+ for scorer_name, score in result.items():
197
+ print(f'| scorer:{scorer_name}')
198
+ for k, v in zip(prf, score):
199
+ print(f"\t{k}:{v*100:2.4f}")
200
+
201
+
202
+ def main(args):
203
+ # Call coco eval
204
+ data = ANETCaptions.from_load_files(args.references,
205
+ args.prediction,
206
+ multi_reference=args.multi_reference,
207
+ verbose=args.verbose,
208
+ )
209
+ data.preprocess()
210
+ if args.soda_type == 'a':
211
+ tious = args.tious
212
+ else:
213
+ tious = None
214
+ evaluator = SODA(data,
215
+ soda_type=args.soda_type,
216
+ tious=tious,
217
+ scorer=args.metric,
218
+ verbose=args.verbose
219
+ )
220
+ result = evaluator.evaluate()
221
+ print_score(result)
222
+
223
+
224
+ if __name__ == '__main__':
225
+ parser = argparse.ArgumentParser()
226
+ parser.add_argument('-p', '--prediction', type=str, required=True, default='sample.json',
227
+ help='system output file with json format for ActivityNet Challenge')
228
+ parser.add_argument('-r', '--references', type=str, nargs='+', default=['./data/val_1.json', './data/val_2.json'],
229
+ help='reference files with ground truth captions')
230
+ parser.add_argument('-m', '--metric', type=str, default="Meteor", choices=['Meteor', 'Cider', 'BertScore'],
231
+ help='choice evaluation metrics for SODA')
232
+ parser.add_argument('-s', '--soda_type', type=str, default="c", choices=['a', 'b', 'c', 'd'],
233
+ help='choice evaluation metrics for SODA')
234
+ parser.add_argument('--tious', type=float, nargs='+', default=[0.3, 0.5, 0.7, 0.9],
235
+ help='list of the tIoUs (only for SODA-a)')
236
+ parser.add_argument('-mr', '--multi_reference', action='store_true',
237
+ help='print details')
238
+ parser.add_argument('-v', '--verbose', action='store_true',
239
+ help='print details')
240
+ args = parser.parse_args()
241
+
242
+ main(args)