Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
Vision Encoder Model: [timesformer-base-finetuned-k600](https://huggingface.co/facebook/timesformer-base-finetuned-k600) \
|
| 6 |
+
Text Decoder Model: [gpt2](https://huggingface.co/gpt2)
|
| 7 |
+
|
| 8 |
+
Dataset used: [MSR-VTT](https://paperswithcode.com/dataset/msr-vtt)
|
| 9 |
+
|
| 10 |
+
#### Results: Epoch 1 finished with average loss: 3.8702
|
| 11 |
+
Epoch 2 finished with average loss: 3.2515
|
| 12 |
+
Epoch 3 finished with average loss: 2.8516
|
| 13 |
+
|
| 14 |
+
#### Example Inference Code:
|
| 15 |
+
```python
|
| 16 |
+
import av
|
| 17 |
+
import numpy as np
|
| 18 |
+
import torch
|
| 19 |
+
from transformers import AutoImageProcessor, AutoTokenizer, VisionEncoderDecoderModel
|
| 20 |
+
|
| 21 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
+
|
| 23 |
+
# load pretrained processor, tokenizer, and model
|
| 24 |
+
image_processor = AutoImageProcessor.from_pretrained("notbdq/videogpt")
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("notbdq/videogpt")
|
| 26 |
+
model = VisionEncoderDecoderModel.from_pretrained("notbdq/videogpt").to(device)
|
| 27 |
+
|
| 28 |
+
video_path = "/kaggle/input/darthvader1/darthvadersurfing.mp4"
|
| 29 |
+
container = av.open(video_path)
|
| 30 |
+
|
| 31 |
+
# extract evenly spaced frames from video
|
| 32 |
+
seg_len = container.streams.video[0].frames
|
| 33 |
+
clip_len = model.config.encoder.num_frames
|
| 34 |
+
indices = set(np.linspace(0, seg_len, num=clip_len, endpoint=False).astype(np.int64))
|
| 35 |
+
frames = []
|
| 36 |
+
container.seek(0)
|
| 37 |
+
for i, frame in enumerate(container.decode(video=0)):
|
| 38 |
+
if i in indices:
|
| 39 |
+
frames.append(frame.to_ndarray(format="rgb24"))
|
| 40 |
+
|
| 41 |
+
# generate caption
|
| 42 |
+
gen_kwargs = {
|
| 43 |
+
"max_length": 20,
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
pixel_values = image_processor(frames, return_tensors="pt").pixel_values.to(device)
|
| 47 |
+
tokens = model.generate(pixel_values, **gen_kwargs)
|
| 48 |
+
caption = tokenizer.batch_decode(tokens, skip_special_tokens=True)[0]
|
| 49 |
+
print(caption) # man is surfing in the ocean and doing tricks on a surfboard
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
#### Author Information:
|
| 53 |
+
🐙 [GitHub](https://github.com/notlober) \
|
| 54 |
+
🤝 [LinkedIn](https://www.linkedin.com/in/selahattin-baki-damar-6bb38128a/)
|