欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python DPED机器学习之实现照片美化

程序员文章站 2022-03-19 09:49:39
目录前言环境部署项目结构tensorflow安装其他依赖安装vgg-19下载项目运行准备图片素材测试效果前言最近发现了一个可以把照片美化的项目,自己玩了玩,挺有意思的,分享一下。github地址:dp...

前言

最近发现了一个可以把照片美化的项目,自己玩了玩,挺有意思的,分享一下。

github地址:dped项目地址

下面来看看项目怎么玩?先放一些项目给出的效果图。可以看出照片更明亮好看了。

Python DPED机器学习之实现照片美化

环境部署

项目结构

下面是项目的原始结构:

Python DPED机器学习之实现照片美化

tensorflow安装

按照项目的说明,我们需要安装tensorflow以及一些必要的库。

Python DPED机器学习之实现照片美化

如果安装gpu版本的tensorflow需要对照一下

tensorflow官方对照地址:tensorflow官方cuda版本对照

我的cuda是11.1的版本,按照tensorflow后还是缺少部分dll,如果有相同问题的,可以用我提供的资源包  提取码:tuan。

缺少哪个dll,直接复制到你的nvidia gpu computing toolkit目录对应cuda的bin目录下。

Python DPED机器学习之实现照片美化

按照自己的版本来,我的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的项目中无法上传这么大的文件,作者让我们自己下。

Python DPED机器学习之实现照片美化

我把dped的资源包统一打包了,也可以从我的云盘下载, 放到项目的vgg_pretrained目录下。下图是资源包的目录

Python DPED机器学习之实现照片美化

资源包地址  提取码:tuan。

项目运行

项目需要的环境我们都装好了,我们跳过训练的部分,测试model的方法官方给出了命令。

Python DPED机器学习之实现照片美化

准备图片素材

我准备了几张图,就不全展示了,展示其中的一张。

Python DPED机器学习之实现照片美化

按照项目的要求,需要放在对应的目录下。

Python DPED机器学习之实现照片美化

测试效果

执行命令

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.

项目会生成前后对比图以及最终结果图。

前后效果图,左边为原始图,右边为对比图。

Python DPED机器学习之实现照片美化

结果图如下

Python DPED机器学习之实现照片美化

可以明显的看出,新图已经明亮了许多,色彩也变的比较鲜明了,效果还是很不错的。 

到此这篇关于python dped机器学习之实现照片美化的文章就介绍到这了,更多相关照片美化内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!