BiSeNet脸部解析,并且可以进行可视化脸部哦
该内容介绍了基于BiSeNet的脸部解析项目。项目使用简单,需输入正方形图片(会resize为523x512),适用于妆容迁移等任务。提供了原PyTorch项目地址,说明权重由Py
该内容介绍了基于BiSeNet的脸部解析项目。项目使用简单,需输入正方形图片(会resize为523x512),适用于妆容迁移等任务。提供了原PyTorch项目地址,说明权重由PyTorch转Paddle的情况。介绍了输入输出路径,重点提及需RGB三通道图片。还给出了相关代码,包括解析可视化、图片判断、模型评估等函数,以及运行结果示例。

BiSeNet脸部解析
本项目使用极其简单,就是你需要脸部解析的图片尽量是一个正方形,因为数据预处理会先把图片resize成为523x512大小。
另外本项目适合为妆容迁移等脸部任务提供脸部各个部位的辅助信息,作为一个轮子是很好的。
原pytorch项目地址:https://github.com/zllrunning/face-parsing.PyTorch
权重pytorch 转paddle,感谢张牙舞爪帮我转的权重,我也不知道我为啥转错了,有点尴尬。
input:
把需要人脸解析的图片放在myphoto文件夹下 举个例子./myphoto/1.webp
output:
生成的人脸解析图片会放在test_res文件夹下
./test_res/1.webp 这张图片就是SSAT妆容迁移需要输入的人脸解析的信息了
./test_res/1color.webp 这张图片就是为了方便直观看是否人脸解析正确罢了
重点!!!!!!!!!!!!
当把需要解析的人脸照片放在./myphoto文件夹下后就请傻瓜式允许下方代码就行!只要你的图片是RGB三通道的就行,RGBA四通道需要自己调试
In [5]from paddle_model import BiSeNetimport paddleimport osimport os.path as ospimport numpy as npfrom PIL import Imageimport paddle.vision.transforms as transformsimport cv2def vis_parsing_maps(im, parsing_anno, stride, save_im=False, save_path='vis_results/parsing_map_on_im.webp'): # Colors for all 20 parts part_colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 0, 85], [255, 0, 170], [0, 255, 0], [85, 255, 0], [170, 255, 0], [0, 255, 85], [0, 255, 170], [0, 0, 255], [85, 0, 255], [170, 0, 255], [0, 85, 255], [0, 170, 255], [255, 255, 0], [255, 255, 85], [255, 255, 170], [255, 0, 255], [255, 85, 255], [255, 170, 255], [0, 255, 255], [85, 255, 255], [170, 255, 255]] im = np.array(im) vis_im = im.copy().astype(np.uint8) vis_parsing_anno = parsing_anno.copy().astype(np.uint8) vis_parsing_anno = cv2.resize(vis_parsing_anno, None, fx=stride, fy=stride, interpolation=cv2.INTER_NEAREST) vis_parsing_anno_color = np.zeros((vis_parsing_anno.shape[0], vis_parsing_anno.shape[1], 3)) + 255 num_of_class = np.max(vis_parsing_anno) for pi in range(1, num_of_class + 1): index = np.where(vis_parsing_anno == pi) vis_parsing_anno_color[index[0], index[1], :] = part_colors[pi] vis_parsing_anno_color = vis_parsing_anno_color.astype(np.uint8) # print(vis_parsing_anno_color.shape, vis_im.shape) vis_im = cv2.addWeighted(cv2.cvtColor(vis_im, cv2.COLOR_RGB2BGR), 0.4, vis_parsing_anno_color, 0.6, 0) # Save result or not if save_im: cv2.imwrite(save_path[:-4] +'.webp', vis_parsing_anno) cv2.imwrite(save_path[:-4]+"color.webp", vis_im, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) # return vis_imIMG_EXTENSIONS = [ '.webp', '.JPG', '.webp', '.JPEG', '.webp', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',]def is_image_file(filename): return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)def evaluate(respth='./test_res', dspth='./data', save_pth='paddleweight1.pdparams'): ''' respth 测试图片模型输出的文件夹路径位置 dspth 模型读取图片的文件夹路径位置 save_pth 加载模型权重路径 ''' if not os.path.exists(respth): os.makedirs(respth) n_classes = 19 net = BiSeNet(n_classes=n_classes) net.set_state_dict(paddle.load(save_pth)) net.eval() to_tensor = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)), ]) with paddle.no_grad(): for image_path in os.listdir(dspth): if is_image_file(image_path): img = Image.open(osp.join(dspth, image_path)) image = img.resize((512, 512), Image.BILINEAR) # image = image[:,:,:3] img = to_tensor(image) img = paddle.unsqueeze(img, 0) # img = img.cuda() out = net(img)[0] parsing = out.squeeze(0).numpy().argmax(0) # print(parsing) print(np.unique(parsing)) vis_parsing_maps(image, parsing, stride=1, save_im=True, save_path=osp.join(respth, image_path))if __name__ == "__main__": evaluate(dspth='./myphoto')登录后复制
[ 0 1 2 3 4 5 10 12 13 14 16 17][ 0 1 2 3 4 5 10 12 13 14 17][ 0 1 2 3 7 10 12 13 14 16 17][ 0 1 2 3 4 5 10 12 13 14 16 17 18]登录后复制
你是一名 AI 行业编辑,请围绕下面这条热点输出一份资讯解读:
热点:BiSeNet脸部解析,并且可以进行可视化脸部哦要求:
1. 先用一句话解释这条热点在讲什么
2. 再总结它为什么重要
3. 说明会影响哪些 AI 产品或内容方向
4. 最后给出 3 个适合资讯站使用的标题
游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。
相关热点苹果起诉OpenAI窃取商业机密,要求销毁资料并重设计AI硬件。SK海力士在美融资265亿美元,创外国公司纪录。传腾讯正洽谈成为Manus最大股东。SpaceX拟2026年底前启动太空移民,特斯拉机器人将首批进驻。
Meta发布旗舰大模型MuseSpark1 1,强化多智能体协同与上下文压缩,支持百万Token窗口。编程基准测试72 2分,领先上代超50分。自研芯片MTIA400性能提升4倍,9月量产。
NovaAI拒答源于违规关键词、违法前提或风险评分阈值触发。应对方法包括:用教学场景包裹意图、拆解为可验证子任务、引入权威约束条件。通过“角色+目标+约束”三段式改写提示词,将提问锚定合规框架,可显著降低拒答概率。
JetBrains于2025年7月7日推出面向软件团队的AI统一管理平台,整合碎片化AI工具,提供共享上下文、可复用智能体工作流及组织级治理与成本管控,采用按需积分制商业模式,并推出团队自动化、JetBrainsContext、Central及CentralCLI等新功能。
- 日榜
- 周榜
- 月榜
热点快看



