Python DPED机器学习之实现照片美化
作者:剑客阿良_ALiang 发布时间:2023-11-25 01:50:24
前言
最近发现了一个可以把照片美化的项目,自己玩了玩,挺有意思的,分享一下。
Github地址:DPED项目地址
下面来看看项目怎么玩?先放一些项目给出的效果图。可以看出照片更明亮好看了。
环境部署
项目结构
下面是项目的原始结构:
tensorflow安装
按照项目的说明,我们需要安装tensorflow以及一些必要的库。
如果安装gpu版本的tensorflow需要对照一下
tensorflow官方对照地址:TensorFlow官方CUDA版本对照
我的cuda是11.1的版本,按照tensorflow后还是缺少部分dll,如果有相同问题的,可以用我提供的资源包 提取码:TUAN。
缺少哪个dll,直接复制到你的NVIDIA GPU Computing Toolkit目录对应cuda的bin目录下。
按照自己的版本来,我的tensorflow命令如下:
pip install tensorflow-gpu==2.4.2 -i https://pypi.douban.com/simple
pip install tf-nightly -i https://pypi.douban.com/simple
其他依赖安装
Pillow, scipy, numpy, imageio安装
pip install Pillow -i https://pypi.douban.com/simple
pip install scipy -i https://pypi.douban.com/simple
pip install numpy -i https://pypi.douban.com/simple
pip install imageio -i https://pypi.douban.com/simple
VGG-19下载
因为模型文件太大,github的项目中无法上传这么大的文件,作者让我们自己下。
我把DPED的资源包统一打包了,也可以从我的云盘下载, 放到项目的vgg_pretrained目录下。下图是资源包的目录
资源包地址 提取码:TUAN。
项目运行
项目需要的环境我们都装好了,我们跳过训练的部分,测试model的方法官方给出了命令。
准备图片素材
我准备了几张图,就不全展示了,展示其中的一张。
按照项目的要求,需要放在对应的目录下。
测试效果
执行命令
python test_model.py model=iphone_orig test_subset=full resolution=orig use_gpu=true
执行过程
(tensorflow) C:\Users\yi\PycharmProjects\DPED>python test_model.py model=iphone_orig test_subset=full resolution=orig use_gpu=true
2021-11-27 23:42:57.922965: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
2021-11-27 23:43:00.532645: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to
use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-11-27 23:43:00.535946: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library nvcuda.dll
2021-11-27 23:43:00.559967: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.759GHz coreCount: 15 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2021-11-27 23:43:00.560121: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
2021-11-27 23:43:00.577706: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublas64_11.dll
2021-11-27 23:43:00.577812: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublasLt64_11.dll
2021-11-27 23:43:00.588560: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cufft64_10.dll
2021-11-27 23:43:00.591950: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library curand64_10.dll
2021-11-27 23:43:00.614412: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusolver64_10.dll
2021-11-27 23:43:00.624267: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusparse64_11.dll
2021-11-27 23:43:00.626309: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudnn64_8.dll
2021-11-27 23:43:00.626481: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-11-27 23:43:01.112598: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-27 23:43:01.112756: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0
2021-11-27 23:43:01.113098: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N
2021-11-27 23:43:01.113463: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6720 MB
memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
2021-11-27 23:43:01.114296: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
WARNING:tensorflow:From C:\Users\yi\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\compat\v2_compat.py:96: disable_resource_variables (from tensorflow.p
ython.ops.variable_scope) is deprecated and will be removed in a future version.
Instructions for updating:
non-resource variables are not supported in the long term
2021-11-27 23:43:01.478512: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-11-27 23:43:01.479339: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.759GHz coreCount: 15 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2021-11-27 23:43:01.479747: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
2021-11-27 23:43:01.480519: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublas64_11.dll
2021-11-27 23:43:01.480927: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublasLt64_11.dll
2021-11-27 23:43:01.481155: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cufft64_10.dll
2021-11-27 23:43:01.481568: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library curand64_10.dll
2021-11-27 23:43:01.481823: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusolver64_10.dll
2021-11-27 23:43:01.482188: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusparse64_11.dll
2021-11-27 23:43:01.482416: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudnn64_8.dll
2021-11-27 23:43:01.482638: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-11-27 23:43:01.482959: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 1070 computeCapability: 6.1
coreClock: 1.759GHz coreCount: 15 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2021-11-27 23:43:01.483077: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
2021-11-27 23:43:01.483254: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublas64_11.dll
2021-11-27 23:43:01.483426: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublasLt64_11.dll
2021-11-27 23:43:01.483638: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cufft64_10.dll
2021-11-27 23:43:01.483817: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library curand64_10.dll
2021-11-27 23:43:01.484052: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusolver64_10.dll
2021-11-27 23:43:01.484250: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusparse64_11.dll
2021-11-27 23:43:01.484433: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudnn64_8.dll
2021-11-27 23:43:01.484662: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-11-27 23:43:01.484841: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-11-27 23:43:01.484984: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0
2021-11-27 23:43:01.485152: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N
2021-11-27 23:43:01.485395: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6720 MB
memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
2021-11-27 23:43:01.485565: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-11-27 23:43:01.518135: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)
Testing original iphone model, processing image 3.jpg
2021-11-27 23:43:01.863678: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudnn64_8.dll
2021-11-27 23:43:02.517063: I tensorflow/core/platform/windows/subprocess.cc:308] SubProcess ended with return code: 0
2021-11-27 23:43:02.632790: I tensorflow/core/platform/windows/subprocess.cc:308] SubProcess ended with return code: 0
2021-11-27 23:43:03.210892: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublas64_11.dll
2021-11-27 23:43:03.509052: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublasLt64_11.dll
Lossy conversion from float32 to uint8. Range [-0.06221151351928711, 1.0705437660217285]. Convert image to uint8 prior to saving to suppress this warning.
Lossy conversion from float32 to uint8. Range [-0.06221151351928711, 1.0705437660217285]. Convert image to uint8 prior to saving to suppress this warning.
Testing original iphone model, processing image 4.jpg
Lossy conversion from float32 to uint8. Range [-0.05176264047622681, 1.0500218868255615]. Convert image to uint8 prior to saving to suppress this warning.
Lossy conversion from float32 to uint8. Range [-0.05176264047622681, 1.0500218868255615]. Convert image to uint8 prior to saving to suppress this warning.
Testing original iphone model, processing image 5.jpg
Lossy conversion from float32 to uint8. Range [-0.03344374895095825, 1.0417983531951904]. Convert image to uint8 prior to saving to suppress this warning.
Lossy conversion from float32 to uint8. Range [-0.03344374895095825, 1.0417983531951904]. Convert image to uint8 prior to saving to suppress this warning.
Testing original iphone model, processing image 6.jpg
Lossy conversion from float32 to uint8. Range [-0.03614246845245361, 1.063475251197815]. Convert image to uint8 prior to saving to suppress this warning.
Lossy conversion from float32 to uint8. Range [-0.03614246845245361, 1.063475251197815]. Convert image to uint8 prior to saving to suppress this warning.
项目会生成前后对比图以及最终结果图。
前后效果图,左边为原始图,右边为对比图。
结果图如下
可以明显的看出,新图已经明亮了许多,色彩也变的比较鲜明了,效果还是很不错的。
来源:https://blog.csdn.net/zhiweihongyan1/article/details/121579505


