Abstract
Neural painting refers to the procedure of producing a series of strokes for a given image and non-photo-realistically recreating it using neural networks. While reinforcement learning (RL) based agents can generate a stroke sequence step by step for this task, it is not easy to train a stable RL agent. On the other hand, stroke optimization methods search for a set of stroke parameters iteratively in a large search space; such low efficiency significantly limits their prevalence and practicality. Different from previous methods, in this paper, we formulate the task as a set prediction problem and propose a novel Transformer-based framework, dubbed Paint Transformer, to predict the parameters of a stroke set with a feed forward network. This way, our model can generate a set of strokes in parallel and obtain the final painting of size 512 × 512 in near real time. More importantly, since there is no dataset available for training the Paint Transformer, we devise a self-training pipeline such that it can be trained without any off-the-shelf dataset while still achieving excellent generalization capability. Experiments demonstrate that our method achieves better painting performance than previous ones with cheaper training and inference costs.
Introduction
Neural painting aims to teach computers to recreate images using brushstrokes rather than pixel manipulation. Historically, this has been approached via Reinforcement Learning (RL), where an agent paints sequentially, or through optimization-based methods that iteratively search for stroke parameters. However, RL agents are notoriously unstable to train, and optimization methods are prohibitively slow, often taking minutes to process a single low-resolution image.
The Paint Transformer addresses these challenges by rethinking the canvas as a set prediction problem. By predicting multiple strokes in parallel via a feed-forward network, the framework achieves near real-time performance and high-quality artistic abstraction without requiring human-labeled datasets.
Methodology
The Architecture
The Paint Transformer framework consists of two primary components:
- Stroke Predictor: Inspired by the DETR (Detection Transformer) architecture, this module receives the current canvas state and the target image. It utilizes a CNN for feature extraction and a Transformer encoder-decoder to predict a set of stroke parameters—including coordinates, shape, color, and rotation—along with a confidence score for each stroke.
- Stroke Renderer: This is a parameter-free, differentiable geometric transformation module. It treats strokes as linear transformations and alpha-blends them onto the canvas. Its differentiability allows the model to backpropagate errors from the final image directly to the stroke parameters.
Self-Training Pipeline
To overcome the lack of "ground truth" painting datasets, the authors developed a self-training strategy. The system generates a random background and a random set of foreground strokes to create a synthetic target image. The model is then trained to predict these specific foreground strokes, enabling infinite training data generation without manual labeling.
Coarse-to-Fine Inference
To mimic human artistic workflows, the model operates across multiple scales. It begins by predicting broad strokes for the entire image to capture global structure and progressively moves to smaller patches to add fine details.
Key Insights
- Parallel Set Prediction: By predicting a set of strokes simultaneously, the model avoids the compounding errors and training instabilities inherent in sequential RL approaches.
- Wasserstein Distance for Strokes: Standard $L_1$ loss is often ineffective for geometric shapes. By modeling strokes as 2D Gaussian distributions and using Wasserstein distance for the loss function, the model receives smoother gradients for learning shape and orientation.
- The "No-Stroke" Neuron: A binary confidence neuron allows the model to learn which strokes are necessary, preventing cluttered results by omitting redundant queries.
Results and Discussion
Paint Transformer demonstrates significant improvements in both efficiency and quality. It processes a 512x512 image in approximately 0.3 seconds, compared to over 500 seconds for optimization-based methods. Furthermore, training takes less than 4 hours on a single consumer GPU (Nvidia RTX 2080 Ti), a fraction of the 40+ hours required by RL methods.
Qualitatively, the model produces distinct, vivid brush textures that feel more like human-made art than the blurred outputs often seen in RL-based neural painting. Evaluation on datasets like WikiArt and FFHQ confirms the model's strong generalization capabilities across landscapes, portraits, and abstract art.
Conclusion
While Paint Transformer is currently limited to straight-line strokes and can occasionally lose global context during fine-scale patch processing, it represents a major step forward in neural painting. Future work will explore more complex stroke shapes and improved cross-patch context to handle intricate features more effectively.
Summary updated