Action Recognition with an Inflated 3D CNN | TF Hub

2023-10-17 04:10

本文主要是介绍Action Recognition with an Inflated 3D CNN | TF Hub,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

action_recognition_with_tf_hub

recognizing actions in video data using the tfhub.dev/deepmind/i3d-kinetics-400/1 module
More models to detect actions in videos can be found here
解读: 用 tfhub.dev/deepmind/i3d-kinetics-400/1 模块去识别视频数据里的动作

The underlying model is described in the paper Action Recognition? A New Model and the Kinetics Dataset, CVPR 2017 conference paper. The source code is publicly available on github
解读: 论文和代码自取

the inflated 3D Convnet or I3D, video classification
This architecture achieved state-of-the-art results on the UCF101 and HMDB51 datasets from fine-tuning these models
The original module was trained on the kinetics-400 dataset and knows about 400 different actions. Labels for these actions can be found in the label map file
recognize activites in videos from a UCF101 dataset
解读: 用在 Kinetics-400 Dataset 上训练的模型去识别 UCF101 数据集上的 Video

# TensorFlow and TF-Hub modules.
from absl import loggingimport tensorflow as tf
import tensorflow_hub as hub
from tensorflow_docs.vis import embedlogging.set_verbosity(logging.ERROR)# Some modules to help with reading the UCF101 dataset.
import random
import re
import os
import tempfile
import ssl
import cv2
import numpy as np# Some modules to display an animation using imageio.
import imageio
from IPython import displayfrom urllib import request  # requires python3# Utilities to fetch videos from UCF101 dataset
UCF_ROOT = "https://www.crcv.ucf.edu/THUMOS14/UCF101/UCF101/"
_VIDEO_LIST = None
_CACHE_DIR = tempfile.mkdtemp()
# As of July 2020, crcv.ucf.edu doesn't use a certificate accepted by the
# default Colab environment anymore.
unverified_context = ssl._create_unverified_context()if not _VIDEO_LIST:index = request.urlopen(UCF_ROOT, context=unverified_context).read().decode("utf-8")videos = re.findall("(v_[\w_]+\.avi)", index)_VIDEO_LIST = sorted(set(videos))


一共有 13320 个视频

