Videomae Base Finetuned Ucfcrime Full
V
Videomae Base Finetuned Ucfcrime Full
由archit11開發
基於VideoMAE框架在UCF-CRIME數據集上微調的視頻分類模型,專注於破壞行為檢測
下載量 85
發布時間 : 3/17/2024
模型概述
該模型是基於MCG-NJU/videomae-base在UCF-CRIME數據集上微調的版本,主要用於視頻中的破壞行為檢測和分類任務。
模型特點
破壞行為檢測
專門針對視頻中的破壞行為進行識別和分類
基於VideoMAE框架
採用高效的VideoMAE自監督學習框架進行預訓練
UCF-CRIME數據集微調
在公開的UCF-CRIME數據集上進行微調,專注於異常行為識別
模型能力
視頻分類
破壞行為檢測
即時視頻分析
使用案例
安防監控
公共場所異常行為檢測
檢測公共場所中的破壞行為或異常活動
智能家居
家庭安全監控
通過家庭攝像頭檢測可能的破壞行為
🚀 videomae-base-finetuned-ucfcrime-full2
該模型是在 UCF-CRIME 數據集上對 MCG-NJU/videomae-base 進行微調後的版本。代碼鏈接:github。 它在評估集上取得了以下結果:
- 損失值:2.5014
- 準確率:0.225
🚀 快速開始
此模型基於 MCG-NJU/videomae-base
在 UCF-CRIME
數據集上微調而來,可用於視頻分類任務,尤其是破壞行為檢測。
✨ 主要特性
- 基於
VideoMAE
架構,適用於視頻分類。 - 在
UCF-CRIME
數據集上進行了微調。
📦 安裝指南
文檔未提供安裝步驟,可參考原模型 MCG-NJU/videomae-base
的安裝說明。
💻 使用示例
基礎用法
使用手機攝像頭進行推理(需從應用商店下載 ipwebcam
應用到手機):
import cv2
import torch
import numpy as np
from transformers import AutoImageProcessor, VideoMAEForVideoClassification
np.random.seed(0)
def preprocess_frames(frames, image_processor):
inputs = image_processor(frames, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()} # Move tensors to GPU
return inputs
# Initialize the video capture object, replace ip addr with the local ip of your phone (will be shown in the ipwebcam app)
cap = cv2.VideoCapture('http://192.168.229.98:8080/video')
# Set the frame size (optional)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
image_processor = AutoImageProcessor.from_pretrained("archit11/videomae-base-finetuned-ucfcrime-full")
model = VideoMAEForVideoClassification.from_pretrained("archit11/videomae-base-finetuned-ucfcrime-full")
# Move the model to GPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
frame_buffer = []
buffer_size = 16
previous_labels = []
top_confidences = [] # Initialize top_confidences
while True:
ret, frame = cap.read()
if not ret:
print("Failed to capture frame")
break
# Add the current frame to the buffer
frame_buffer.append(frame)
# Check if we have enough frames for inference
if len(frame_buffer) >= buffer_size:
# Preprocess the frames
inputs = preprocess_frames(frame_buffer, image_processor)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
# Get the top 3 predicted labels and their confidence scores
top_k = 3
probs = torch.softmax(logits, dim=-1)
top_probs, top_indices = torch.topk(probs, top_k)
top_labels = [model.config.id2label[idx.item()] for idx in top_indices[0]]
top_confidences = top_probs[0].tolist() # Update top_confidences
# Check if the predicted labels are different from the previous labels
if top_labels != previous_labels:
previous_labels = top_labels
print("Predicted class:", top_labels[0]) # Print the predicted class for debugging
# Clear the frame buffer and continue from the next frame
frame_buffer.clear()
# Display the predicted labels and confidence scores on the frame
for i, (label, confidence) in enumerate(zip(previous_labels, top_confidences)):
label_text = f"{label}: {confidence:.2f}"
cv2.putText(frame, label_text, (10, 30 + i * 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release everything when done
cap.release()
cv2.destroyAllWindows()
高級用法
簡單使用示例:
import av
import torch
import numpy as np
from transformers import AutoImageProcessor, VideoMAEForVideoClassification
from huggingface_hub import hf_hub_download
np.random.seed(0)
def read_video_pyav(container, indices):
'''
Decode the video with PyAV decoder.
Args:
container (`av.container.input.InputContainer`): PyAV container.
indices (`List[int]`): List of frame indices to decode.
Returns:
result (np.ndarray): np array of decoded frames of shape (num_frames, height, width, 3).
'''
frames = []
container.seek(0)
start_index = indices[0]
end_index = indices[-1]
for i, frame in enumerate(container.decode(video=0)):
if i > end_index:
break
if i >= start_index and i in indices:
frames.append(frame)
return np.stack([x.to_ndarray(format="rgb24") for x in frames])
def sample_frame_indices(clip_len, frame_sample_rate, seg_len):
'''
Sample a given number of frame indices from the video.
Args:
clip_len (`int`): Total number of frames to sample.
frame_sample_rate (`int`): Sample every n-th frame.
seg_len (`int`): Maximum allowed index of sample's last frame.
Returns:
indices (`List[int]`): List of sampled frame indices
'''
converted_len = int(clip_len * frame_sample_rate)
end_idx = np.random.randint(converted_len, seg_len)
start_idx = end_idx - converted_len
indices = np.linspace(start_idx, end_idx, num=clip_len)
indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
return indices
# video clip consists of 300 frames (10 seconds at 30 FPS)
file_path = hf_hub_download(
repo_id="nielsr/video-demo", filename="eating_spaghetti.mp4", repo_type="dataset"
)
# use any other video just replace `file_path` with the video path
container = av.open(file_path)
# sample 16 frames
indices = sample_frame_indices(clip_len=16, frame_sample_rate=1, seg_len=container.streams.video[0].frames)
video = read_video_pyav(container, indices)
image_processor = AutoImageProcessor.from_pretrained("archit11/videomae-base-finetuned-ucfcrime-full")
model = VideoMAEForVideoClassification.from_pretrained("archit11/videomae-base-finetuned-ucfcrime-full")
inputs = image_processor(list(video), return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
# model predicts one of the 13 ucf-crime classes
predicted_label = logits.argmax(-1).item()
print(model.config.id2label[predicted_label])
📚 詳細文檔
訓練和評估數據
更多信息待補充。
訓練過程
訓練超參數
訓練過程中使用了以下超參數:
- 學習率:5e-05
- 訓練批次大小:8
- 評估批次大小:8
- 隨機種子:42
- 優化器:Adam,
betas=(0.9, 0.999)
,epsilon=1e-08
- 學習率調度器類型:線性
- 學習率調度器熱身比例:0.1
- 訓練步數:700
訓練結果
訓練損失 | 輪數 | 步數 | 驗證損失 | 準確率 |
---|---|---|---|---|
2.5836 | 0.13 | 88 | 2.4944 | 0.2080 |
2.3212 | 1.13 | 176 | 2.5855 | 0.1773 |
2.2333 | 2.13 | 264 | 2.6270 | 0.1046 |
1.985 | 3.13 | 352 | 2.4058 | 0.2109 |
2.194 | 4.13 | 440 | 2.3654 | 0.2235 |
1.9796 | 5.13 | 528 | 2.2609 | 0.2235 |
1.8786 | 6.13 | 616 | 2.2725 | 0.2341 |
1.71 | 7.12 | 700 | 2.2228 | 0.2226 |
框架版本
- Transformers 4.38.1
- Pytorch 2.1.2
- Datasets 2.1.0
- Tokenizers 0.15.2
📄 許可證
本模型採用 CC BY-NC 4.0
許可證。
Timesformer Base Finetuned K400
TimeSformer是基於Kinetics-400數據集預訓練的視頻分類模型,採用時空注意力機制實現視頻理解。
視頻處理
Transformers

T
facebook
108.61k
33
Vivit B 16x2 Kinetics400
MIT
ViViT是對視覺變換器(ViT)的擴展,適用於視頻處理,特別適合視頻分類任務。
視頻處理
Transformers

V
google
56.94k
32
Animatediff Motion Lora Zoom In
動態LoRAs能夠為動畫添加特定類型的運動效果,如縮放、平移、傾斜和旋轉。
視頻處理
A
guoyww
51.43k
8
Videomae Base
VideoMAE是基於掩碼自編碼器(MAE)的視頻自監督預訓練模型,通過預測被掩碼視頻塊的像素值學習視頻內部表示。
視頻處理
Transformers

V
MCG-NJU
48.66k
45
Dfot
MIT
一種新穎的視頻擴散模型,能夠根據任意數量的上下文幀生成高質量視頻
視頻處理
D
kiwhansong
47.19k
6
Videomae Base Finetuned Kinetics
VideoMAE是基於掩碼自編碼器(MAE)的視頻自監督預訓練模型,在Kinetics-400數據集上微調後可用於視頻分類任務。
視頻處理
Transformers

V
MCG-NJU
44.91k
34
Mochi 1 Preview
Apache-2.0
由Genmo開發的高保真視頻生成模型,具有卓越的運動表現力和精準的提示跟隨能力
視頻處理 英語
M
genmo
27.13k
1,216
Animatediff Motion Lora Zoom Out
動態LoRAs能為動畫添加特定類型的運動效果
視頻處理
A
guoyww
11.43k
5
Ppo SpaceInvadersNoFrameskip V4
這是一個基於PPO算法的強化學習智能體,專門用於在SpaceInvadersNoFrameskip-v4遊戲環境中進行訓練和遊戲。
視頻處理
P
sb3
8,999
0
Stable Video Diffusion Img2vid Xt 1 1
其他
Stable Video Diffusion (SVD) 1.1 是一款基於擴散模型的圖像轉視頻工具,能夠將靜態圖像作為條件幀生成短視頻片段。
視頻處理
S
vdo
8,560
28
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98