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

目录
  • 前言
  • 环境部署
    • 项目结构
    • tensorflow安装
    • 其他依赖安装
    • VGG-19下载
  • 项目运行
    • 准备图片素材
    • 测试效果

前言

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

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.

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

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

结果图如下

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

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

(0)

相关推荐

  • Python实现对照片中的人脸进行颜值预测

    一.所需工具 **Python版本:**3.5.4(64bit) 二.相关模块 opencv_python模块 sklearn模块 numpy模块 dlib模块 一些Python自带的模块. 三.环境搭建 (1)安装相应版本的Python并添加到环境变量中: (2)pip安装相关模块中提到的模块. 例如: 若pip安装报错,请自行到: http://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载pip安装报错模块的whl文件,并使用: pip install whl

  • Python实现老照片修复之上色小技巧

    导语 "黑白变彩色,就是这么简单" 老照片上色,是一门功夫,费时费力. 老照片上色,也是一门艺术,还原历史. 提起老照片上色,小编第一个想到了的就是一位名叫Marina Amaral的艺术家,她将历史上很多著名的老照片,都用后期处理的方式填补上了颜色. 逼真.写实,看不出丝毫的漏洞,你对她的作品有多钦佩,也就意味着这项技艺有多复杂. 所以,你想学习老照片上色吗?也想把父母的照片,或者儿时的黑白照变成彩色的吗? 那木木子给你的建议的是:别费劲了,因为,这项工作,以后交给AI去完成就可以了

  • Python 人工智能老照片修复算法学习

    目录 前言 项目环境搭建 conda虚拟环境创建 激活环境 Pytorch安装 Synchronized-BatchNorm-PyTorch repository安装 Global目录Synchronized-BatchNorm-PyTorch项目部署 检测预处理模型下载 下载脸部增强模型文件 下载依赖 完整部署后项目结构 项目使用 验证一下 总结 前言 老旧或者破损的照片如何修复呢?本文主要分享一个博主使用后非常不错的照片恢复开源项目:Bringing-Old-Photos-Back-to-L

  • python 通过exifread读取照片信息

    通过第三方库exifread读取照片信息. exifread官网:https://pypi.org/project/ExifRead/ 一.安装exifread pip install exifread 二.读取照片信息,以及根据经纬度通过百度地图API获取位置 import exifread import json import urllib.request # Open image file for reading (binary mode) f = open('001.jpg', 'rb'

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

    目录 前言 环境部署 项目结构 tensorflow安装 其他依赖安装 VGG-19下载 项目运行 准备图片素材 测试效果 前言 最近发现了一个可以把照片美化的项目,自己玩了玩,挺有意思的,分享一下. Github地址:DPED项目地址 下面来看看项目怎么玩?先放一些项目给出的效果图.可以看出照片更明亮好看了. 环境部署 项目结构 下面是项目的原始结构: tensorflow安装 按照项目的说明,我们需要安装tensorflow以及一些必要的库. 如果安装gpu版本的tensorflow需要对照

  • Python实现将蓝底照片转化为白底照片功能完整实例

    本文实例讲述了Python实现将蓝底照片转化为白底照片功能.分享给大家供大家参考,具体如下: import cv2 import numpy as np img=cv2.imread('yay.jpg') #原始图片 #缩放 rows,cols,channels = img.shape img=cv2.resize(img,None,fx=0.5,fy=0.5) rows,cols,channels = img.shape cv2.imshow('img',img) #转换hsv hsv=cv2

  • Python 使用 prettytable 库打印表格美化输出功能

    pip install prettytable 每次添加一行 from prettytable import PrettyTable # 默认表头:Field 1.Field 2... # 添加表头 table = PrettyTable(["URL", "参数", "值"]) # add_row 添加一行数据 table.add_row(["http://aaa.com", "raskv", "

  • Python如何使用字符打印照片

    这篇文章主要介绍了Python如何使用字符打印照片,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1. 前言 第一次在学校机房里见到计算机,还是上古时期.计算机型号大概是LASER-310吧,有点记不清了.那会儿,显示器还是单色的,只能显示文本,每行最多显示80个字符.想看图片,印象中只能用针式打印机打印在两侧穿孔的宽行打印纸上,每个像素用一个字符表示,不同的字符代表不同的灰度,就像下图这个样子.有没有感觉到浓郁古风呢?其实,随便一张照片,十几

  • python基于机器学习预测股票交易信号

    引言 近年来,随着技术的发展,机器学习和深度学习在金融资产量化研究上的应用越来越广泛和深入.目前,大量数据科学家在Kaggle网站上发布了使用机器学习/深度学习模型对股票.期货.比特币等金融资产做预测和分析的文章.从金融投资的角度看,这些文章可能缺乏一定的理论基础支撑(或交易思维),大都是基于数据挖掘.但从量化的角度看,有很多值得我们学习参考的地方,尤其是Pyhton的深入应用.数据可视化和机器学习模型的评估与优化等.下面借鉴Kaggle上的一篇文章<Building an Asset Trad

  • Python实现机器学习算法的分类

    Python算法的分类 对葡萄酒数据集进行测试,由于数据集是多分类且数据的样本分布不平衡,所以直接对数据测试,效果不理想.所以使用SMOTE过采样对数据进行处理,对数据去重,去空,处理后数据达到均衡,然后进行测试,与之前测试相比,准确率提升较高. 例如:决策树: Smote处理前: Smote处理后: from typing import Counter from matplotlib import colors, markers import numpy as np import pandas

  • 基于python使MUI登录页面的美化

    目录 1.前言 2.问题描述 3.解决方案 (1)背景美化 (2)输入框美化 4.结语 本文转自微信公众号:"算法与编程之美" 1.前言 之前的文章Python用HBuilder创建交流社区APP我们已经在HBuilder上创建的APP ,现HBuilder中已经有了登录页面的相关的html文件,但是按照html已有的页面来看,它缺少外观的美化.现在大多数软件需要外观的加成,本篇文章主要讲的是MUI登录页面的美化. 2.问题描述 在将主要的内容构造之后,如今思考如何实现将页面进行美化是

  • Python OpenCV机器学习之图像识别详解

    目录 背景 一.人脸识别 二.车牌识别 三.DNN图像分类 背景 OpenCV中也提供了一些机器学习的方法,例如DNN:本篇将简单介绍一下机器学习的一些应用,对比传统和前沿的算法,能从其中看出优劣: 一.人脸识别 主要有以下两种实现方法: 1.哈尔(Haar)级联法:专门解决人脸识别而推出的传统算法: 实现步骤: 创建Haar级联器: 导入图片并将其灰度化: 调用函数接口进行人脸识别: 函数原型: detectMultiScale(img,scaleFactor,minNeighbors) sc

  • Python+matplotlib实现折线图的美化

    目录 1. 导入包 2. 获得数据 3. 对数据做一些预处理 4. 画图 4.1 优化:添加点 4.2 优化:设置刻度 4.3 优化:设置填充 4.4 优化:设置填充颜色 5. 把功能打包成函数 6.测试函数 最后 大家好,今天分享一个非常有趣的 Python 教程,如何美化一个 matplotlib 折线图,喜欢记得收藏.关注.点赞. 1. 导入包 import pandas as pd import matplotlib.pyplot as plt import matplotlib.tic

  • Python实现调用摄像头拍摄照片

    目录 步骤 代码 实现效果 步骤 用opencv打开摄像头并拍照 保存照片到本地 获取邮箱(如qq邮箱)的授权码,方法可自行百度 将照片以附件的形式发送到指定邮箱 删除本地照片 代码 import os # 删除图片文件 import cv2 # 调用摄像头拍摄照片 from smtplib import SMTP_SSL # SSL加密的 传输协议 from email.mime.text import MIMEText # 构建邮件文本 from email.mime.multipart i

随机推荐