利用现有模型处理面部视频获取特征向量(4)

于是载入完整版视频

bash 复制代码
conda activate video_features
cd video_features 
python main.py \
    feature_type=r21d \
    device="cuda:0" \
    video_paths="[/home/ubuntu/low/0.mp4,/home/ubuntu/low/1.mp4,/home/ubuntu/low/2.mp4,/home/ubuntu/low/3.mp4,/home/ubuntu/low/4.mp4,/home/ubuntu/low/5.mp4,/home/ubuntu/low/6.mp4,/home/ubuntu/low/7.mp4,/home/ubuntu/low/8.mp4,/home/ubuntu/low/9.mp4,/home/ubuntu/low/10.mp4,/home/ubuntu/low/12.mp4,/home/ubuntu/low/13.mp4,/home/ubuntu/low/14.mp4,/home/ubuntu/low/15.mp4,/home/ubuntu/low/16.mp4,/home/ubuntu/low/17.mp4,/home/ubuntu/low/18.mp4,/home/ubuntu/low/19.mp4,/home/ubuntu/low/20.mp4,/home/ubuntu/low/21.mp4,/home/ubuntu/low/22.mp4,/home/ubuntu/low/23.mp4,/home/ubuntu/low/24.mp4,/home/ubuntu/low/25.mp4,/home/ubuntu/low/26.mp4,/home/ubuntu/low/27.mp4,/home/ubuntu/low/28.mp4,/home/ubuntu/low/29.mp4,/home/ubuntu/low/30.mp4,/home/ubuntu/low/31.mp4,/home/ubuntu/low/32.mp4,/home/ubuntu/low/33.mp4,/home/ubuntu/low/34.mp4,/home/ubuntu/low/35.mp4,/home/ubuntu/low/36.mp4,/home/ubuntu/low/37.mp4,/home/ubuntu/low/38.mp4,/home/ubuntu/low/39.mp4,/home/ubuntu/low/40.mp4,/home/ubuntu/low/41.mp4,/home/ubuntu/low/42.mp4,/home/ubuntu/low/43.mp4,/home/ubuntu/low/44.mp4,/home/ubuntu/low/45.mp4,/home/ubuntu/low/46.mp4,/home/ubuntu/low/47.mp4,/home/ubuntu/low/48.mp4,/home/ubuntu/low/49.mp4,/home/ubuntu/low/50.mp4,/home/ubuntu/low/51.mp4,/home/ubuntu/low/52.mp4,/home/ubuntu/low/53.mp4,/home/ubuntu/low/54.mp4,/home/ubuntu/low/55.mp4,/home/ubuntu/low/56.mp4,/home/ubuntu/low/57.mp4,/home/ubuntu/low/58.mp4,/home/ubuntu/low/59.mp4,/home/ubuntu/low/60.mp4,/home/ubuntu/low/61.mp4,/home/ubuntu/low/62.mp4,/home/ubuntu/low/63.mp4,/home/ubuntu/low/64.mp4,/home/ubuntu/low/65.mp4,/home/ubuntu/low/66.mp4,/home/ubuntu/low/67.mp4,/home/ubuntu/low/68.mp4,/home/ubuntu/low/69.mp4]"

并且把支持的feature_type尝试个遍,clip、i3d、r21d、raft、resnet、s3d、timm和vggish共八个

率先试一下r21d,对69个视频处理过后会生成什么,修改configs中的r21d.yml文件

把output_path指代清楚,并且把on_extraction这里换成我prefer的numpy形式

运行完之后,把output_path当中的文件夹下载到window,写一个代码把生成的69个.npy文件整合到一个csv文件中,供我跑机器学习。npy------>csv代码如下

python 复制代码
import numpy as np
import pandas as pd
import os,re
from itertools import chain
numpy_os = "C:/Users/DDDCY/Desktop/fsdownload/r2plus1d_18_16_kinetics"
csv_os = "C:/Users/DDDCY/Desktop/result/features"

def natural_sort_key(s):
    """
    按文件名的结构排序,即依次比较文件名的非数字和数字部分
    """
    sub_strings = re.split(r'(\d+)', s)
    sub_strings = [int(c) if c.isdigit() else c for c in sub_strings]
    return sub_strings

filenames = os.listdir(numpy_os)
filename = sorted(filenames, key=natural_sort_key)
df = pd.DataFrame()
for file in filename:
    input = np.load(numpy_os+'/'+file)
    x = list(chain.from_iterable(input))
    dx = pd.DataFrame(x)
    dy = dx.transpose()
    df = pd.concat([df,dy])
df = df.reset_index(drop=True)
df.to_csv(csv_os+'/r21d.csv',sep=',',index="None")

每个视频其实输出的特征是一个93 rows x512 columns 的向量,但是考虑到如果再增加一个维度,变成三维张量,机器学习算法不好处理。所以我把每个视频的二维向量转化为一维。结果就如下了。

既然拿到了特征,我就赶忙去跑一下机器学习。还是先跑个回归吧

相关推荐
Eiceblue1 小时前
Python 合并 Excel 单元格
开发语言·vscode·python·pycharm·excel
weixin_421133414 小时前
编写python 后端 vscode 安装插件大全
开发语言·vscode·python
hshpy5 小时前
start using Python 3.11 after installation
windows·python·python3.11
李智 - 重庆5 小时前
Python3 【高阶函数】水平考试:30道精选试题和答案
经验分享·python·编程技巧·案例学习·错误分析
日日行不惧千万里5 小时前
ultralytics 是什么?
python
我想学LINUX5 小时前
【2024年华为OD机试】 (C卷,200分)- 机器人走迷宫(JavaScript&Java & Python&C/C++)
java·c语言·javascript·python·华为od·机器人
西猫雷婶6 小时前
python学opencv|读取图像(四十五)增加掩模:使用cv2.bitwise_and()函数实现图像按位与运算
开发语言·python·opencv
Zik----7 小时前
pytorch卷积的入门操作
人工智能·pytorch·python
时雨h7 小时前
JDK、JRE、Java SE、Java EE和Java ME的详细解析
java·python·java-ee
琳琳简单点7 小时前
对神经网络基础的理解
人工智能·python·深度学习·神经网络