Views
No views yet
1from transformers import AutoModel, AutoTokenizer
2
3def transform(video_pixel):
4 transform_list = [
5 transforms.Lambda(lambda x: x / 255.),
6 Normalize(
7 [0.485, 0.456, 0.406],
8 [0.229, 0.224, 0.225]),
9 ShortSideScale(256),
10 CenterCrop(224),
11 ]
12 transform = Compose(transform_list)
13 return transform(video_pixel).transpose(0, 1)
14
15def captioning(video_tensor):
16
17 video = transform(video)
18
19 model = AutoModel.from_pretrained("fztkm/lc_video_description_videomae_gpt2", trust_remote_code=True).requires_grad_(False)
20 tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
21
22 output_tokens = model.generate(pixel_values=video_tensor, desired_length=desired_length, max_new_tokens=100)
23 caption = tokenizer.batch_decode(output_tokens, skip_special_tokens=True)
24
25 print(caption)1@ARTICLE{Nitta2024_length_control_captioning,
2 author={Nitta, Tomoya and Fukuzawa, Takumi and Tamaki, Toru},
3 journal={IEEE Access},
4 title={Fine-grained length controllable video captioning with ordinal embeddings},
5 year={2024},
6 doi={10.1109/ACCESS.2024.3506751}
7}