您的位置:  首页 > 技术杂谈 > 正文

设计师解放双手之作!3秒生成风景园林效果图,AIGC赋能景观设计

2023-05-26 12:00 https://my.oschina.net/u/4067628/blog/9093692 飞桨PaddlePaddle 次阅读 条评论

项目简介

在过去几十年,风景园林经历了从“刀耕火种”的完全手绘设计时代到当下比较流行的参数化设计时代,过去的每一轮技术革新都让风景园林作品的表现形式产生了巨大的改变。随着计算机图像技术的发展,我们有更多的建模和渲染软件辅助提升图纸表现效果,但表现效果提升的背后伴随的是越来越巨大的人力资源投入,一张美观的效果图需要经过建模、渲染、图像编辑等多个软件繁杂反复操作才能生产出来,加班熬夜重复性地绘图已成为行业常态。简而言之,过去计算机图像技术的发展并没有让设计师的工作更加轻松,反而成为了一把沉重的“枷锁”。

在人工智能生成内容技术(Artificial Intelligence Generated Content,AIGC)井喷式发展的背景下,风景园林行业正经历着智能化变革。如何借助人工智能技术进一步提高设计效率、实现快速多样化设计,对满足用户多样和变化的需求、改变行业投入高和人效低现状有重要意义。在飞桨 AI Studio 和 PPDiffusers 的支持下,华南农业大学 SCUrban Lab 团队尝试在风景园林的场景下对 Stable Diffusion 模型进行调教优化。本文将分享当前探索成果,除此之外,我们也公开了一个“城市公园”场景下的 LoRA 模型权重,欢迎大家测试反馈。

环境安装

PPDiffusers 介绍

PPDiffusers 是一款支持多种模态(如文本图像跨模态、图像、语音)扩散模型(Diffusion Model)训练和推理的国产化工具箱。依托于飞桨框架和 PaddleNLP 自然语言处理开发库,PPDiffusers 提供了超过50种 SOTA 扩散模型 Pipelines 集合,支持文图生成(Text-to-Image Generation)、文本引导的图像编辑(Text-Guided Image Inpainting)、文本引导的图像变换(Image-to-Image Text-Guided Generation)、超分(Super Resolution)在内的10+任务,覆盖文本图像跨模态、图像、音频等多种模态。

PPDiffusers 安装

如果您是刚接触 Python 编程的新用户,我们推荐使用以下便捷的 pip 的安装方式:

pip install --upgrade ppdiffusers -f https://www.[paddlepaddle](https://www.oschina.net/action/visit/ad?id=1185 "paddlepaddle").org.cn/whl/[paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle")nlp.html --user

由于最近 AIGC 发展速度比较快,PPDiffusers 代码仓库更新也比较频繁,如果您有一定的 Python 基础,我们推荐克隆 PaddleNLP 仓库源代码进行手动安装。