猜你喜欢
- 不同的色彩空间中对图片的色彩体现有很大不同#色彩空间的相互转换:最常见的是HSV与RGB,YUV与RGB的相互转换#常见色彩空间有:#RGB
- 在某些情况下,程序需要在定义函数时为一个或多个形参指定默认值,这样在调用函数时就可以省略为该形参传入参数值,而是直接使用该形参的默认值。为形
- 上个周末去书店时碰巧看到了AS3 CookeBook,我记得在apollo的alpha版快出来的时候,7yue就推荐过这个小册子,只不过我已
- 环境系统:Centos7.2 服务:Nginx1:下载PHP7.0.2的安装包解压,编译,安装: $ cd /usr/s
- 目录话不多说,直接贴所有代码运行效果需要用到的两张图片总结话不多说,直接贴所有代码import randomimport sysimport
- 区别: 1、主键,Oracle不可以实现自增,mysql可以实现自增。 oracle新建序列,SEQ_USER_Id.nextval 2、索
- 网上有不少生成缩略图的ASP组件。若你的虚拟空间不支持注册新组件,可能会感觉自己的网站失色不少。心晴不才,结合网上资源写了个无组件生成缩略图
- 最近用到了docx生成word文档,docx本身用起来很方便,自带的各种样式都很好看,美中不足的就是对中文的支持不够好。在未设置中文字体的时
- 这篇文章中我们将通过对HelloWorld的message进行操作,介绍一下如何使用flask进行Restful的CRUD。概要信息事前准备
- 共存问题我之前一直使用的是SQL2012版本的数据库管理工具,为了与时俱进,我也尝试更新一下版本,当然SQLServer管理工具是可以多版本
- 1. 判断表单元素是否存在(一) if("periodPerMonth" in document.theForm) {
- MySQL多表join时报错如下:[Err]1267 – Illegal mix of collations(utf8_general_ci
- SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它
- 企业最有价值的资产通常是其数据库中的客户或产品信息。因此,在这些企业中,数据库管理的一个重要部分就是保护这些数据免受外部攻击,及修复软/硬件
- 在python中进行两个整数相除的时候,在默认情况下都是只能够得到整数的值,而在需要进行对除所得的结果进行精确地求值时,想在运算后即得到浮点
- Pandas DataFrame 取一行数据会得到Series的方法如题,想要取如下dataframe的一行数据,以为得到的还是datafr
- var obj = document.getElementByIdx_x(”testSelect”); //定位idvar index =
- prototype 是在 IE 4 及其以后版本引入的一个针对于某一类的对象的方法,而且特殊的地方便在于:它是一个给类的对象添加方法的方法!
- 首先,运行 Python 解释器,导入 re 模块并编译一个 RE:#!python Python 2.2.2 (#1, Feb 10 20
- 前言本文讲诉了Vuex的安装、搭建。以及Actions、Mutations、State、Getters的使用,为什么使用mapState、m