当前位置: 首页 > news >正文

铁岭新区旅行社电话网站优化及推广

铁岭新区旅行社电话,网站优化及推广,网站开发详细设计模板,node.js网站开发框架老照片常常因为当时的技术限制而只有黑白版本。然而现代的 AI 技术,如 DeOldify,可以让这些照片重现色彩。 本教程将详细介绍如何使用 DeOldify 来给老照片上色。 文章目录 准备工作执行代码图片上色视频上色 总结 准备工作 这里用 git clone 命令克隆…

老照片常常因为当时的技术限制而只有黑白版本。然而现代的 AI 技术,如 DeOldify,可以让这些照片重现色彩。

本教程将详细介绍如何使用 DeOldify 来给老照片上色。

在这里插入图片描述

文章目录

  • 准备工作
  • 执行代码
    • 图片上色
    • 视频上色
  • 总结

准备工作

这里用 git clone 命令克隆了 DeOldify 的 GitHub 仓库,然后安装了所需的依赖库。

git clone https://github.com/jantic/DeOldify.git

常规的需要创建和激活虚拟环境,并安装相关依赖包。

conda create --name python38 python=3.8
conda activate python38 pip install -r requirements.txt

然后会可能会提示

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
onnxruntime 1.14.1 requires flatbuffers, which is not installed.
onnxruntime 1.14.1 requires sympy, which is not installed.

这里还需要安装flatbufferssympy

pip install flatbuffers sympy

安装完成之后你的文件目录是这样的,然后将虚拟环境目录移动到当前目录下。

在这里插入图片描述
接下来需要下载模型文件。

下载地址在 https://huggingface.co/spensercai/DeOldify/tree/main 。

在这里插入图片描述
将下载好的文件移动到models文件夹下即可。

在这里插入图片描述

执行代码

图片上色

  • 导入依赖库:包括DeOldify库、matplotlib.pyplot、torch等。这些库用于图像处理、可视化以及深度学习任务。
  • 设置设备:使用DeOldify库的device.set()函数将计算设备设置为GPU0。这意味着后续的图像处理任务将在GPU上进行加速处理,如果有多个GPU可用,可以根据需要进行选择。
  • 设置图像风格:使用plt.style.use('dark_background')设置了Matplotlib图形的风格,使其采用黑色背景。
  • 禁用警告:使用warnings.filterwarnings()函数来忽略特定类型的警告,这里忽略了UserWarning类型的警告消息。
  • 创建着色器:使用get_image_colorizer(artistic=True)创建了一个图像着色器对象,其中artistic=True表示使用艺术化的着色方式。
  • 设置参数
    • render_factor定义了渲染因子,影响着色的细节程度。
    • source_urlsource_path分别指定了输入图像的URL和本地路径。
    • result_path用于存储着色后的图像的路径,初始设置为None。
  • 图像着色
    • 代码根据source_url是否为空,选择不同的方式来进行图像着色。如果source_url不为空,将从URL加载图像并进行着色,否则从本地路径加载图像进行着色。着色后的结果将存储在result_path中。
# env setup.py/py
# -*- coding: UTF-8 -*-
'''
@Project :setup.py 
@File    :porcess_img.py
@IDE     :PyCharm 
@Author  :Mr数据杨
@Date    :2023/10/11 12:43 
'''from deoldify import device
from deoldify.device_id import DeviceId# choices:  CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)from deoldify.visualize import *plt.style.use('dark_background')
torch.backends.cudnn.benchmark = True
import warningswarnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")colorizer = get_image_colorizer(artistic=True)render_factor = 35
source_url = None
source_path = 'data/img.jpg'
result_path = Noneif source_url is not None:result_path = colorizer.plot_transformed_image_from_url(url=source_url, path=source_path, render_factor=render_factor, compare=True)
else:result_path = colorizer.plot_transformed_image(path=source_path, render_factor=render_factor, compare=True)show_image_in_notebook(result_path)

最后会在result_images文件夹下生成结果图片。

在这里插入图片描述

视频上色

执行代码之前需要在项目目录下创建video文件夹,并在文件夹下创建source文件夹。

这里执行的代码不再解释,理论上和上面图片的差不多,就是处理的时候先将视频转帧然后依次上色最后再合并在一起,保存成视频。

# env setup.py/py
# -*- coding: UTF-8 -*-
'''
@Project :setup.py 
@File    :porcess_img.py
@IDE     :PyCharm 
@Author  :Mr数据杨
@Date    :2023/10/11 12:43 
'''from deoldify import device
from deoldify.device_id import DeviceId# choices:  CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)from deoldify.visualize import *plt.style.use('dark_background')
import warningswarnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")colorizer = get_video_colorizer()render_factor = 21# source_url='https://twitter.com/silentmoviegifs/status/1116751583386034176'
source_url = None
file_name = 'video'
file_name_ext = file_name + '.mp4'
result_path = Noneif source_url is not None:result_path = colorizer.colorize_from_url(source_url, file_name_ext, render_factor=render_factor)
else:result_path = colorizer.colorize_from_file_name(file_name_ext, render_factor=render_factor)show_video_in_notebook(result_path)

总结

DeOldify 不仅能够给老照片上色,还能用于其他许多有趣的应用,如老电影修复等。希望这个简单的教程能帮助读者更容易地掌握这一技术。

如果想使用Stable Diffusion进行操作的话可以参考 Stable diffusion 用DeOldify给黑白照片、视频上色。

http://www.rdtb.cn/news/13851.html

相关文章:

  • 奥德贵阳网络推广公司seo精准培训课程
  • 惠州百度推广排名电商seo优化是什么
  • 深圳网站建设与网站制作如何找客户资源
  • 专业做网站优化搜索引擎优化的简称
  • 护士做兼职的网站推广软文范文
  • 系统开发过程中的第一个文档什么叫做seo
  • 珠海企业集团网站建设wordpress官网入口
  • 网站浏览器测试引擎网站
  • 泰安营销型手机网站建设网络营销具有哪些特点
  • 成都酒店设计公司淘宝seo什么意思
  • pc端和移动端的网站区别是什么意思企业管理培训课程费用
  • 冬季什么行业做网站比较多小程序设计
  • 拼客多网站多少钱可以做上海全网推广
  • 建一个网站首先要怎么做网络营销环境的分析主要是
  • soho没有注册公司 能建一个外贸网站吗推广平台排名前十名
  • wordpress 广告管理重庆seo网站系统
  • 手机网站的文本排版是怎么做的seo推广如何做
  • 腾讯做的购物网站优惠活动推广文案
  • 福州移动网站建设b2b电子商务网站
  • 网上青年团智慧团建登录虞城seo代理地址
  • 深圳专业建站平台上海企业网站推广
  • 广东企业网站建设长沙百度快速排名
  • 医院网站建设的目的西安seo报价
  • 怎么样网站速度快产品营销
  • 网站建设书外贸平台有哪些比较好
  • 南宁美丽南方官方网站建设意见新网站推广最直接的方法
  • 佛山新网站建设如何恶意点击软件有哪些
  • 广州市天河区网站设计公司上海服务政策调整
  • 宝鸡网站制作公司优化营商环境 提升服务效能
  • 2021半夜好用的网站成都seo的方法