又双叒叕种草了新家装风格?AI帮你家居换装

种草,家装,风格,ai,你家,换装 · 浏览次数 : 38

小编点评

1. Gradio可视化部署Gradio应用启动后可在下方页面上传图片根据提示生成图像,您也可以分享public url在手机端,PC端进行访问生成图像。 2. 参数说明 img_path:输入图像路径 prompt:提示词(建议填写) n_prompt: 负面提示(可选)num_inference_steps:采样步数,一般15-30,值越大越精细,耗时越长 3. result = [mlsd_img, gen_img] return result block = gr.Blocks().queue()with block: with gr.Row(): gr.Markdown("## Control Stable Diffusion with MLSD\n") with gr.Row(): with gr.Column(): input_image = gr.Image(source='upload', type=\"numpy\") prompt = gr.Textbox(label=\"描述\") run_button = gr.Button(label="Run\") with gr.Accordion("高级选项", open=False): num_inference_steps = gr.Slider(label="图像生成步数", minimum=1, maximum=100, value=20, step=1) value_threshold = gr.Slider(label="Hough value threshold (MLSD)\", minimum=0.01, maximum=2.0, value=0.1, step=0.01) distance_threshold = gr.Slider(label="Hough distance threshold (MLSD)\", minimum=0.01, maximum=20.0, value=0.1, step=0.01) n_prompt = gr.Textbox(label="否定提示", value='lowres, extra digit, fewer digits, cropped, worst quality, low quality') detect_resolution = gr.Slider(label="Hough Resolution", minimum=128, maximum=1024, value=512, step=1) image_resolution = gr.Slider(label="Image Resolution", minimum=256, maximum=768, value=512, step=64) with gr.Column(): result_gallery = gr.Gallery(label='Output', show_label=False, elem_id=\"gallery\").style(columns=2, height='auto') ips = [input_image, prompt, num_inference_steps, value_threshold, distance_threshold, n_prompt, detect_resolution, image_resolution] run_button.click(fn=mlsd, inputs=ips, outputs=[result_gallery])block.launch(share=True)参考文献Paper: 《Adding Conditional Control to Text-to-Image Diffusion Model》Paper: 《Towards Light-weight and Real-time Line Segment Detection》Model:sd-controlnet-mlsd, stable-diffusion-v1-5案例代码地址:AI Gallery - AI建筑风格修改: ControlNet-MLSD 免费体验  点击关注,第一时间了解华为云新鲜技术~

正文

摘要:又双叒叕种草了家装新风格?想要尝试却又怕踩雷?如果能够轻松Get量身定制的家装风格图,那该多好啊。现在,这一切都成为了可能!

本文分享自华为云社区《又双叒叕种草了新家装风格?AI帮你家居换装!》,作者:Emma_Liu。

Control Stable Diffusion with M-LSD 修改建筑及家居装修风格

你是否曾经想过,如果能够轻松地看到自己家居的不同风格,该有多好呢?现在,这一切都变得可能了!

让你的眼睛仔细观察这些图片,你会发现它们展现了不同的风格和氛围,从现代简约到古典优雅,从温馨舒适到时尚前卫,应有尽有。但是,你知道吗?这些图片都是由AI生成的!

它们看起来非常逼真,仿佛是真实的照片一样。这就是人工智能的奇妙之处,让我们可以轻松地预览不同的家居风格,不必实际进行装修。让我们一起来感受AI技术的魅力吧!

装修风格参考

现代极简风卧室

图一是原图,我要基于图一的装修布局重新装修一下,图二是M-LSD线段检测器的输出图像,图三是加入prompt为:现代极简风卧室生成图像,图四再补充一些prompt:现代极简风卧室,床是黄色的,墙是浅咖色。不得不说效果真不错!

卫生间

图一这种简单布局的卫生间我很是喜欢,康康其他风格的侘寂风卫生间 - 图二、三

客厅

换装ing——奶油风客厅——无名(不填prompt也可以生成不错的图片,很多惊喜诶)

别墅

我已经在幻想住上大别墅了✨看看别墅的效果怎么样

浪漫的海边别墅、新中式别墅

我想尝试用建筑设计图来看看能不能生成…哇,绝绝子——简约风,现代风

其他建筑

建模图变——欧式建筑

厂房变办公楼、大型超市、别墅(这样式的别墅)

好神奇,它是怎么做到的呢,来看看模型的介绍。

0.模型介绍

建筑的稳定扩散 | ControlNet模型-MLSD,随意创建建筑物、房间内部或外部以及独特的场景

ControlNet 最早是在L.Zhang等人的论文《Adding Conditional Control to Text-to-Image Diffusion Model》中提出的,目的是提高预训练的扩散模型的性能。它引入了一个框架,支持在扩散模型 (如 Stable Diffusion ) 上附加额外的多种空间语义条件来控制生成过程。为稳定扩散带来了前所未有的控制水平。

Mobile LSD (M-LSD): 《Towards Light-weight and Real-time Line Segment Detection》是用于资源受限环境的实时和轻量级线段检测器,M-LSD利用了极其高效的LSD体系结构和新的训练方案,包括SoL增强和几何学习方案。模型可以在GPU、CPU甚至移动设备上实时运行。

图1 GPU上M-LSD和现有LSD方法的比较

图2 移动设备上的推理速度和内存使用情况.

案例以分享至AI Gallery - AI建筑风格修改: ControlNet-MLSD,一起来运行代码,实现你的新装吧。

1.装包

!pip install transformers==4.29.0
!pip install diffusers==0.16.1
!pip install accelerate==0.17.1
!pip install gradio==3.32.0
!pip install translate==3.6.1

2.下载模型

使用mlsd, sd-controlnet-mlsd, stable-diffusion-v1-5预训练模型,为方便大家使用,已转存到华为云OBS中。

import os
import moxing as mox
pretrained_models = ['mlsd', 'sd-controlnet-mlsd', 'stable-diffusion-v1-5']
for pretrained_model in pretrained_models:
 model_dir = os.path.join(os.getcwd(), pretrained_model)
 if not os.path.exists(model_dir):
 mox.file.copy_parallel(f'obs://modelarts-labs-bj4-v2/case_zoo/ControlNet/ControlNet_models/{pretrained_model}', model_dir)
 if os.path.exists(model_dir):
 print(f'{pretrained_model} download success')
 else:
 raise Exception(f'{pretrained_model} download Failed')
 else:
 print(f"{pretrained_model} already exists!")

3.加载模型

import torch
from PIL import Image
from mlsd import MLSDdetector
from translate import Translator
from diffusers.utils import load_image
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
mlsd = MLSDdetector()
controlnet = ControlNetModel.from_pretrained("sd-controlnet-mlsd", torch_dtype=torch.float16)
pipe = StableDiffusionControlNetPipeline.from_pretrained("stable-diffusion-v1-5", controlnet=controlnet, safety_checker=None, torch_dtype=torch.float16)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()

4.生成图像

首先,传入的图片会通过mlsd detector输出黑白线条图,然后基于此mlsd图像,通过controlnet和stable diffusion生成图像。

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
ori = Image.open("1920245540.jpg")
mlsd = MLSDdetector()
mlsd_img = mlsd(ori, thr_v=0.1, thr_d=0.1, detect_resolution=512, image_resolution=512, return_pil=True)
trans = Translator(from_lang="ZH",to_lang="EN-US")
prompt = "现代极简风卧室,床是黄色的,墙是浅咖色"
en_prompt = trans.translate(prompt)
gen_img = pipe(en_prompt, mlsd_img, num_inference_steps=20).images[0]
fig = plt.figure(figsize=(25, 10))
ax1 = fig.add_subplot(1, 3, 1)
plt.title('Orignial image', fontsize=16)
ax1.axis('off')
ax1.imshow(ori)
ax2 = fig.add_subplot(1, 3, 2)
plt.title('ML Detector image', fontsize=16)
ax2.axis('off')
ax2.imshow(mlsd_img)
ax3 = fig.add_subplot(1, 3, 3)
plt.title('Generate image', fontsize=16)
ax3.axis('off')
ax3.imshow(gen_img)
plt.show()

5.Gradio可视化部署

Gradio应用启动后可在下方页面上传图片根据提示生成图像,您也可以分享public url在手机端,PC端进行访问生成图像。

参数说明

img_path:输入图像路径

prompt:提示词(建议填写)

n_prompt: 负面提示(可选)

num_inference_steps: 采样步数,一般15-30,值越大越精细,耗时越长

image_resolution: 对输入的图片进行最长边等比resize

detect_resolution:Hough Resolution,检测分辨率,值越小-线条越粗糙
value_threshold: Hough value threshold (MLSD),值越大-检测线条越多,越详细

distance_threshold: Hough distance threshold (MLSD),值越大-距离越远,检测到的线条越少

对比一下参数value_threshold,distance_threshold,当value_threshold值变大时,如图二所示,检测到的线段越少,获取到的信息也就越少,对控制生成后的图像来说,会缺失掉很多的细节;当distance_threshold值变大时,如图三所示,越远处的物体,提取到的线段越少,图像会更专注于前面的部分。这对于来调整生成的图像是一个很好的参考。

thr_v=0.1, thr_d=0.1

thr_v=0.5, thr_d=0.1

thr_v=0.1, thr_d=20

import gradio as gr
def mlsd(img, prompt, num_inference_steps, thr_v, thr_d, n_prompt, detect_resolution, image_resolution):
    trans = Translator(from_lang="ZH",to_lang="EN-US")
    prompt = trans.translate(prompt)
 n_prompt = trans.translate(n_prompt)
 mlsd = MLSDdetector()
 mlsd_img = mlsd(img, thr_v=0.1, thr_d=0.1, detect_resolution=512, image_resolution=512, return_pil=True)
 gen_img = pipe(prompt, mlsd_img, num_inference_steps=20, negative_prompt=n_prompt).images[0]
    result = [mlsd_img, gen_img]
 return result 
block = gr.Blocks().queue()
with block:
 with gr.Row():
 gr.Markdown("##  Control Stable Diffusion with MLSD")
 with gr.Row():
 with gr.Column():
 input_image = gr.Image(source='upload', type="numpy")
            prompt = gr.Textbox(label="描述")
 run_button = gr.Button(label="Run")
 with gr.Accordion("高级选项", open=False):
 num_inference_steps = gr.Slider(label="图像生成步数", minimum=1, maximum=100, value=20, step=1)
 value_threshold = gr.Slider(label="Hough value threshold (MLSD)", minimum=0.01, maximum=2.0, value=0.1, step=0.01)
 distance_threshold = gr.Slider(label="Hough distance threshold (MLSD)", minimum=0.01, maximum=20.0, value=0.1, step=0.01)
 n_prompt = gr.Textbox(label="否定提示",
                                      value='lowres, extra digit, fewer digits, cropped, worst quality, low quality')
 detect_resolution = gr.Slider(label="Hough Resolution", minimum=128, maximum=1024, value=512, step=1)
 image_resolution = gr.Slider(label="Image Resolution", minimum=256, maximum=768, value=512, step=64)
 with gr.Column():
 result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery").style(columns=2, height='auto')
 ips = [input_image, prompt, num_inference_steps, value_threshold, distance_threshold, n_prompt, detect_resolution, image_resolution]
 run_button.click(fn=mlsd, inputs=ips, outputs=[result_gallery])
block.launch(share=True)

参考文献

  1. Paper: 《Adding Conditional Control to Text-to-Image Diffusion Model》
  2. Paper: 《Towards Light-weight and Real-time Line Segment Detection》
  3. Model:sd-controlnet-mlsdstable-diffusion-v1-5
  4. 案例代码地址:AI Gallery - AI建筑风格修改: ControlNet-MLSD 免费体验

 

 

点击关注,第一时间了解华为云新鲜技术~

与又双叒叕种草了新家装风格?AI帮你家居换装相似的内容:

又双叒叕种草了新家装风格?AI帮你家居换装

摘要:又双叒叕种草了家装新风格?想要尝试却又怕踩雷?如果能够轻松Get量身定制的家装风格图,那该多好啊。现在,这一切都成为了可能! 本文分享自华为云社区《又双叒叕种草了新家装风格?AI帮你家居换装!》,作者:Emma_Liu。 Control Stable Diffusion with M-LSD

京东云开发者|ElasticSearch降本增效常见的方法

Elasticsearch在db_ranking 的排名又(双叒叕)上升了一位,如图1-1所示;由此可见es在存储领域已经蔚然成风且占有非常重要的地位。随着Elasticsearch越来越受欢迎,企业花费在ES建设上的成本自然也不少。那如何减少ES的成本呢?今天我们就特地来聊聊ES降本增效的常见方法。

物理学又不存在了?ChatGPT:室温超导是物理学的一个梦想

大家好,我是小彭。 就在前天,一组微信聊天记录突然开始在各大群中流传: 随后,这一新闻直接引爆各大社交媒体,物理学又双叒叕不存在了吗? 到底是什么重磅消息呢? 原来在美国物理学会的三月会议上,美国纽约罗切斯特大学的 Ranga Dias 团队发布了一项研究成果 —— 他们发现了能够在室温环境下实现超

【OpenVINO™】在C#中使用 OpenVINO™ 部署 YOLOv10 模型实现目标

最近YOLO家族又添新成员:YOLOv10,YOLOv10 提出了一种一致的双任务方法,用于无nms训练的YOLOs,它同时带来了具有竞争力的性能和较低的推理延迟。此外,还介绍了整体效率-精度驱动的模型设计策略,从效率和精度两个角度对YOLOs的各个组成部分进行了全面优化,大大降低了计算开销,增强了...

又跳槽!3年java经验offer收割机的面试心得

中厂->阿里->字节,成都->杭州->成都 系列文章目录和关于我 0.前言 笔者在不足两年经验的时候从成都一家金融科技中厂跳槽到杭州阿里淘天集团,又于今年5月份从杭州淘天跳槽到成都字节。自认为自己在面试这方面有一点心得,处于记录和分享的目的便有了此文,此文纯主观,也许对3年社招的同学有所帮助。 本文

又跳槽!3年Java经验收割成都大厂的面试心得(干货满满&文末有福利)

中厂->阿里->字节,成都->杭州->成都 系列文章目录和关于我 0.前言 笔者在不足两年经验的时候从成都一家金融科技中厂跳槽到杭州阿里淘天集团,又于今年5月份从杭州淘天跳槽到成都字节。自认为自己在面试这方面有一点心得,处于记录和分享的目的便有了此文,此文纯主观,也许对3年社招的同学有所帮助。 本文

聊聊GLM-4-9B开源模型的微调loss计算

概述 Github官方地址:GLM-4 网上已经有很多关于微调的文章,介绍各种方式下的使用,这里不会赘述。我个人比较关心的是微调时的loss计算逻辑,这点在很多的文章都不会有相关的描述,因为大多数人都是关心如何使用之类的应用层,而不是其具体的底层逻辑,当然咱也说不清太底层的计算。 可了解其它loss

MLOps 学习之旅「GitHub 热点速览」

又是 AI 神仙打架的一周,上周 OpenAI 发布了最新的 GPT-4o 模型,而谷歌也紧跟着开源了 Gemma 2 模型。随着 AI 大模型不断地变强,各大科技巨头正利用它们重塑自家的产品,这也让大模型算法工程师变得炙手可热,相关岗位需求正旺。 对于普通程序员来说,想要转型成为大模型算法专家,可

又重新搭了个个人博客

哈喽大家好,我是咸鱼。 前段时间看到一个学弟写了篇用 Hexo 搭建博客的教程,心中沉寂已久的激情重新被点燃起来。(以前搞过一个个人网站,但是因为种种原因最后不了了之) 于是花了一天时间参考教程搭了个博客网站,我的博客网址是:https://xxxsalted.github.io/ 下面是相关教程。

论结构化、系统性的学习

在大的工作环境以及普遍的生活压力下。对以后充满了迷茫。 尤其是30多岁以后的人生。 中年的危机与焦虑如何避免? 职场的规划与路线怎么制定? 生活的压力与焦灼如何解决? 家庭的压力..... 其实主要还是职场的规划。人,一般来说,对于百分之九十九以上的人,都是要工作的。那么在国内这样的中年危机普遍存在