def list_ucf_videos():"""Lists videos available in UCF101 dataset."""global _VIDEO_LISTif not _VIDEO_LIST:index = request.urlopen(UCF_ROOT, context=unverified_context).read().decode("utf-8")videos = re.findall("(v_[\w_]+\.avi)", index)_VIDEO_LIST = sorted(set(videos))return list(_VIDEO_LIST)def fetch_ucf_video(video):"""Fetchs a video and cache into local filesystem."""cache_path = os.path.join(_CACHE_DIR, video)if not os.path.exists(cache_path):urlpath = request.urljoin(UCF_ROOT, video)print("Fetching %s => %s" % (urlpath, cache_path))data = request.urlopen(urlpath, context=unverified_context).read()open(cache_path, "wb").write(data)return cache_path# Utilities to open video files using CV2
def crop_center_square(frame):y, x = frame.shape[0:2]min_dim = min(y, x)start_x = (x // 2) - (min_dim // 2)start_y = (y // 2) - (min_dim // 2)return frame[start_y:start_y + min_dim, start_x:start_x + min_dim]def load_video(path, max_frames=0, resize=(224, 224)):cap = cv2.VideoCapture(path)frames = []try:while True:ret, frame = cap.read()if not ret:breakframe = crop_center_square(frame)frame = cv2.resize(frame, resize)frame = frame[:, :, [2, 1, 0]]frames.append(frame)if len(frames) == max_frames:breakfinally:cap.release()return np.array(frames) / 255.0def to_gif(images):converted_images = np.clip(images * 255, 0, 255).astype(np.uint8)imageio.mimsave('./animation.gif', converted_images, fps=25)return embed.embed_file('./animation.gif')# Get a sample cricket video.
video_path = fetch_ucf_video("v_CricketShot_g04_c02.avi")
sample_video = load_video(video_path)
to_gif(sample_video)

video_list = list_ucf_videos()[:2]
# Get a sample cricket video.
for video in video_list:fetch_ucf_video(video)# Get the kinetics-400 action labels from the GitHub repository.
KINETICS_URL = "https://raw.githubusercontent.com/deepmind/kinetics-i3d/master/data/label_map.txt"
with request.urlopen(KINETICS_URL) as obj:labels = [line.decode("utf-8").strip() for line in obj.readlines()]
print("Found %d labels." % len(labels))# Get the list of videos in the dataset.
ucf_videos = list_ucf_videos()categories = {}
for video in ucf_videos:category = video[2:-12]if category not in categories:categories[category] = []categories[category].append(video)
print("Found %d videos in %d categories." % (len(ucf_videos), len(categories)))for category, sequences in categories.items():summary = ", ".join(sequences[:2])print("%-20s %4d videos (%s, ...)" % (category, len(sequences), summary))

i3d = hub.load("https://tfhub.dev/deepmind/i3d-kinetics-400/1").signatures['default']def predict(sample_video):# Add a batch axis to the to the sample video.model_input = tf.constant(sample_video, dtype=tf.float32)[tf.newaxis, ...]logits = i3d(model_input)['default'][0]probabilities = tf.nn.softmax(logits)print("Top 5 actions:")for i in np.argsort(probabilities)[::-1][:5]:print(f"  {labels[i]:22}: {probabilities[i] * 100:5.2f}%")predict(sample_video)

下面是预测输出

这篇关于Action Recognition with an Inflated 3D CNN | TF Hub的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/222843

相关文章

无人叉车3d激光slam多房间建图定位异常处理方案-墙体画线地图切分方案

墙体画线地图切分方案 针对问题:墙体两侧特征混淆误匹配,导致建图和定位偏差,表现为过门跳变、外月台走歪等 ·解决思路:预期的根治方案IGICP需要较长时间完成上线,先使用切分地图的工程化方案,即墙体两侧切分为不同地图,在某一侧只使用该侧地图进行定位 方案思路 切分原理:切分地图基于关键帧位置,而非点云。 理论基础:光照是直线的,一帧点云必定只能照射到墙的一侧,无法同时照到两侧实践考虑:关

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX

SAM2POINT:以zero-shot且快速的方式将任何 3D 视频分割为视频

摘要 我们介绍 SAM2POINT,这是一种采用 Segment Anything Model 2 (SAM 2) 进行零样本和快速 3D 分割的初步探索。 SAM2POINT 将任何 3D 数据解释为一系列多向视频,并利用 SAM 2 进行 3D 空间分割,无需进一步训练或 2D-3D 投影。 我们的框架支持各种提示类型,包括 3D 点、框和掩模,并且可以泛化到不同的场景,例如 3D 对象、室

Unable to instantiate Action, goodsTypeAction, defined for 'goodsType_findAdvanced' in namespace '/

报错: Unable to instantiate Action, goodsTypeAction,  defined for 'goodsType_findAdvanced' in namespace '/'goodsTypeAction......... Caused by: java.lang.ClassNotFoundException: goodsTypeAction.......

深度学习实战:如何利用CNN实现人脸识别考勤系统

1. 何为CNN及其在人脸识别中的应用 卷积神经网络(CNN)是深度学习中的核心技术之一,擅长处理图像数据。CNN通过卷积层提取图像的局部特征,在人脸识别领域尤其适用。CNN的多个层次可以逐步提取面部的特征,最终实现精确的身份识别。对于考勤系统而言,CNN可以自动从摄像头捕捉的视频流中检测并识别出员工的面部。 我们在该项目中采用了 RetinaFace 模型,它基于CNN的结构实现高效、精准的

模具要不要建设3D打印中心

随着3D打印技术的日益成熟与广泛应用,模具企业迎来了自建3D打印中心的热潮。这一举措不仅为企业带来了前所未有的发展机遇,同时也伴随着一系列需要克服的挑战,如何看待企业引进增材制造,小编为您全面分析。 机遇篇: 加速产品创新:3D打印技术如同一把钥匙,为模具企业解锁了快速迭代产品设计的可能。企业能够迅速将创意转化为实体模型,缩短产品从设计到市场的周期,抢占市场先机。 强化定制化服务:面

用ajax json给后台action传数据要注意的问题

必须要有get和set方法   1 action中定义bean变量,注意写get和set方法 2 js中写ajax方法,传json类型数据 3 配置action在struts2中

使用http-request 属性替代action绑定上传URL

在 Element UI 的 <el-upload> 组件中,如果你需要为上传的 HTTP 请求添加自定义的请求头(例如,为了通过身份验证或满足服务器端的特定要求),你不能直接在 <el-upload> 组件的属性中设置这些请求头。但是,你可以通过 http-request 属性来自定义上传的行为,包括设置请求头。 http-request 属性允许你完全控制上传的行为,包括如何构建请求、发送请

WPF入门到跪下 第十三章 3D绘图 - 3D绘图基础

3D绘图基础 四大要点 WPF中的3D绘图涉及4个要点: 视口,用来驻留3D内容3D对象照亮部分或整个3D场景的光源摄像机,提供在3D场景中进行观察的视点 一、视口 要展示3D内容,首先需要一个容器来装载3D内容。在WPF中,这个容器就是Viewport3D(3D视口),它继承自FrameworkElement,因此可以像其他元素那样在XAML中使用。 Viewport3D与其他元素相

如何将卷积神经网络(CNN)应用于医学图像分析:从分类到分割和检测的实用指南

引言 在现代医疗领域,医学图像已经成为疾病诊断和治疗规划的重要工具。医学图像的类型繁多,包括但不限于X射线、CT(计算机断层扫描)、MRI(磁共振成像)和超声图像。这些图像提供了对身体内部结构的详细视图,有助于医生在进行准确诊断和制定个性化治疗方案时获取关键的信息。 1. 医学图像分析的挑战 医学图像分析面临诸多挑战,其中包括: 图像数据的复杂性:医学图像通常具有高维度和复杂的结构