BiSeNet脸部解析,并且可以进行可视化脸部哦
该内容介绍了基于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]登录后复制
游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。
同类文章
逼AI当山顶洞人!Claude防话痨插件爆火,网友:受够了AI废话
新智元报道编辑:元宇【新智元导读】一个让AI像原始人一样说话的插件,在HN上一夜爆火,冲破2w星。它的核心只是一条简单粗暴的prompt:删掉冠词、客套和一切废话,号称能省下75%的输出token。
季度利润翻 8 倍,最赚钱的「卖铲人」财报背后,内存涨价狂潮如何收场?
AI 时代最赚钱的公司,可能从来不是做 AI 的那个。作者|张勇毅编辑|靖宇淘金热里最稳赚的人,从来不是淘金的,是卖铲子的。这句老话在 2026 年的科技行业又应验了一次。只不过这次卖铲子的不是英伟
Claude Code Harness+龙虾科研团来了!金字塔分层架构+多智能体
Claw AI Lab团队量子位 | 公众号 QbitAI你还在一个人做科研吗?科研最难的,从来不是问题本身,而是一个想法从文献到实验再到写作,只能靠自己一点点往前推。一个人方向偏了没人提醒,遇到歧
让离线强化学习从「局部描摹」变「全局布局」丨ICLR'26
面对复杂连续任务的长程规划,现有的生成式离线强化学习方法往往会暴露短板。它们生成的轨迹经常陷入局部合理但全局偏航的窘境。它们太关注眼前的每一步,却忘了最终的目的地。针对这一痛点,厦门大学和香港科技大
美国犹他州启动新试点项目:AI为患者开具精神类药物处方
IT之家 4 月 5 日消息,据外媒 PC Mag 当地时间 4 月 4 日报道,美国医疗机构 Legion Health 在犹他州获得监管批准,启动一项试点项目,允许 AI 系统为患者开具精神类药
- 日榜
- 周榜
- 月榜
相关攻略
2015-03-10 11:25
2015-03-10 11:05
2021-08-04 13:30
2015-03-10 11:22
2015-03-10 12:39
2022-05-16 18:57
2025-05-23 13:43
2025-05-23 14:01
热门教程
- 游戏攻略
- 安卓教程
- 苹果教程
- 电脑教程
热门话题




