Qing Lin, Mengmi Zhang*
*Corresponding author
Emotional intelligence enables humans to recognize emotions in images, understand their causes, reason about interventions, and generate visual modifications to achieve desired affective states. While current AI models can synthesize realistic images or perform limited content reasoning, they lack systematic emotional understanding, control, and personalization. Here, we introduce Emotion-augmented geneRatiOn System (EROS), a personalized hybrid AI that combines symbolic reasoning with deep learning. By leveraging large-scale image–emotion datasets and human psychophysics experiments, EROS derives generalizable affective rules, identifies emotion-relevant regions, and predicts context-aware modifications that preserve scene semantics. It further enables inference-time personalization through an expandable memory bank that yields interpretable emotional profiles without fine-tuning, allowing rapid and precise modulation of human affect. We demonstrate that EROS outperforms state-of-the-art large multimodal models in eliciting faster and stronger targeted emotional responses in individuals. Beyond affective computing, this framework offers a blueprint for AI systems that understand, reason about, and augment complex human cognitive states, with applications in mental health, adaptive media, and human–computer interaction.
Emotion-augmented geneRatiOn System (EROS) is an affective image editing framework that edits an input image toward a target emotional valence while preserving semantic and structural consistency.
EROS contains five modules:
- Recognition: predicts whether an image conveys positive or negative valence.
- Reasoning: localizes emotion-relevant regions using Grad-CAM and SAM.
- Control: retrieves affective editing motifs from EmoTree.
- Generation: synthesizes edited images with localized diffusion-based inpainting.
- Personalization: adapts motif selection using user feedback through EmoMem.
This repository provides two running modes:
1. Offline EROS-NoMem
A 5-loop non-personalized version.
2. Online Full EROS
An interactive personalized version with user feedback.
conda create -n EROS python=3.10
conda activate EROS
pip install torch torchvision torchaudio
pip install git+https://github.com/huggingface/diffusers.git
pip install transformers==4.49
pip install accelerate
pip install git+https://github.com/facebookresearch/segment-anything.git
pip install grad-cam
pip install numpy==1.24.3
pip install spacy
python -m spacy download en_core_web_sm
pip install controlnet_aux
pip install 'git+https://github.com/salesforce/LAVIS.git'
pip install openai
pip install gradio==4.44.1
pip install gradio-modal==0.0.4
pip install pydantic==2.10.4
pip install pydantic-core==2.27.2Before running EROS, please download all required assets and place them in the corresponding directories.
Download our EmoTree and place it under:
EmoTree/
└── EmoTree.json
Download our pretrained emotion predictor and place it under:
Emo_Predictor_model/
└── emo_preditor.pt
Download the SAM ViT-H checkpoint from link and place it under:
sam_model/
└── sam_vit_h_4b8939.pth
Launch the interactive demo:
python app_online_demo.pyThe interface allows users to:
- Upload an image
- Select a target valence
- Provide feedback ("Yes" / "No")
- Build personalized EmoMem profiles online
Run the non-personalized 5-loop version:
python EROS_noMem_top5loop.pyInput images should be placed in:
src_imgs/
Results will be saved in:
results/EROS_5loop/
EmoTree is a hierarchical affective knowledge structure used by EROS to retrieve interpretable editing motifs.
You can directly use our pre-built EmoTree.
- Download our EmoTree and put it in
EmoTree/.
If you would like to build EmoTree from scratch using EmoSet, follow the steps below.
- Set Up the Environment
- Export your OpenAI API key:
export OPENAI_API_KEY="YOUR_API_KEY"- Download EmoSet118k and put it in
Dataset/. The dataset structure is:
Dataset/
└── EmoSet118k/
├── train.json
└── image/
├── amusement/
├── awe/
├── contentment/
├── excitement/
├── anger/
├── disgust/
├── fear/
└── sadness/
Run:
python build_tree_step1_cluster_images.pyThis step extracts CLIP image features and performs hierarchical clustering.
The output will be stored in:
clusters/
Run:
python build_tree_step2_extract_source_concepts.pyThis step uses BLIP and GPT to extract source concepts, attributes, actions, and scenes from clustered images.
The output will be stored in:
json/src_concept/
Run:
python build_tree_step3_generate_emotree.pyThis step generates target motifs and organizes them into the final EmoTree structure.
The output will be stored in:
json/emo_tree/emo_tree.json
The final EmoTree consists of four levels:
Level 1:
Semantic Image Cluster
Level 2:
Source Concept
Level 3:
Target Valence
Level 4:
Target Motif
(Concept, Attribute, Action, Scene)
The resulting tree can be directly used for affective image editing and emotional motif retrieval.
Visualize EmoTree cluster:
Before visualizing EmoTree clusters, make sure the local cluster files have been generated. See Step 1: Hierarchical Image Clustering. The clusters should be stored in:
clusters/
Run:
python result_analysis/figure_tree_TSNE.pyVisualize EmoTree top-20 target concept:
python result_analysis/figure_tree_top20_concept.pyVisualize the global statistics of unique concepts, attributes, actions, and scenes:
python result_analysis/figure_tree_freq.pyGenerate word clouds:
python result_analysis/figure_word_cloud.pyParticipants interact with EROS in real time.
An OpenAI API key is required because Exp-EmoInteract compares EROS against GPT-based affective editing during runtime.
Before launching the experiment interface, export your OpenAI API key:
export OPENAI_API_KEY="YOUR_API_KEY"Download our test images and put them in src_imgs/.
Launch the experiment interface:
python app_inlab_exp.pyExperiment logs, participant responses, and personalization histories will be saved automatically.
Data from all participants in Exp-EmoInteract are available at the link.
For result analysis, run
python result_analysis/exp_EmoInteract_bootstrap.py- If the pair-out dataset is available, Exp-EmoMotif trials will be shown during Exp-EmoInteract image generation.
This allows participants to complete motif-preference evaluations while waiting for new images to be generated.
- If the dataset is not provided, the experiment interface will still run normally. However, users must wait while images are generated online.
The pair-out dataset used in Exp-EmoMotif can be downloaded at this link.
After downloading:
unzip pair_out.zipThis experiment compares EROS against state-of-the-art image editing methods using pre-generated results.
We have conducted a series of Mechanical Turk experiments using the Psiturk platform, which requires JavaScript, HTML, and Python 3.8.
Experiment code can be download here.
You can follow the PsiTurk Setup Guide to configure the environment and run the experiment.
Data from all participants in Exp-EmoPairwise are available at the link.
For result analysis, run
python result_analysis/exp_EmoPairwise_bootstrap.pyWe collect human annotations of emotion-relevant image regions, which can be download here.
Experiment code can be download here.
You can follow the PsiTurk Setup Guide to configure the environment and run the experiment.
We evaluated the consistency between human-annotated emotion-relevant regions and those predicted by EROS.
First, extract the emotion-relevant regions predicted by EROS:
python result_analysis/exact_emo_region_EROS.pyThen, extract the human-annotated emotion-relevant regions:
python result_analysis/exact_emo_region_human.pyFinally, run the result analysis:
python result_analysis/exp_EmoRegion_bootstrap.pyThis experiment evaluates whether prompts derived from EmoTree motifs convey the intended emotional valence.
Experiment code can be download here.
You can follow the PsiTurk Setup Guide to configure the environment and run the experiment.
Data from all participants in Exp-EmoPrompt are available at the link.
For result analysis, run
python result_analysis/exp_EmoPrompt_bootstrap.pyThis experiment evaluates both generic affective rules (EmoTree) and personalized affective profiles (EmoMem).
Experiment code can be download here.
You can follow the PsiTurk Setup Guide to configure the environment and run the experiment.
Data from all participants in Exp-EmoRule are available at the link.
For stage 1 result analysis, run
python result_analysis/exp_EmoRule_stage1_bootstrap.pyFor stage 2-3 result analysis, run
python result_analysis/exp_EmoRule_stage23_bootstrap.pyThis experiment evaluates whether motif preferences remain consistent across semantically related scenes.
The pair-out dataset used in Exp-EmoMotif can be downloaded at this link.
After downloading:
unzip pair_out.zipTo launch this experiment, run
python app_inlab_exp.pyData from all participants in Exp-EmoMotif are available at the link.
For result analysis, run
python result_analysis/exp_EmoMotif_bootstrap.pyIn affective image editing, models are expected to minimally modify images while achieving the target valence. To quantify both structural preservation and editing localization, we introduce two contrastive metrics:
- SSIM-C (Structural Similarity Contrast)
- L1-C (Pixel Difference Contrast)
A weight map w ∈ [0, 1] is constructed by aggregating binary masks from multiple human annotators (data collected in Exp-EmoRegion). The weight map represents the consensus of emotion-relevant regions intended for editing.
Weighted SSIM and L1 distances are computed separately for:
- Preserved regions, weighted by
1-w - Edited regions, weighted by
w
The contrastive metrics are defined as:
SSIM-C = SSIM_preserve / (SSIM_edit + ε)
L1-C = L1_preserve / (L1_edit + ε)
where ε is a small constant for numerical stability.
Interpretation:
- Higher SSIM-C indicates stronger structural preservation outside edited regions together with larger changes inside intended editing regions.
- Lower L1-C indicates smaller pixel-level deviations in preserved regions and larger modifications in targeted editing regions.
Before running the script, prepare:
- Source images
- Edited images
- Human annotation masks
Modify the corresponding input paths in:
base_dir
src_img_pth
user_mask_folder
res_method_pth_dict
loop_method_pth_dictThen run:
python result_analysis/metric_SSIMC_L1C.pyOutput:
results_summary_bootstrap_ssimc_l1c.csv
The emotion predictor is used by EROS to estimate whether an image conveys positive or negative valence.
Before running the script, prepare source images under:
src_imgs/
Image filenames should begin with one of the eight EmoSet emotion labels:
amusement, awe, contentment, excitement, anger, disgust, fear, sadness
The pretrained checkpoint should be placed under:
Emo_Predictor_model/
└── emo_preditor.pt
To evaluate the pretrained emotion predictor, run:
python result_analysis/test_emo_predictor.pyThe confusion matrix will be saved to:
plots/EmoPredictor/confusion_matrix.png
@article{lin2026EROS,
title={Personalized Emotional Intelligence in Generative AI through Symbolic Affective Reasoning},
author={Qing Lin and Mengmi Zhang},
journal={arXiv preprint arXiv:2607.10678},
year={2026}
}

