科技 > 人工智能 > 动态

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

116人参与 2024-08-06 动态

项目简介

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

在人工智能生成内容技术(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 应用中心,开发者可以打开以下链接并尝试上传自己的景观手绘或照片,感受快速高效输出渲染效果图的能力!

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

结语

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

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

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

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

https://www.scurbanlab.com/

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

飞桨EasyDL月刊:4月功能全新升级,模型训练步骤缩短63%

08-06

宝武中南钢铁借助飞桨让钢筋超限监控有了“火眼金睛”

08-06

超越YOLOv8,飞桨推出精度最高的实时检测器RT-DETR!

08-06

基于PINN的极少监督数据二维非定常圆柱绕流模拟

08-06

一文解读基于PaddleSeg的钢筋长度超限监控方案

08-06

百度CTO王海峰做客《中国经济大讲堂》:文心一言,读书破万亿

08-06

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论