在人工智能天生内容技能(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 安装

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

如果您是刚打仗 Python 编程的新用户,我们推举利用以下便捷的 pip 的安装办法:

pip install --upgrade ppdiffusers -f https://www.paddlepaddle.org.cn/whl/paddlenlp.html --user

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

git clone https://github.com/PaddlePaddle/PaddleNLPcd PaddleNLP/ppdiffuserspython setup.py install模型先容

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

效果图天生运用

基于笔墨天生

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

推理代码:

import paddlefrom ppdiffusers import StableDiffusionPipeline, DPMSolverMultistepSchedulerpaddle.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 osimport cv2import randomimport paddlefrom annotator.canny import CannyDetectorfrom annotator.util import HWC3, resize_imagefrom paddlenlp.trainer import set_seed as seed_everythingfrom ppdiffusers import ControlNetModel, StableDiffusionControlNetPipeline, StableDiffusionPipelineapply_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.no_grad():img = resize_image(HWC3(input_image), image_resolution)H, W, C = img.shapedetected_map = apply_canny(img, low_threshold, high_threshold)detected_map = HWC3(detected_map)control = paddle.to_tensor(detected_map.copy(), dtype=paddle.float32) / 255.0control = 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] + resultsinputImage = 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 地址

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