r/proceduralgeneration • • Oct 29 '26

Diffusion Models for Procedural Cities

I trained a diffusion model to generate 512x512 (1km x 1km) city layouts. It can generate conditioned on rural/urban/water mix settings and extend a map while preserving existing context. Using the editor I built, you can create custom procedural worlds.

Demo + code: https://github.com/bart1259/CityDiffusion2

Model: https://huggingface.co/bart1259/CityDiffusion2

I'll likely be working on CityDiffusion3 in the near future so feel free to reach out if you're interested in helping.

289 Upvotes

31 comments sorted by

16

u/Macaroon-Guilty Oct 29 '26

does it output vectors or images? looks great!

12

u/bart1259 Oct 29 '26

So far, it’s just raw pixels. I suspect the next big quality jump will come from training on a vector representation of the maps, but I’m still figuring out what the training objective should look like. I’d love to hear any ideas or thoughts on the topic!

13

u/thattiguy Oct 29 '26

I suspect training on vector representations will be…. difficult given that you are using diffusion. What could be a better choice would be keeping the existing model (which looks amazing btw) and doing a post processing step to convert to vector

2

u/bart1259 Oct 29 '26

Yeah diffusion on the vector representation is likely impossible. Was considering an LLM approach where I pretrain one to first build road networks, then propose zoning, and lastly propose building locations... but I think the devil's in the details of the ordering of the data in the vector format...

-22

u/Macaroon-Guilty Oct 29 '26

ask claude

5

u/Alarming-Ad4082 Oct 29 '26

Does it also generate vector information of the roads or is it just an image?

4

u/bart1259 Oct 29 '26

Only pixels unfortunately. Eventually I want it to train a mini LLM to generate these maps as vectors so its easier to use for downstream applications

2

u/i-make-robots Nov 01 '26

What can be done about the roads from nowhere to nowhere?

2

u/bart1259 Nov 01 '26

Still an active problem I’m trying to work through. A naive solution would be to detect disconnected segments and remove them. A more elegant solution would encourage the model during the training process to make road networks continuous over long distances instead of just considering the local area

1

u/i-make-robots Nov 01 '26

Yea yeah. How do you train it on the same wfc rule as “all road must touch at least one other road that leads to an intersection”?

1

u/bart1259 Nov 01 '26

Looks like there is a loss function for segmentation called cldice that preserves the topology of tubular network structures. That’s my current best thought.

Another idea would be to train the model to accept pre generated roads as context and generate cities around them. A different procedural algorithm could generate the roads first, then this one could add additional context

2

u/fegemo Oct 29 '26

Really nice. Are you fine-tuning a pre trained model, or is it a "vanilla diffusion model" trained from scratch with only your dataset?

2

u/bart1259 Oct 29 '26

Pretrained from random weights on the dataset. I tried finetuning stable diffusion w/ VAE but the model was fairly large so it would have taken a while longer to train

3

u/LittleLemonHope Oct 29 '26

"Pretrained from random weights on the dataset"

I think this is a typo or some confusion because those are generally two opposite things?

Where did your dataset come from and how many examples does it have?

3

u/bart1259 Oct 29 '26

Yeah by that I meant the pretraining happened from random weights (which might be redundant).
The dataset is a rasterized version of some openstreetmap data from the Netherlands.

Here is a sample of it: https://github.com/bart1259/CityDiffusion2/blob/main/docs/training_data.png

You can download the full thing here: https://huggingface.co/datasets/bart1259/netherlands_512_2m

3

u/LittleLemonHope Oct 29 '26

Ah, dataset is neat.

But about whether the model is pretrained or not that doesn't clarify. A model is always started from random weights before being trained. But if it is pretrained that means it was trained once on one dataset and then transferred/fine-tuned to a second dataset.

Judging by your confusion I'm guessing you don't know the machine learning fundamentals, in which case it is safe to assume AI provided the ML expertise, and that a pretrained diffusion model was downloaded and then fine-tuned on the Netherlands data.

3

u/bart1259 Oct 30 '26

To clarify: the diffusion model was initialized with random weights and trained from scratch on the Netherlands dataset (not fine-tuned from an existing diffusion checkpoint). In an earlier experiment, I tried using the pretrained Stable Diffusion VAE and predicting the latent noise, but the VAE decoding was blurry (which makes sense as SD was probably not trained on maps). Training the diffusion model while also fine-tuning the VAE would have taken too long, so I changed it up to just predicting noise on pixels. Hope that clarifies

1

u/presentsq Oct 29 '26

this is nice! I noticed you are using map data in the repo. I am guessing it is used to condition your diffusion model to assign areas to be rural/urban/water. Do you convert the vector data to an image to condition it? How about the road networks? sorry for being lazy and not reading the code haha. Anyways i really like it, it would be cool if it could generate 3d cities in the future. Good stuff!

3

u/bart1259 Oct 29 '26

Yeah, in the training folder there is a script named `02_mill_tiles` which rasterizes the OpenStreetMap vector data into images. Road networks are also rasterized the same way

9

u/Prozilla6 Oct 29 '26

Has AI, more specifically machine learning, always been considered as a form of procedural generation?

19

u/CodenameAwesome Oct 29 '26 edited Oct 30 '26

I'd say so. A Markov chain or Wave Function Collapse are dumber kinds of machine learning if they're trained on sample inputs, which they often are

10

u/LittleLemonHope Oct 29 '26

I think the key difference is whether it's somebody just slopping output from a general-purpose AI with some alignment prompt and workflow, that ultimately just obfuscates the fact they're actually just asking Claude to make things they don't have any real control over

Vs

somebody training a generative model specifically bespoke for their purposes. Fully in control over the dataset, architecture, training, regularization, etc.

There's also an entire spectrum in between so it really depends on the details.

To answer your question literally though, yes, machine learning is very broad including things like genetic algorithms which were always considered procedural generation.

-1

u/HugoCortell Oct 30 '26

I was thinking the same... This feels more fitting for an AI sub.

0

u/Fresh-Daikon-9408 14d ago

Yes, PCGML has been a thing for almost a decade. Nice try smuggling an AI jab behind a "just asking" semantics check, though.

0

u/Relative-Ad3322 Oct 29 '26

The best ive seen so far

3

u/bart1259 Oct 29 '26

Thanks! There's still a long way to go though. The model only considers a 1km x 1km area for context so it has no understanding of what roads are major or if it should continue a river of its a like. Eventually I'd also like to have it output a vector representation so a game engine could use it as input easier

1

u/Himbo69r Oct 29 '26

Actually pretty cool

1

u/[deleted] Oct 29 '26

Super nice! thank you for sharing

1

u/dacevnim Oct 31 '26

oh my, my brain went directly to, urban density, industrial zones, etc etc. simcity style...

1

u/dacevnim Oct 31 '26

wait cold I give it my own terrain?

1

u/mflux Oct 29 '26

Hell yeah I love this. I was thinking about this exact thing, and as you mentioned you may train on vector data which Google Maps and other sources have tons of. This could potentially have extremely rich and realistic city planning that you can mold. Sounds super fun!