git clone https://github.com/[PaddlePaddle](https://www.oschina.net/action/visit/ad?id=1185 "PaddlePaddle")/[Paddle](https://www.oschina.net/action/visit/ad?id=1185 "Paddle")NLP
cd [Paddle](https://www.oschina.net/action/visit/ad?id=1185 "Paddle")NLP/ppdiffusers
python setup.py install

模型介绍

本项目主要用到的是模型是 Stable Diffusion V1.5 版本和 ControlNet。为了使生成图像的表现效果更加接近现实场景,我们也使用了基于 Stable Diffusion 的 Realistic Vision V2.0 模型。针对风景园林公共景观设计领域,我们实验室利用自有的城市公园图像数据库训练了 CityParkLoraV1 权重模型并开源,同时我们还使用了针对地产景观的 Fair-faced-concrete-V1 微调权重,所有开源地址的模型附在文章最后,在此也对所有开源贡献者表示衷心感谢。

效果图生成应用

基于文字生成

与设计大类专业类似,在景观设计院的工作过程中,我们也几乎每天都会收到来自甲方各式各样的文字需求,比如我们经常调侃的“五彩斑斓的黑”“尊贵大气而低调的风格”等等。对于初出茅庐的设计师,表面上笑脸嘻嘻迎合甲方,但内心早已万马奔腾。所以我们第一个场景实验就是基于文字的景观效果图像生成,下面我们就演示一个湿地公园景观生成场景。

推理代码:

import [paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle")
from ppdiffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler

[paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle").seed(12321)
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe.unet.load_attn_procs("Xiejiehang/CityParkLoraV1", from_hf_hub=True)
image = pipe("A wetland park in the suburbs of the city, high resolution,hyper quality,full details, natural, communtiy park, outdoor, grassland", num_inference_steps=50).images[0]

效果展示:

效果图

基于现实场景生成

对现有的景观效果进行升级改造也是风景园林的主要工作之一。在景观改造之前,我们会到现场进行场地的勘察调研,拍摄记录场地现状的照片,然后经过一系列设计工作后,将设计成果 P 图到场地现状图上。一个经验丰富的设计师,平均 P 一张普通设计效果图的时间在1个小时左右。如果项目规模比较大,我们还需要在 3D 建模软件中对场地进行1:1还原,这样一整个设计周期下来需要3-5天甚至更长时间。因此我们第二个场景实验就是针对现实场景的图像生成,利用 ControlNet 保留原图像的特征,然后利用 Stable Diffusion 对图像进行重绘,以下是一个真实的“美丽乡村”建设项目的实验效果:

推理代码:

import os
import cv2
import random
import [paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle")

from annotator.canny import CannyDetector
from annotator.util import HWC3, resize_image
from [paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle")nlp.trainer import set_seed as seed_everything
from ppdiffusers import ControlNetModel, StableDiffusionControlNetPipeline, StableDiffusionPipeline

apply_canny = CannyDetector()
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny")

pipe = StableDiffusionControlNetPipeline.from_pretrained(
"SG161222/Realistic_Vision_V2.0", controlnet=controlnet, from_hf_hub=True, from_diffusers=True
)

def process(
input_image,
prompt,
a_prompt,
n_prompt,
num_samples,
image_resolution,
ddim_steps,
guess_mode,
strength,
scale,
seed,
eta,
low_threshold,
high_threshold,
):

with [paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle").no_grad():
img = resize_image(HWC3(input_image), image_resolution)
H, W, C = img.shape
detected_map = apply_canny(img, low_threshold, high_threshold)

detected_map = HWC3(detected_map)
control = [paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle").to_tensor(detected_map.copy(), dtype=[paddle](https://www.oschina.net/action/visit/ad?id=1185 "paddle").float32) / 255.0
control = control.unsqueeze(0).transpose([0, 3, 1, 2])
control_scales = (
[strength * (0.825 ** float(12 - i)) for i in range(13)] if guess_mode else ([strength] * 13)
) 
if seed == -1:
seed = random.randint(0, 65535)
seed_everything(seed)
results = []
for _ in range(num_samples):
img = pipe(
prompt + ", " + a_prompt,
negative_prompt=n_prompt,
image=control,
num_inference_steps=ddim_steps,
height=H,
width=W,
eta=eta,
controlnet_conditioning_scale=control_scales,
guidance_scale=scale,
).images[0]
results.append(img)

return [255 - detected_map] + results

inputImage = cv2.imread('test_img/village.jpg')
results = process(input_image=inputImage,
prompt="beautiful village,shrubs and flowers around the building,countryside,country road,blue sky,modern house,white wall,glass window, wooden roof,high resolution,hyper quality,full details",
a_prompt="",
n_prompt="",
num_samples=1,
image_resolution=512,
ddim_steps=20,
guess_mode=False,
strength=1.0,
scale=9.0,
seed=123321123,
eta=0.0,
low_threshold=20,
high_threshold=200,
)

# 保存图像
savePath = "./outputImg/"
if not os.path.exists(savePath):
os.makedirs(savePath)
for i in range(1, len(results)):
results[i].save(os.path.join(savePath, "{}.jpg".format(i)))

效果展示:

原图

效果图

在这个场景的实验中,我们在 V100 32G 的显卡环境下测试每张图的生成时间大约是10秒左右,与人工绘图动辄1个小时到1周不等的时间相比,这极大地提升了景观设计的效率,真正解放了生产力!

基于手绘线稿生成

手绘是风景园林设计师的日常表达方式之一。在景观设计过程中,我们会将脑海里的设计灵感和推敲过程用手绘的方式快速表达出来,然后交给建模师和美术设计进行计算机辅助绘图。我们的第三个场景实验,就是充分利用 ControlNet Canny 边缘检测的特性,将手绘线稿渲染成真实场景的效果图。

推理代码:

pipe.apply_lora("/home/aistudio/data/data214847/Fair-faced-concrete-V1.safetensors")

inputImage = cv2.imread('test_img/draw.jpg')
results = process(input_image=inputImage,
prompt="garden in residential area,large grassland,adults and children walking,people sit under umbrellas chatting,glass window,blue sky,high resolution,hyper quality,full details,modern architecture,outside,facade",
a_prompt="",
n_prompt="water,lake",
num_samples=1,
image_resolution=512,
ddim_steps=20,
guess_mode=False,
strength=1.0,
scale=9.0,
seed=12332,
eta=0.0,
low_threshold=20,
high_threshold=200,
)

<!---->

savePath = "./outputImg/"
if not os.path.exists(savePath):
os.makedirs(savePath)
for i in range(1, len(results)):
results[i].save(os.path.join(savePath, "{}.jpg".format(i)))

效果展示:

原图

效果图

在线体验

为了让开发者快速体验以上的内容,目前我们已经将基于现实场景和手绘线稿生成效果图的能力上线到 AI Studio 应用中心,开发者可以打开以下链接并尝试上传自己的景观手绘或照片,感受快速高效输出渲染效果图的能力!

  • AI Studio地址

<https://aistudio.baidu.com/aistudio/projectdetail/6235423

结语

以上是我们实验室基于 Stable Diffusion 模型针对风景园林场景下的一些实验探索和验证,展现了人工智能在风景园林行业应用的巨大潜力。经过我们多轮反复的实验和工程设计调优,验证了 Stable Diffusion 等生成模型可以被有效应用于风景园林景观设计领域,并且能大幅节约设计师的工作时间,具备提高全行业领域生产力的能力。

欢迎更多有兴趣的开发者与我们一起攻克设计控制、设计结果有效性验证等难题,拓展 AIGC 相关技术的研究及应用,构建起真正的风景园林循证设计框架。

  • AI Studio 项目链接

https://aistudio.baidu.com/aistudio/projectdetail/6088322

  • 版权声明

本文中使用的原图和设计稿由华南农业大学 SCUrban Lab 提供,未经授权许可禁止一切带有商业目的性的转载和使用。

  • SCUrban Lab 地址

https://www.scurbanlab.com/

参考文献

[1] https://github.com/PaddlePaddle/PaddleNLP/tree/develop/ppdiffusers

[2] https://huggingface.co/Xiejiehang/CityParkLoraV1/

[3] https://huggingface.co/lllyasviel/sd-controlnet-canny

[4] https://huggingface.co/SG161222/Realistic_Vision_V2.0

[5] https://civitai.com/models/34597/fair-faced-concrete-architecture

展开阅读全文
  • 0
    感动
  • 0
    路过
  • 0
    高兴
  • 0
    难过
  • 0
    搞笑
  • 0
    无聊
  • 0
    愤怒
  • 0
    同情
热度排行
友情链接