Python机器学习之实现模糊照片人脸恢复清晰
作者:剑客阿良_ALiang 时间:2021-02-13 09:56:53
前言
最近看到一个有意思的机器学习项目——GFPGAN,他可以将模糊的人脸照片恢复清晰。开源项目的Github地址:https://github.com/TencentARC/GFPGAN
我们看一看作者给出的对比图。
最右侧的就是GFPGAN的效果,看一下最左层的输入图片,可以发现GFPGAN将图片恢复的非常清晰。这个效果非常惊艳。
按照以前的惯例,我还是先把这个项目安装使用一下,看看能不能对代码重新封装,变成可以工程化的项目。
环境安装
我们先看一下项目README给的提示。
首先需要的python版本是>=3.7的,所以我用Anaconda创建了一个python3.9的虚拟环境。Pytorch的安装直接从官网获取命令安装一个最新版本即可。
因为还有一些基础依赖的安装,照着安装一下就行,其实setup.py是已经在项目中的,如下图。
由于模型比较大,所以作者没有放在github上,给了下面的下载提示。该模型是作者提供已经训练好的模型。
如果下载很慢的话,可以从我的网盘下载。
链接提取码:TUAN
作者还提供了基础模型可供自行训练。
验证模型
下面我准备了一些图,挑了一些比较典型的图片,有黑白的、彩色的以及马赛克的,想看看是不是都可以实现清晰化处理。
准备的图片如下:
按照README提供的指令
python inference_gfpgan.py --upscale 2 --test_path inputs/newImages --save_root results
看一下执行结果:
(pytorch39) C:\Users\yi\PycharmProjects\GFPGAN>python inference_gfpgan.py --upscale 2 --test_path inputs/newImages --save_root results
C:\Users\yi\PycharmProjects\GFPGAN\inference_gfpgan.py:45: UserWarning: The unoptimized RealESRGAN is very slow on CPU. We do not use it. If you really want to use it, p
lease modify the corresponding codes.
warnings.warn('The unoptimized RealESRGAN is very slow on CPU. We do not use it. '
Processing 331.jpg ...
E:\ProgramData\Anaconda3\envs\pytorch39\lib\site-packages\torch\nn\functional.py:3679: UserWarning: The default behavior for interpolate/upsample with float scale_factor
changed in 1.6.0 to align with other frameworks/libraries, and now uses scale_factor directly, instead of relying on the computed output size. If you wish to restore th
e old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details.
warnings.warn(
Processing 333.jpg ...
Processing 334.jpg ...
Processing 335.jpg ...
Results are in the [results] folder.
(pytorch39) C:\Users\yi\PycharmProjects\GFPGAN>
按照默认参数,会在results结果文件夹中生成4个目录分别为前后对比图、原检测出来的脸部图、处理后的脸部图、处理后的最终图。
我们看看效果
可以看出两点:
1、马赛克不能消除,有一张全马赛克的图片,直接无法修复。
2、常规的模糊照片修复的是真的很清晰呀。
来源:https://blog.csdn.net/zhiweihongyan1/article/details/122025741
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python matplotlib实现折线图的绘制
![](https://img.aspxhome.com/file/2023/1/93621_0s.png)
教你用压缩技术给SQL Server备份文件瘦身
解决Python字典查找报Keyerror的问题
![](https://img.aspxhome.com/file/2023/0/100800_0s.png)
python matplotlib imshow热图坐标替换/映射实例
![](https://img.aspxhome.com/file/2023/6/92086_0s.jpg)
JS实现仿Windows经典风格的选项卡Tab切换代码
![](https://img.aspxhome.com/file/2023/2/56172_0s.png)
PythonPC客户端自动化实现原理(pywinauto)
![](https://img.aspxhome.com/file/2023/3/95673_0s.png)
css中浮动思考与小结
python字符串常用方法
Python 如何写入Excel格式和颜色
![](https://img.aspxhome.com/file/2023/7/86687_0s.jpg)
asp.net aspnetpager分页统计时与实际不符的解决办法
Python实现以主程序的形式执行模块
![](https://img.aspxhome.com/file/2023/8/86578_0s.png)
一小时学会TensorFlow2之大幅提高模型准确率
![](https://img.aspxhome.com/file/2023/0/109370_0s.png)
python3对拉勾数据进行可视化分析的方法详解
![](https://img.aspxhome.com/file/2023/1/79761_0s.png)
使用Python的Django框架结合jQuery实现AJAX购物车页面
![](https://img.aspxhome.com/file/2023/3/99033_0s.jpg)
Python中Django框架利用url来控制登录的方法
Python中的list.sort()方法和函数sorted(list)
Python学习之包与模块详解
![](https://img.aspxhome.com/file/2023/7/66867_0s.jpg)
Phantomjs抓取渲染JS后的网页(Python代码)
Python爬虫天气预报实例详解(小白入门)
![](https://img.aspxhome.com/file/2023/5/77565_0s.jpg)