Abstract
Editing existing images in text-to-image diffusion models often requires complex prompt engineering and results in unintended changes to unrelated image attributes. We present CASO (ClAssifier-guided Semantic Optimization), a training-free framework that achieves precise, disentangled image editing by optimizing semantic embeddings using gradients from pre-trained classifiers. By moving beyond text-based guidance, CASO preserves image identity while enabling high-fidelity attribute manipulation across diverse domains and artistic styles.
Introduction: The Challenges of Text-Based Editing
While models like Stable Diffusion have revolutionized image generation, editing existing images remains a "dark art." Most current methodologies rely on text prompts to guide modifications, an approach plagued by three major flaws:
- Prompt Engineering: Crafting descriptions that achieve specific results is time-consuming and unintuitive.
- Attribute Entanglement: Modifying one feature (e.g., adding "glasses") often inadvertently alters unrelated elements like hair color or background textures.
- Inconsistency: Identical prompts can yield wildly different results depending on random seeds or subtle phrasing variations.
CASO addresses these issues by replacing imprecise text strings with mathematical, classifier-based guidance that captures the pure semantic essence of an attribute.
The CASO Framework
CASO treats image editing as an optimization problem within the latent space of a frozen diffusion model. Unlike methods that require expensive retraining, CASO keeps the underlying model (e.g., Stable Diffusion) fixed, making it a lightweight and accessible solution.
Methodology and Dual Loss Optimization
The core of CASO is the optimization of a continuous "semantic embedding." Using a pre-trained, off-the-shelf attribute classifier (such as VGG16), the system calculates gradients to tune the embedding so the resulting image is more likely to be classified as having the target attribute. This process is governed by two primary losses:
- Edit Loss: Ensures the generated image matches the target attribute according to the classifier.
- Reconstruction Loss: Ensures the edited image retains the identity, structure, and background of the original input.
This approach is theoretically supported by "neural collapse" theory. The authors demonstrate that optimized embeddings converge toward the "class mean" of the attribute, explaining why the resulting edits are both precise and highly representative of the target feature.
Key Results and Generalization
CASO was evaluated across diverse datasets, including human faces (FFHQ, CelebAHQ), animals (AFHQ), and objects (Stanford Cars).
Quantitative Superiority
In comparative tests, CASO achieved lower LPIPS scores (a measure of perceptual similarity) than state-of-the-art methods like SEGA and DiffAE. This indicates that CASO is significantly better at preserving the original image's identity during the editing process. Furthermore, the method improved reconstruction quality; on the AFHQ Cat dataset, the FID score dropped from 72.35 to 43.20 when using targeted "cat" guidance.
Zero-Shot Generalization and Stitching
A standout feature of CASO is its ability to generalize. Although the classifiers were trained on real-world images, the learned embeddings work effectively on out-of-distribution data, such as sketches, anime, and classical oil paintings. Additionally, the framework supports "embedding stitching," allowing users to concatenate multiple learned embeddings (e.g., "Pale Skin" + "Bushy Eyebrows") to perform complex, simultaneous edits without interference between attributes.
Limitations and Ethical Considerations
While powerful, CASO depends on the availability of pre-trained classifiers for specific attributes. Editing an obscure feature requires first training a corresponding classifier. Additionally, high guidance scales can eventually lead to visual distortions. The authors also highlight the potential for misuse in creating deepfakes, suggesting the need for access controls and usage logs in deployment scenarios.
Conclusion
CASO moves image editing from a process of trial-and-error prompt engineering toward a theoretically sound, optimization-based framework. By leveraging classifier gradients, it provides a path toward highly controllable and disentangled manipulation of generative models without the need for additional training.
Summary updated