Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
d625294d
Unverified
Commit
d625294d
authored
Jul 11, 2024
by
Raushan Turganbay
Committed by
GitHub
Jul 11, 2024
Browse files
InstructBlipVideo: Update docstring (#31886)
* update docs * one more change
parent
c54af4c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
src/transformers/models/instructblipvideo/diff_instructblipvideo.py
...ormers/models/instructblipvideo/diff_instructblipvideo.py
+9
-7
src/transformers/models/instructblipvideo/modeling_instructblipvideo.py
...rs/models/instructblipvideo/modeling_instructblipvideo.py
+9
-7
No files found.
src/transformers/models/instructblipvideo/diff_instructblipvideo.py
View file @
d625294d
...
@@ -158,7 +158,8 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipForConditionalGenera
...
@@ -158,7 +158,8 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipForConditionalGenera
>>> from transformers import InstructBlipVideoProcessor, InstructBlipVideoForConditionalGeneration
>>> from transformers import InstructBlipVideoProcessor, InstructBlipVideoForConditionalGeneration
>>> import torch
>>> import torch
>>> from huggingface_hub import hf_hub_download
>>> from huggingface_hub import hf_hub_download
>>> from av
>>> import av
>>> import numpy as np
>>> def read_video_pyav(container, indices):
>>> def read_video_pyav(container, indices):
... '''
... '''
...
@@ -180,20 +181,21 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipForConditionalGenera
...
@@ -180,20 +181,21 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipForConditionalGenera
... frames.append(frame)
... frames.append(frame)
... return np.stack([x.to_ndarray(format="rgb24") for x in frames])
... return np.stack([x.to_ndarray(format="rgb24") for x in frames])
>>> model = InstructBlipVideo
Processor
.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto")
>>> model = InstructBlipVideo
ForConditionalGeneration
.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto")
>>> processor = InstructBlipVideo
ForConditionalGeneration
.from_pretrained("Salesforce/instructblip-vicuna-7b")
>>> processor = InstructBlipVideo
Processor
.from_pretrained("Salesforce/instructblip-vicuna-7b")
>>> file_path = hf_hub_download(
>>> file_path = hf_hub_download(
repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
... repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
)
... )
>>> container = av.open(video_path)
>>> container = av.open(file_path)
>>> # sample uniformly 4 frames from the videWhy is this video funny?o
>>> # sample uniformly 4 frames from the videWhy is this video funny?o
>>> total_frames = container.streams.video[0].frames
>>> total_frames = container.streams.video[0].frames
>>> indices = np.arange(0, total_frames, total_frames / 4).astype(int)
>>> indices = np.arange(0, total_frames, total_frames / 4).astype(int)
>>> clip = read_video_pyav(container, indices)
>>> clip = read_video_pyav(container, indices)
>>> prompt = "What is happening in the video?"
>>> prompt = "What is happening in the video?"
>>> inputs = processor(
videos=clip, text=prompt
, return_tensors="pt").to(device)
>>> inputs = processor(
text=prompt, images=clip
, return_tensors="pt").to(
model.
device)
>>> outputs = model.generate(
>>> outputs = model.generate(
... **inputs,
... **inputs,
...
...
src/transformers/models/instructblipvideo/modeling_instructblipvideo.py
View file @
d625294d
...
@@ -1393,7 +1393,8 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipVideoPreTrainedModel
...
@@ -1393,7 +1393,8 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipVideoPreTrainedModel
>>> from transformers import InstructBlipVideoProcessor, InstructBlipVideoForConditionalGeneration
>>> from transformers import InstructBlipVideoProcessor, InstructBlipVideoForConditionalGeneration
>>> import torch
>>> import torch
>>> from huggingface_hub import hf_hub_download
>>> from huggingface_hub import hf_hub_download
>>> from av
>>> import av
>>> import numpy as np
>>> def read_video_pyav(container, indices):
>>> def read_video_pyav(container, indices):
... '''
... '''
...
@@ -1415,20 +1416,21 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipVideoPreTrainedModel
...
@@ -1415,20 +1416,21 @@ class InstructBlipVideoForConditionalGeneration(InstructBlipVideoPreTrainedModel
... frames.append(frame)
... frames.append(frame)
... return np.stack([x.to_ndarray(format="rgb24") for x in frames])
... return np.stack([x.to_ndarray(format="rgb24") for x in frames])
>>> model = InstructBlipVideo
Processor
.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto")
>>> model = InstructBlipVideo
ForConditionalGeneration
.from_pretrained("Salesforce/instructblip-vicuna-7b", device_map="auto")
>>> processor = InstructBlipVideo
ForConditionalGeneration
.from_pretrained("Salesforce/instructblip-vicuna-7b")
>>> processor = InstructBlipVideo
Processor
.from_pretrained("Salesforce/instructblip-vicuna-7b")
>>> file_path = hf_hub_download(
>>> file_path = hf_hub_download(
repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
... repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
)
... )
>>> container = av.open(video_path)
>>> container = av.open(file_path)
>>> # sample uniformly 4 frames from the videWhy is this video funny?o
>>> # sample uniformly 4 frames from the videWhy is this video funny?o
>>> total_frames = container.streams.video[0].frames
>>> total_frames = container.streams.video[0].frames
>>> indices = np.arange(0, total_frames, total_frames / 4).astype(int)
>>> indices = np.arange(0, total_frames, total_frames / 4).astype(int)
>>> clip = read_video_pyav(container, indices)
>>> clip = read_video_pyav(container, indices)
>>> prompt = "What is happening in the video?"
>>> prompt = "What is happening in the video?"
>>> inputs = processor(
videos=clip, text=prompt
, return_tensors="pt").to(device)
>>> inputs = processor(
text=prompt, images=clip
, return_tensors="pt").to(
model.
device)
>>> outputs = model.generate(
>>> outputs = model.generate(
... **inputs,
... **inputs,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment