语音生成表情SlefTalk

目录

SlefTalk官网

依赖项安装

windows安装psbody

templates.pkl 下载地址:

推理代码:

diffspeaker


SlefTalk官网

GitHub - psyai-net/SelfTalk_release: This is the official source for our ACM MM 2023 paper "SelfTalk: A Self-Supervised Commutative Training Diagram to Comprehend 3D Talking Faces""

有预训练

依赖项安装

GitHub - MPI-IS/mesh: MPI-IS Mesh Processing Library

linux安装psbody库

如何安装psbody库、mesh包-CSDN博客

windows安装psbody

python3.8版本

Windows安装psbody_mesh - 哔哩哔哩

D:\Program Files\boost_1_73_0

templates.pkl 下载地址:

DiffSpeaker/scripts/demo/demo_biwi.sh at 0f2ae2d4e88fe78bff8bb7a1fdbc628e8733f120 · theEricMa/DiffSpeaker · GitHub

推理代码:

import numpy as np
import librosa
import os, argparse, pickle
from SelfTalk import SelfTalk
from transformers import Wav2Vec2Processor
import torch
import time
import cv2
import tempfile
from subprocess import call
import pyrender
# from psbody.mesh import Mesh
import trimesh# os.environ['PYOPENGL_PLATFORM'] = 'osmesa'  # egl@torch.no_grad()
def test_model(args):if not os.path.exists(args.result_path):os.makedirs(args.result_path)# build modelmodel = SelfTalk(args)model.load_state_dict(torch.load('BIWI.pth',map_location=torch.device(args.device)))model = model.to(torch.device(args.device))model.eval()with torch.no_grad():template_file = os.path.join(args.dataset, args.template_path)with open(template_file, 'rb') as fin:templates = pickle.load(fin, encoding='latin1')temp = templates[args.subject]template = temp.reshape((-1))template = np.reshape(template, (-1, template.shape[0]))template = torch.FloatTensor(template).to(device=args.device)wav_path = args.wav_pathtest_name = os.path.basename(wav_path).split(".")[0]speech_array, sampling_rate = librosa.load(os.path.join(wav_path), sr=16000)processor = Wav2Vec2Processor.from_pretrained("jonatasgrosman/wav2vec2-large-xlsr-53-english")audio_feature = np.squeeze(processor(speech_array, sampling_rate=16000).input_values)audio_feature = np.reshape(audio_feature, (-1, audio_feature.shape[0]))audio_feature = torch.FloatTensor(audio_feature).to(device=args.device)start = time.time()prediction, lip_features, logits = model.predict(audio_feature, template)end = time.time()print("Model predict time: ", end - start)prediction = prediction.squeeze()  # (seq_len, V*3)np.save(os.path.join(args.result_path, test_name), prediction.detach().cpu().numpy())# The implementation of rendering is borrowed from VOCA: https://github.com/TimoBolkart/voca/blob/master/utils/rendering.py
def get_unit_factor(unit):if unit == 'mm':return 1000.0elif unit == 'cm':return 100.0elif unit == 'm':return 1.0else:raise ValueError('Unit not supported')def render_mesh_helper(mesh, t_center, rot=np.zeros(3), tex_img=None, z_offset=0):camera_params = {'c': np.array([400, 400]),'k': np.array([-0.19816071, 0.92822711, 0, 0, 0]),'f': np.array([4754.97941935 / 8, 4754.97941935 / 8])}frustum = {'near': 0.01, 'far': 3.0, 'height': 800, 'width': 800}mesh_copy = Mesh(mesh.v, mesh.f)mesh_copy.v[:] = cv2.Rodrigues(rot)[0].dot((mesh_copy.v - t_center).T).T + t_centerintensity = 2.0rgb_per_v = Noneprimitive_material = pyrender.material.MetallicRoughnessMaterial(alphaMode='BLEND',baseColorFactor=[0.3, 0.3, 0.3, 1.0],metallicFactor=0.8,roughnessFactor=0.8)tri_mesh = trimesh.Trimesh(vertices=mesh_copy.v, faces=mesh_copy.f, vertex_colors=rgb_per_v)render_mesh = pyrender.Mesh.from_trimesh(tri_mesh, material=primitive_material, smooth=True)if 1 == 1:scene = pyrender.Scene(ambient_light=[.2, .2, .2], bg_color=[0, 0, 0])else:scene = pyrender.Scene(ambient_light=[.2, .2, .2], bg_color=[255, 255, 255])camera = pyrender.IntrinsicsCamera(fx=camera_params['f'][0],fy=camera_params['f'][1],cx=camera_params['c'][0],cy=camera_params['c'][1],znear=frustum['near'],zfar=frustum['far'])scene.add(render_mesh, pose=np.eye(4))camera_pose = np.eye(4)camera_pose[:3, 3] = np.array([0, 0, 1.0 - z_offset])scene.add(camera, pose=[[1, 0, 0, 0],[0, 1, 0, 0],[0, 0, 1, 1],[0, 0, 0, 1]])angle = np.pi / 6.0pos = camera_pose[:3, 3]light_color = np.array([1., 1., 1.])light = pyrender.DirectionalLight(color=light_color, intensity=intensity)light_pose = np.eye(4)light_pose[:3, 3] = posscene.add(light, pose=light_pose.copy())light_pose[:3, 3] = cv2.Rodrigues(np.array([angle, 0, 0]))[0].dot(pos)scene.add(light, pose=light_pose.copy())light_pose[:3, 3] = cv2.Rodrigues(np.array([-angle, 0, 0]))[0].dot(pos)scene.add(light, pose=light_pose.copy())light_pose[:3, 3] = cv2.Rodrigues(np.array([0, -angle, 0]))[0].dot(pos)scene.add(light, pose=light_pose.copy())light_pose[:3, 3] = cv2.Rodrigues(np.array([0, angle, 0]))[0].dot(pos)scene.add(light, pose=light_pose.copy())flags = pyrender.RenderFlags.SKIP_CULL_FACES# try:# eglr = pyrender.OffscreenRenderer(viewport_width=frustum['width'], viewport_height=frustum['height'])color, _ = r.render(scene, flags=flags)# except:#     print('pyrender: Failed rendering frame')#     color = np.zeros((frustum['height'], frustum['width'], 3), dtype='uint8')return color[..., ::-1]def render_sequence_meshes(audio_fname, sequence_vertices, template, out_path, uv_template_fname='',texture_img_fname=''):if not os.path.exists(out_path):os.makedirs(out_path)tmp_video_file = tempfile.NamedTemporaryFile('w', suffix='.mp4', dir=out_path)if int(cv2.__version__[0]) < 3:writer = cv2.VideoWriter(tmp_video_file.name, cv2.cv.CV_FOURCC(*'mp4v'), 25, (800, 800), True)else:writer = cv2.VideoWriter(tmp_video_file.name, cv2.VideoWriter_fourcc(*'mp4v'), 25, (800, 800), True)if os.path.exists(uv_template_fname) and os.path.exists(texture_img_fname):uv_template = Mesh(filename=uv_template_fname)vt, ft = uv_template.vt, uv_template.fttex_img = cv2.imread(texture_img_fname)[:, :, ::-1]else:vt, ft = None, Nonetex_img = Nonenum_frames = sequence_vertices.shape[0]center = np.mean(sequence_vertices[0], axis=0)for i_frame in range(num_frames):render_mesh = Mesh(sequence_vertices[i_frame], template.f)if vt is not None and ft is not None:render_mesh.vt, render_mesh.ft = vt, ftimg = render_mesh_helper(render_mesh, center)writer.write(img)writer.release()video_fname = os.path.join(out_path, 'video.mp4')cmd = ('ffmpeg' + ' -i {0} -i {1} -pix_fmt yuv420p -qscale 0 {2} -y'.format(audio_fname, tmp_video_file.name, video_fname)).split()call(cmd)def output_sequence_meshes(sequence_vertices, template, out_path, uv_template_fname='', texture_img_fname=''):mesh_out_path = os.path.join(out_path, 'meshes')if not os.path.exists(mesh_out_path):os.makedirs(mesh_out_path)if os.path.exists(uv_template_fname):uv_template = Mesh(filename=uv_template_fname)vt, ft = uv_template.vt, uv_template.ftelse:vt, ft = None, Nonenum_frames = sequence_vertices.shape[0]for i_frame in range(num_frames):out_fname = os.path.join(mesh_out_path, '%05d.obj' % i_frame)out_mesh = Mesh(sequence_vertices[i_frame], template.f)if vt is not None and ft is not None:out_mesh.vt, out_mesh.ft = vt, ftif os.path.exists(texture_img_fname):out_mesh.set_texture_image(texture_img_fname)out_mesh.write_obj(out_fname)def main():parser = argparse.ArgumentParser(description='SelfTalk: A Self-Supervised Commutative Training Diagram to Comprehend 3D Talking Faces')parser.add_argument("--model_name", type=str, default="BIWI", help='vocaset or BIWI')parser.add_argument("--dataset", type=str, default="BIWI", help='vocaset or BIWI')parser.add_argument("--fps", type=float, default=25, help='frame rate - 30 for vocaset; 25 for BIWI')parser.add_argument("--feature_dim", type=int, default=1024, help='512 for vocaset; 1024 for BIWI')parser.add_argument("--period", type=int, default=25, help='period in PPE - 30 for vocaset; 25 for BIWI')parser.add_argument("--vertice_dim", type=int, default=23370 * 3,help='number of vertices - 5023*3 for vocaset; 23370*3 for BIWI')parser.add_argument("--device", type=str, default="cuda", help='cuda or cpu')parser.add_argument("--train_subjects", type=str, default="F2 F3 F4 M3 M4 M5")parser.add_argument("--test_subjects", type=str, default="F1 F5 F6 F7 F8 M1 M2 M6")parser.add_argument("--output_path", type=str, default="demo/output", help='path of the rendered video sequence')parser.add_argument("--wav_path", type=str, default="demo/wav/test.wav", help='path of the input audio signal')parser.add_argument("--result_path", type=str, default="demo/result", help='path of the predictions')parser.add_argument("--subject", type=str, default="F3",help='select a subject from test_subjects or train_subjects')parser.add_argument("--background_black", type=bool, default=True, help='whether to use black background')parser.add_argument("--template_path", type=str, default="templates.pkl", help='path of the personalized templates')parser.add_argument("--render_template_path", type=str, default="templates",help='path of the mesh in BIWI/FLAME topology')args = parser.parse_args()test_model(args)# fa_path = args.result_path + "/" + args.wav_path.split("/")[-1].split(".")[0] + ".npy"# temp = "./BIWI/BIWI.ply"# out_path = fa_path.split(".")[0]# audio_fname = args.wav_path## template = Mesh(filename=temp)# predicted_vertices_out = np.load(fa_path).reshape(-1, 23370, 3)# print("Start rendering...")# output_sequence_meshes(predicted_vertices_out, template, out_path)## render_sequence_meshes(audio_fname, predicted_vertices_out, template, out_path, uv_template_fname='',#                        texture_img_fname='')if __name__ == "__main__":main()

diffspeaker

https://github.com/theEricMa/DiffSpeaker

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/3120.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NSQ消息队列---总结篇

架构 概念 nsqlookup&#xff1a;存储了nsqd的元数据和服务信息(endpoind),向消费者提供服务发现功能, 向nsqadmin提供数据查询功能。 nsqd: 是接收、队列和传送消息到客户端的守护进程。 nsqadmin&#xff1a;简单的管理界面,展示了topic, channel以及channel上的消费者,也…

【漏洞复现】号卡极团管理系统 index.php SQL注入漏洞

0x01 产品简介 号卡极团管理系统是一款专为号卡行业打造的管理系统&#xff0c;它具备一系列强大的功能&#xff0c;能够满足号卡行业推广人员在业务运营中的各类需求。 0x02 漏洞概述 号卡极团管理系统存在SQL注入漏洞&#xff0c;未授权的攻击者可以通过该漏洞获取数据库敏…

Playwright

一&#xff1a;选择器 个人理解&#xff0c;其实跟css选择器一样 1、某个类的第一个 .your-class-name:first-of-type2、某个类的第一个子元素 :first-child

数据库关系模式分解 - 无损连接和保持函数依赖性

文章目录 1 概述1.1 关系模式分解的好坏标准 2 无损连接验证算法 1 概述 1.1 关系模式分解的好坏标准 书上的算法太抽象了&#xff0c;咱不好理解&#xff0c;以下举例说明。一个关系可以有很多种分解方法&#xff0c;如何判断分解的好与坏呢&#xff1f; ① 查询时的连接操作…

