Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoCLIP help on demo script #5571

Open
dnitti-psee opened this issue Dec 6, 2024 · 0 comments
Open

VideoCLIP help on demo script #5571

dnitti-psee opened this issue Dec 6, 2024 · 0 comments

Comments

@dnitti-psee
Copy link

❓ Questions and Help

What is your question?

I wanted to make sure this is the correct way to use the VIDEOCLIP model.
I have a basket video and I want to find the clips of one second that contain the ball (for example).
I also tried queries such as "slum dunk", "ball".
but the score doesn't seem to be good to extract such clips
is this code correct? is the preprocessing correct?

Code

import torch
import cv2
from mmpt.models import MMPTModel
from scripts.video_feature_extractor.preprocessing import Preprocessing
from scripts.video_feature_extractor.videoreader import VideoLoader
import numpy as np
model, tokenizer, aligner = MMPTModel.from_pretrained(
    "projects/retri/videoclip/how2.yaml")

model.eval()

video_loader = VideoLoader(video_dict={},framerate=30,size= 224,centercrop=True,shards= 0)

out_video = video_loader._decode("","/mnt/data/exp/basket.mp4")['video']
out_video = out_video[:out_video.shape[0]//30*30]
out_video = out_video.permute(0, 2, 3, 1)

# preprocessing
video_frames = out_video.view(1, -1, 30, 224, 224, 3)/255.0

caps, cmasks = aligner._build_text_seq(
    tokenizer("ball", add_special_tokens=False)["input_ids"]
)

caps, cmasks = caps[None, :], cmasks[None, :]  # bsz=1

for sec in range(video_frames.size(1)):
    with torch.no_grad():
        output = model(video_frames[:, sec:sec+1], caps, cmasks, return_score=True)["score"]
@dnitti-psee dnitti-psee changed the title VideoCLIP VideoCLIP help on demo script Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant