Inspiration
Recently, I started learning how to use the open source modeling program Blender. I've been blown away at how powerful the program is. One feature that particularly amazes me is the fluid simulation tool suite, given the sophistication, accuracy, and adaptability of the tools. However, generating these simulations can take hours or even days for complex scenes. I was interested in exploring ways to speed up this process by generating imperfect but fast approximations of the fluid flow. I turned to machine learning to give it a try.
What it does
The machine learning model generates 2D pictures of fluid flow based on some previous number of preceding frames. To generate a sequence/animation of fluid flow, the output of the model can be fed back into itself.
How I built it
Firstly, I created a Blender project that would allow me to generate the training data. I used a fluid simulation confined to a square, where the source of the fluid was moved around to create variety in the training data. For about 10 different iterations, I moved the fluid source, ran the simulation, and rendered the animation frames to image files. I discarded image frames where the fluid was either very turbulent or calm.
Next, I imported these image sequences into Python. For the features, I grouped pairs of images to give the model time context for the motion of the fluid. The training labels were the images following the feature pairs.
This training data was fed through a neural network mainly consisting of dense layers. The final dense layer was the same dimension as the input image size so the output could be fed back into the model on a future iteration.
After the model was trained, I evaluated the model by starting it off on samples from the training set (images rendered from Blender) and then using its predictions from that input as input for predicting new frames. I repeated this cycle process to generate a sequence of animation frames. One downside of this approach is that the errors, inaccuracies, and noise from previous predictions compounds as more frames are generated, so long prediction sequences devolve after 50-100 iterations.
The raw training data animations and the model-predicted animations are both shown in the project video on YouTube.
Challenges I ran into
I had the most trouble with the machine learning model's architecture due to the time constraints. I think my architecture choices early in the hackathon forced me down a path where I did not have a good opportunity for success. The machine learning model performed worse than I had hoped despite experimenting with various hyperparameters. The model accuracy was never more than a few percent, although it was able to output some reasonable looking frames, so it's possible that accuracy is not a fair metric of evaluation. Despite the accuracy being low, the loss frequently almost always decreased significantly during the training process. It's possible that the model overfit the training data, but this wasn't noticeable upon evaluation of the model. It's also possible that there just isn't enough training data.
Accomplishments that I'm proud of
I am most proud of the data generation process in Blender and the data loading/cleaning/organization process in Python. I was anticipating the most difficulty with these steps, but they went smoothly. As a whole, I am also happy with this project idea and I think it could be interesting to continue researching in the future.
What I learned
My biggest takeaway from this project is that machine learning is unforgiving. I thought I could spend just a bit of time experimenting with various models and learning as I went, but this approach was inefficient and unsuccessful. I would have had more success if I had thought about the machine learning aspect of this project more rigorously before I tried to code it. Finding a machine learning project with parallels to this project would have also been helpful, but I had no luck finding one.
What's next for ML Fluid Prediction
The first thing to improve upon is the model architecture, perhaps with convolutional layers or a LSTM approach. If the 2D model performs well, a model that predicts 3D fluid simulations would be something interesting to explore. Additionally, adding obstacles or varying the environment of the 2D model would make the model more generally useful and applicable to address the original project goal of speeding up fluid simulations.
Log in or sign up for Devpost to join the conversation.