类的六个构造函数相关干货

构造函数 特点 1.名字与类名相同 2.无返回值 3.对象实例化的时候编译器自动调用这个函数 4.构造函数可以重载&#xff08;无参构造函数&#xff0c;拷贝构造等&#xff09; 5.如果类中没有显式定义构造函数&#xff08;深拷贝&#xff09;&#xff0c;则编译器会自动生成一个…

CSS基础——2.CSS选择器

1. 通用选择器 通用选择器用星号*表示,它不匹配某个特定的 HTML 元素,而是匹配 HTML 文档中的每个元素,开发中通常使用通用选择器来清除 HTML元素中默认的内外边距 通用选择器格式:*{} * { margin: 0 auto; padding: 0; } 2. 标签选择器 根据标签的名字 进行选择匹…

抖音阳哥:选品师项目究竟能不能算蓝海项目?

在当今这个信息爆炸的时代&#xff0c;短视频平台如抖音已经成为了人们获取信息、娱乐休闲的重要渠道。抖音上涌现出许多具有影响力的网红&#xff0c;他们不仅分享自己的生活点滴&#xff0c;还常常推荐一些创业项目或商业模式。其中&#xff0c;阳哥分享的选品师项目引起了广…

STM32H750片外QSPI下载算法文件(stldr)生成

STM32H750片外QSPI下载算法文件&#xff08;stldr&#xff09;生成 &#x1f33f;相关篇《STM32H750片外QSPI启动配置简要》&#x1f4cc;参考实现资料&#xff1a; https://github.com/lchnu/STM32H750XBH_ARTPIQSPI_W25Q64JV https://gitee.com/wangchief/H750_W25QXX ✨利…

