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