WPF之Label

Label在wpf中表示控件的文本标签&#xff0c;并提供访问密钥支持。 常用属性: 属性 HorizontalContentAlignment文本水平内容排列VerticalContentAlignment垂直内容排列width宽height高fontsize字体大小fontfamily字体样式fontwidth字体粗细 具体写法 <Label Width"20…

JavaScript常用的Hook脚本

页面最早加载代码Hook时机 在source里 用dom事件断点的script断点然后刷新网页&#xff0c;就会断在第一个js标签&#xff0c;这时候就可以注入代码进行hook 监听 键盘 与 鼠标 事件 // 判断是否按下F12 onkeydown事件 /* 提示&#xff1a; 与 onkeydown 事件相关联的事件触…

风格迁移adaIN 和iT的adaLN

文章目录 BN、LN、IN、GN的区别![](https://img-blog.csdnimg.cn/direct/d38c005616f145cba2aa1c4c2e046be0.png)图像风格迁移adaINDiT adaLN BN、LN、IN、GN的区别 BatchNorm&#xff1a;batch方向做归一化&#xff0c;算NxHxW的均值&#xff0c;对小batchsize效果不好&#x…

「Kafka」Kafka基础知识入门介绍(三)

「Kafka」Kafka基础知识入门介绍&#xff08;三&#xff09; 一、消息主题1. 创建主题 二、生产数据1. 命令行模式2. Java代码模式 三、消费数据1. 命令行模式2. Java代码模式 「Kafka」Kafka理论知识解读&#xff08;一&#xff09; 「Kafka」Kafka安装和启动&#xff08;二&a…

【kotlin】利用by关键字更加方便地实现装饰器模式

关于kotlin中的by关键字的用法&#xff0c;kotlin官方文档属性委托这一节讲得很清楚。 简单来说就是这样的&#xff0c;假设存在一个接口Component如下&#xff1a; interface Component {fun method1(): IntArrayfun method2(a: Int)fun method3(a: Int, str: String) }那么对…

React-性能优化的手段

​&#x1f308;个人主页&#xff1a;前端青山 &#x1f525;系列专栏&#xff1a;React篇 &#x1f516;人终将被年少不可得之物困其一生 依旧青山,本期给大家带来React篇专栏内容:React-性能优化的手段 目录 React 性能优化的手段有哪些&#xff1f; 一、是什么 二、如何做…

【无标题】cocos与外部laya或者web交互

一.电脑&#xff1a; 电脑网页&#xff1a;cocos --->laya this.webview._impl._iframe.contentWindow.postMessage("cocosToLaya", "*");//laya //这里是浏览器环境下&#xff0c; 接收web传过来的消息//cocos window.addEventListener(&q…

【汇编语言】流程转移和子程序

【汇编语言】流程转移和子程序 文章目录 【汇编语言】流程转移和子程序前言一、“转移”综述二、操作符offset三、jmp指令jmp指令——无条件转移jmp指令&#xff1a;依据位移进行转移两种段内转移远转移&#xff1a;jmp far ptr 标号转移地址在寄存器中的jmp指令转移地址在内存…

Vue3种常用插槽的使用

插槽总结 &#xff1a; 插槽的作用&#xff1a;让父组件可以向子组件指定位置插入html结构&#xff0c;也是一种组件间通信的方式&#xff0c;适用于 父组件 > 子组件 。分类&#xff1a;默认插槽、具名插槽、作用域插槽 1、默认插槽 父组件中&#xff1a; <Category>…

鸿蒙HarmonyOS应用 - ArkUI组件

ArkUI组件 基础组件 Image 声明Image组件并设置图片源 网络权限&#xff1a;ohos.permission.INTERNET Image(scr: string | PixelMap | Resource)// 1. string&#xff1a;用于加载网络图片&#xff0c;需要申请网络权限 Image("https://xxx.png")// 2. PixelMap…

一线实战,一次底层超融合故障导致的Oracle异常恢复

背景概述 某客户数据由于底层超融合故障导致数据库产生有大量的坏块&#xff0c;最终导致数据库宕机&#xff0c;通过数据抢救&#xff0c;恢复了全部的数据。下面是详细的故障分析诊断过程&#xff0c;以及详细的解决方案描述&#xff1a; 故障现象 数据库宕机之后&#xff0c…

粤嵌—2024/4/24—删除有序数组中的重复项 ||

代码实现&#xff1a; 方法一&#xff1a;双指针 int removeDuplicates(int *nums, int numsSize) {int l 0, r 0;while (r < numsSize) {if (r > 1 && nums[r] nums[l - 1] && nums[r] nums[l - 2]) {r;} else {nums[l] nums[r];l;r;}}return l; }…