Ashish Mehta commited on
Commit
8e53dc6
·
1 Parent(s): ecc9495

Add initial project structure and configuration files for Adjective-Aware Object Embedding

Browse files

- Created README.md detailing project objectives, structure, and execution strategy.
- Added dataset.yaml for dataset configuration, including attribute taxonomy and splits.
- Introduced eval.yaml for evaluation metrics and visualization settings.
- Established experiment.yaml for defining baseline and proposed runs.
- Configured model.yaml for encoder settings and GNN architecture.
- Developed train.yaml for training parameters and optimization strategies.
- Drafted plan_draft.md outlining project goals, architecture, and data preparation strategies.

README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adjective-Aware Object Embedding
2
+
3
+ This project builds adjective-aware object embeddings using:
4
+
5
+ - CLIP image features
6
+ - DINOv2 image features
7
+ - Graph Neural Network (GNN) reasoning over object-attribute graphs
8
+
9
+ Current scope starts with `chair` and multi-label attributes like `broken`, `blue`, `wooden`, and `plastic`.
10
+
11
+ ## Project Structure
12
+
13
+ - `plan/plan.md` - detailed execution strategy and technical plan
14
+ - `configs/dataset.yaml` - dataset, attributes, splits, normalization
15
+ - `configs/model.yaml` - encoder, fusion, graph, and head settings
16
+ - `configs/train.yaml` - optimization, staging, losses, checkpointing
17
+ - `configs/eval.yaml` - metrics, visualization, error analysis
18
+ - `configs/experiment.yaml` - baseline/main/ablation run definitions
19
+
20
+ ## Config Overview
21
+
22
+ ### `dataset.yaml`
23
+
24
+ Defines:
25
+
26
+ - dataset root/cache/processed paths
27
+ - attribute taxonomy and synonym normalization
28
+ - split strategy and filtering rules
29
+ - basic augmentation
30
+
31
+ ### `model.yaml`
32
+
33
+ Defines:
34
+
35
+ - CLIP + DINO encoder settings
36
+ - fusion type (`concat`, optional gated/projected ablations)
37
+ - graph variant (`bipartite` / `enriched`)
38
+ - attribute node initialization (`clip_text` / `trainable`)
39
+ - GNN layers and baseline MLP head
40
+
41
+ ### `train.yaml`
42
+
43
+ Defines:
44
+
45
+ - two-stage training (frozen then partial fine-tuning)
46
+ - optimizer, scheduler, AMP, grad clipping
47
+ - weighted BCE + optional contrastive loss
48
+ - early stopping and checkpoint monitoring
49
+
50
+ ### `eval.yaml`
51
+
52
+ Defines:
53
+
54
+ - classification metrics (mAP, macro/micro F1, per-attribute metrics)
55
+ - embedding metrics (retrieval@K, silhouette)
56
+ - UMAP/t-SNE options
57
+ - error analysis outputs
58
+
59
+ ### `experiment.yaml`
60
+
61
+ Defines:
62
+
63
+ - baseline runs (A/B/C)
64
+ - main proposed run (CLIP+DINO+GNN)
65
+ - ablation runs (graph type, node init, loss, fine-tuning)
66
+
67
+ ## Execution Strategy (No Timeline)
68
+
69
+ Follow this order:
70
+
71
+ 1. Data prep + label normalization
72
+ 2. Baselines (A/B/C)
73
+ 3. Graph model training
74
+ 4. Ablations and tuning
75
+ 5. Robustness checks + packaging
76
+ 6. Build a minimal Gradio demo interface (final step, after model is fully trained and selected)
77
+
78
+ Use `plan/plan.md` as the source of truth for quality gates and deliverables.
79
+
80
+ ## How To Run
81
+
82
+ This repo currently provides config skeletons. Connect them to your training entrypoint (for example `scripts/train.py`) and evaluation entrypoint (for example `scripts/eval.py`).
83
+
84
+ Typical flow:
85
+
86
+ 1. Run baseline experiments from `configs/experiment.yaml`.
87
+ 2. Run the proposed GNN experiment.
88
+ 3. Run ablation experiments.
89
+ 4. Compare all runs in one metrics table.
90
+
91
+ ## Expected Outputs
92
+
93
+ - model checkpoints
94
+ - evaluation reports (mAP/F1/per-attribute)
95
+ - embedding analysis artifacts (UMAP/retrieval results)
96
+ - error analysis summaries
97
+ - minimal Gradio demo for interactive predictions
98
+
99
+ ## Notes
100
+
101
+ - Keep experiments reproducible with fixed seeds.
102
+ - Track all runs with consistent config snapshots.
103
+ - Measure gains against **Baseline C** to isolate graph contribution.
104
+
configs/dataset.yaml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ project:
2
+ name: adjective_aware_embedding
3
+ task: multi_label_attribute_prediction
4
+ primary_object_class: chair
5
+
6
+ dataset:
7
+ name: visual_genome
8
+ root_dir: data/raw/visual_genome
9
+ processed_dir: data/processed/visual_genome
10
+ cache_dir: data/cache
11
+ image_size: 224
12
+ num_workers: 8
13
+ pin_memory: true
14
+
15
+ splits:
16
+ train: 0.8
17
+ val: 0.1
18
+ test: 0.1
19
+ stratify_by_attribute_groups: true
20
+ split_seed: 42
21
+
22
+ attributes:
23
+ groups:
24
+ color:
25
+ - blue
26
+ - red
27
+ - white
28
+ - black
29
+ material:
30
+ - wooden
31
+ - plastic
32
+ - metal
33
+ condition:
34
+ - broken
35
+ - clean
36
+ - dirty
37
+ - old
38
+ min_support: 200
39
+ lowercase: true
40
+ lemmatize: true
41
+ synonym_map:
42
+ wood: wooden
43
+ damaged: broken
44
+
45
+ filtering:
46
+ drop_empty_labels: true
47
+ deduplicate_images: true
48
+ keep_only_primary_object: chair
49
+ max_samples_per_attribute: null
50
+
51
+ augmentation:
52
+ enabled: true
53
+ horizontal_flip_prob: 0.5
54
+ color_jitter_prob: 0.2
55
+ random_resized_crop_scale:
56
+ - 0.8
57
+ - 1.0
configs/eval.yaml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ evaluation:
2
+ split: val
3
+ threshold:
4
+ strategy: fixed
5
+ value: 0.5
6
+
7
+ metrics:
8
+ classification:
9
+ - map
10
+ - macro_f1
11
+ - micro_f1
12
+ - per_attribute_ap
13
+ - per_attribute_f1
14
+ calibration:
15
+ enabled: false
16
+ bins: 15
17
+ metrics:
18
+ - ece
19
+ embedding:
20
+ enabled: true
21
+ retrieval_k:
22
+ - 1
23
+ - 5
24
+ - 10
25
+ compute_silhouette: true
26
+
27
+ visualization:
28
+ umap:
29
+ enabled: true
30
+ n_neighbors: 15
31
+ min_dist: 0.1
32
+ random_state: 42
33
+ tsne:
34
+ enabled: false
35
+ perplexity: 30
36
+ random_state: 42
37
+
38
+ error_analysis:
39
+ enabled: true
40
+ top_k_false_positives: 20
41
+ top_k_false_negatives: 20
42
+ analyze_by_frequency_bucket: true
43
+ confusion_focus_groups:
44
+ - color
45
+ - material
46
+ - condition
47
+
48
+ reporting:
49
+ save_predictions: true
50
+ save_embeddings: true
51
+ output_dir: reports/eval
configs/experiment.yaml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ id: exp_clip_dino_gnn_v1
3
+ description: CLIP+DINO fusion with bipartite GNN and BCE+InfoNCE.
4
+ tags:
5
+ - baseline_c_plus_gnn
6
+ - adjective_embedding
7
+ - visual_genome
8
+
9
+ defaults:
10
+ dataset: configs/dataset.yaml
11
+ model: configs/model.yaml
12
+ train: configs/train.yaml
13
+ eval: configs/eval.yaml
14
+
15
+ baseline_runs:
16
+ - name: baseline_a_clip_only_mlp
17
+ overrides:
18
+ encoders.clip.enabled: true
19
+ encoders.dino.enabled: false
20
+ graph.variant: none
21
+ gnn.type: none
22
+ - name: baseline_b_dino_only_mlp
23
+ overrides:
24
+ encoders.clip.enabled: false
25
+ encoders.dino.enabled: true
26
+ graph.variant: none
27
+ gnn.type: none
28
+ - name: baseline_c_clip_dino_mlp
29
+ overrides:
30
+ encoders.clip.enabled: true
31
+ encoders.dino.enabled: true
32
+ graph.variant: none
33
+ gnn.type: none
34
+
35
+ main_run:
36
+ name: proposed_clip_dino_gnn
37
+ overrides:
38
+ graph.variant: bipartite
39
+ gnn.type: gat
40
+ attribute_nodes.init_type: clip_text
41
+
42
+ ablation_runs:
43
+ - name: graph_enriched_with_attribute_priors
44
+ overrides:
45
+ graph.variant: enriched
46
+ graph.include_attribute_priors: true
47
+ - name: trainable_attribute_nodes
48
+ overrides:
49
+ attribute_nodes.init_type: trainable
50
+ - name: bce_only
51
+ overrides:
52
+ loss.contrastive.enabled: false
53
+ - name: partial_encoder_finetune
54
+ overrides:
55
+ training.stage2.enabled: true
56
+ training.stage2.unfreeze_top_n_layers: 4
configs/model.yaml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model:
2
+ name: clip_dino_gnn
3
+ num_attributes: 12
4
+ primary_object_class: chair
5
+
6
+ encoders:
7
+ clip:
8
+ enabled: true
9
+ model_name: ViT-B-32
10
+ pretrained: true
11
+ output_dim: 512
12
+ freeze_stage1: true
13
+ dino:
14
+ enabled: true
15
+ model_name: vit_base_patch14_dinov2
16
+ pretrained: true
17
+ output_dim: 768
18
+ freeze_stage1: true
19
+
20
+ fusion:
21
+ type: concat
22
+ output_dim: 1280
23
+ projected_fusion:
24
+ enabled: false
25
+ hidden_dim: 512
26
+ gated_fusion:
27
+ enabled: false
28
+ hidden_dim: 512
29
+
30
+ graph:
31
+ variant: bipartite
32
+ include_attribute_priors: false
33
+ edge_weighting:
34
+ labeled_positive: 1.0
35
+ weak_min: 0.3
36
+ weak_max: 0.8
37
+
38
+ attribute_nodes:
39
+ init_type: clip_text
40
+ prompt_template: "a {attribute} chair"
41
+ trainable_dim: 256
42
+
43
+ gnn:
44
+ type: gat
45
+ layers:
46
+ - in_dim: 1280
47
+ out_dim: 512
48
+ heads: 4
49
+ dropout: 0.2
50
+ - in_dim: 512
51
+ out_dim: 256
52
+ heads: 2
53
+ dropout: 0.2
54
+ classifier:
55
+ in_dim: 256
56
+ out_dim: 12
57
+
58
+ baseline_heads:
59
+ mlp:
60
+ enabled: true
61
+ hidden_dims:
62
+ - 512
63
+ - 256
64
+ dropout: 0.2
configs/train.yaml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ run:
2
+ seed: 42
3
+ deterministic: true
4
+ experiment_name: clip_dino_gnn_bipartite
5
+ output_dir: outputs
6
+ save_every_n_epochs: 1
7
+
8
+ training:
9
+ stage1:
10
+ enabled: true
11
+ epochs: 20
12
+ freeze_encoders: true
13
+ lr_head: 0.001
14
+ lr_encoder: 0.0
15
+ stage2:
16
+ enabled: true
17
+ epochs: 20
18
+ freeze_encoders: false
19
+ unfreeze_top_n_layers: 2
20
+ lr_head: 0.0005
21
+ lr_encoder: 0.00001
22
+
23
+ optimization:
24
+ optimizer: adamw
25
+ weight_decay: 0.0001
26
+ betas:
27
+ - 0.9
28
+ - 0.999
29
+ grad_clip_norm: 1.0
30
+ gradient_accumulation_steps: 1
31
+ mixed_precision: true
32
+
33
+ scheduler:
34
+ type: cosine_with_warmup
35
+ warmup_ratio: 0.1
36
+ min_lr: 0.0000001
37
+
38
+ batching:
39
+ batch_size: 32
40
+ eval_batch_size: 64
41
+
42
+ loss:
43
+ bce:
44
+ enabled: true
45
+ pos_weight_mode: inverse_frequency
46
+ contrastive:
47
+ enabled: true
48
+ type: infonce
49
+ temperature: 0.07
50
+ lambda: 0.1
51
+ positive_sampling: same_adjective_group
52
+ negative_sampling: conflicting_groups
53
+
54
+ early_stopping:
55
+ enabled: true
56
+ monitor: val_map
57
+ mode: max
58
+ patience: 8
59
+
60
+ checkpoint:
61
+ enabled: true
62
+ monitor: val_map
63
+ mode: max
64
+ save_best_only: true
plan/plan.md CHANGED
@@ -1,335 +1,340 @@
1
- # Adjective-Aware Object Embedding using CLIP, DINOv2, and Graph Neural Networks
2
 
3
- ## 1. Project Objective
4
 
5
- Build a system that learns **adjectives associated with objects** (e.g.,
6
- chairs) and reshapes the embedding space so objects cluster based on
7
- attributes like:
8
 
9
- - broken
10
- - blue
11
- - wooden
12
- - plastic
13
- - dirty
14
- - metal
15
 
16
- Encoders used: - CLIP Vision Encoder - DINOv2 Vision Encoder - Graph
17
- Neural Network layer for attribute reasoning
18
 
19
- ------------------------------------------------------------------------
20
 
21
- ## 2. System Architecture
22
 
23
- Image │ ├── CLIP Encoder ├── DINOv2 Encoder │ └── Feature Fusion │ ▼
24
- Object Embedding │ ▼ Graph Construction │ ▼ Graph Neural Network │ ▼
25
- Adjective-aware embedding │ ▼ Attribute prediction
26
 
27
- ------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
28
 
29
- ## 3. Encoders
30
 
31
- ### CLIP Vision Encoder
32
 
33
- Common models: - ViT-B/32 - ViT-L/14
34
 
35
- Output embedding size: 512--768
36
 
37
- Benefits: - aligned with language - semantic understanding
 
38
 
39
- ### DINOv2 Encoder
40
 
41
- Common models: - vit-small - vit-base - vit-large
 
 
42
 
43
- Output embedding size: 768--1024
44
 
45
- Benefits: - strong visual structure representation - self-supervised
46
- learning
 
47
 
48
- ------------------------------------------------------------------------
49
 
50
- ## 4. Feature Fusion
51
 
52
- clip_embedding = CLIP(image)\
53
- dino_embedding = DINO(image)
 
 
54
 
55
- combined_embedding = concat(clip_embedding, dino_embedding)
56
 
57
- Typical dimension:
58
 
59
- 1536
60
 
61
- ------------------------------------------------------------------------
62
 
63
- ## 5. Graph Design
64
 
65
- Graph nodes:
 
 
66
 
67
- Object nodes\
68
- Attribute nodes
69
 
70
- Example:
71
 
72
- Objects: chair_1 chair_2 chair_3
73
 
74
- Attributes: blue broken wooden plastic dirty metal
 
 
75
 
76
- Edges:
77
 
78
- chair → blue\
79
- chair → broken\
80
- chair → plastic
81
 
82
- Optional attribute relations:
83
 
84
- plastic ↔ material\
85
- blue ↔ color\
86
- broken ↔ damage
87
 
88
- ------------------------------------------------------------------------
89
 
90
- ## 6. Node Features
91
 
92
- ### Object nodes
 
 
 
93
 
94
- Feature = fused embedding
95
 
96
- dimension = 1536
97
 
98
- ### Attribute nodes
99
 
100
- Option 1 (recommended)
101
 
102
- Use CLIP text embeddings:
 
103
 
104
- "a blue chair"\
105
- "a broken chair"\
106
- "a wooden chair"
107
 
108
- Option 2
109
 
110
- Learn attribute embeddings (trainable vectors)
 
 
 
111
 
112
- ------------------------------------------------------------------------
113
 
114
- ## 7. GNN Model
115
 
116
- Suggested architecture:
 
 
117
 
118
- GATConv(input_dim,512)\
119
- ReLU\
120
- GATConv(512,256)\
121
- Linear(256,1)
122
 
123
- Prediction is computed from attribute nodes.
124
 
125
- ------------------------------------------------------------------------
126
 
127
- ## 8. Training Objectives
128
 
129
- ### Attribute Prediction
130
 
131
- Multi‑label classification
132
 
133
- Loss:
 
134
 
135
- Binary Cross Entropy
136
 
137
- Example label:
138
 
139
- chair_1: broken=1\
140
- blue=0\
141
- plastic=1
 
142
 
143
- ### Contrastive Embedding Loss
144
 
145
- Encourage clustering by adjectives.
146
 
147
- Example:
148
 
149
- Positive pair: blue chair A blue chair B
150
 
151
- Negative pair: blue chair vs broken chair
152
 
153
- Loss options: - Triplet loss - Contrastive loss - InfoNCE
 
 
154
 
155
- ------------------------------------------------------------------------
156
 
157
- ## 9. Datasets
158
 
159
- ### Visual Genome
160
 
161
- \~108k images with objects, attributes, and relationships.
162
 
163
- Example annotation:
164
 
165
- chair → wooden\
166
- chair → old
167
 
168
- Download: https://visualgenome.org
169
 
170
- ------------------------------------------------------------------------
 
171
 
172
- ### Open Images V7
173
 
174
- \~9M images with detection and attribute labels.
 
175
 
176
- Example:
177
 
178
- chair → plastic\
179
- chair → old
180
 
181
- Download: https://storage.googleapis.com/openimages/web/index.html
 
 
 
 
 
182
 
183
- ------------------------------------------------------------------------
184
 
185
- ### MIT States Dataset
 
 
 
 
186
 
187
- Object‑state dataset.
188
 
189
- Examples:
190
 
191
- broken chair\
192
- painted chair\
193
- clean chair
194
 
195
- ------------------------------------------------------------------------
 
 
 
196
 
197
- ### SUN Attribute Dataset
198
 
199
- Dataset containing \~102 visual attributes.
 
 
200
 
201
- Examples:
202
 
203
- rusty\
204
- shiny\
205
- old\
206
- colorful
207
 
208
- ------------------------------------------------------------------------
 
 
209
 
210
- ### COCO Dataset
211
 
212
- Object detection dataset (\~330k images).
213
 
214
- Attributes must be manually annotated.
215
 
216
- Download: https://cocodataset.org
 
 
 
 
217
 
218
- ------------------------------------------------------------------------
219
 
220
- ### LAION‑400M
221
 
222
- Large image‑text dataset with captions.
223
 
224
- Example captions:
225
 
226
- "a broken plastic chair"\
227
- "a blue chair"
 
 
228
 
229
- Attributes can be extracted using NLP.
230
 
231
- Download: https://laion.ai
 
 
 
232
 
233
- ------------------------------------------------------------------------
234
 
235
- ### ImageNet‑Attribute variants
 
 
 
236
 
237
- Researchers often annotate ImageNet objects with attributes such as:
238
 
239
- metal\
240
- wooden\
241
- colorful
 
 
242
 
243
- Useful for transfer learning.
244
 
245
- ------------------------------------------------------------------------
246
 
247
- ## 10. Data Preparation
248
 
249
- Dataset pipeline:
250
 
251
- images ↓ object detection (chair) ↓ extract attributes ↓ build
252
- object‑attribute graph
 
 
 
 
 
 
 
253
 
254
- Example dataset:
255
 
256
- dataset/ chair_001.jpg chair_002.jpg
257
 
258
- labels:
 
259
 
260
- chair_001.jpg → \[blue,plastic\]\
261
- chair_002.jpg → \[broken,wooden\]
262
 
263
- ------------------------------------------------------------------------
 
264
 
265
- ## 11. Training Pipeline
 
266
 
267
- Image ↓ CLIP encoder ↓ DINOv2 encoder ↓ feature fusion ↓ graph
268
- construction ↓ GNN forward pass ↓ attribute prediction ↓ loss
269
- computation ↓ backpropagation
270
 
271
- ------------------------------------------------------------------------
272
 
273
- ## 12. Inference Pipeline
 
 
 
 
 
274
 
275
- New Image ↓ CLIP + DINO ↓ embedding fusion ↓ graph node creation ↓ GNN
276
- inference ↓ attribute scores
277
 
278
- Example output:
279
 
280
- broken: 0.91\
281
- blue: 0.12\
282
- plastic: 0.87\
283
- wooden: 0.04
284
-
285
- ------------------------------------------------------------------------
286
-
287
- ## 13. Evaluation
288
-
289
- Metrics:
290
-
291
- - mean average precision
292
- - F1 score
293
- - multi‑label accuracy
294
-
295
- Embedding analysis:
296
-
297
- - t‑SNE
298
- - UMAP
299
-
300
- Goal: observe clusters based on adjectives.
301
-
302
- ------------------------------------------------------------------------
303
-
304
- ## 14. Future Extensions
305
-
306
- Graph Transformer instead of GNN.
307
-
308
- Scene graph learning:
309
-
310
- chair → broken → leg
311
-
312
- LLM integration to generate descriptions:
313
-
314
- "This is a broken blue plastic chair."
315
-
316
- ------------------------------------------------------------------------
317
-
318
- ## 15. Deliverables
319
-
320
- - adjective aware embedding model
321
- - attribute prediction model
322
- - graph dataset
323
- - clustering visualizations
324
-
325
- ------------------------------------------------------------------------
326
-
327
- ## 16. Summary
328
-
329
- The system combines:
330
-
331
- CLIP semantic features\
332
- DINOv2 visual features\
333
- Graph neural network reasoning
334
-
335
- to produce an **embedding space structured by object adjectives**.
 
1
+ # Adjective-Aware Object Embedding
2
 
3
+ ## 1) Goal and Scope
4
 
5
+ Build an adjective-aware representation pipeline for object images (starting with `chair`) that:
 
 
6
 
7
+ - predicts multi-label attributes (for example `broken`, `blue`, `wooden`, `plastic`)
8
+ - reshapes embedding space so items cluster by adjectives, not only by object identity
9
+ - supports both offline analysis (embedding quality) and online inference (attribute scoring)
 
 
 
10
 
11
+ Initial scope is single-object class (`chair`) to de-risk data and modeling, then generalize to multi-class.
 
12
 
13
+ ---
14
 
15
+ ## 2) Target Outcomes (Definition of Done)
16
 
17
+ The project is complete when all conditions below are met:
 
 
18
 
19
+ - **Model quality**
20
+ - mAP improves over baseline by >= 8-12% relative.
21
+ - Macro-F1 improves over baseline by >= 5% relative.
22
+ - At least 4 key attributes (`broken`, `blue`, `wooden`, `plastic`) achieve per-class AP >= 0.70 on validation (adjustable by data quality).
23
+ - **Embedding quality**
24
+ - UMAP/t-SNE shows tighter adjective clusters than baseline.
25
+ - Retrieval@K for same-adjective neighbors is measurably improved.
26
+ - **Engineering quality**
27
+ - Reproducible training with fixed seeds and config-driven runs.
28
+ - End-to-end training + inference scripts run without manual edits.
29
+ - Experiment logs and checkpoints are versioned and comparable.
30
 
31
+ ---
32
 
33
+ ## 3) Technical Strategy
34
 
35
+ ### 3.1 Core Idea
36
 
37
+ Use a dual-encoder visual backbone:
38
 
39
+ - CLIP image features (semantic alignment)
40
+ - DINOv2 image features (visual structure)
41
 
42
+ Fuse both features and perform message passing over an object-attribute graph, where:
43
 
44
+ - object nodes use fused visual features
45
+ - attribute nodes use CLIP text embeddings (or learnable vectors as ablation)
46
+ - edges encode object-attribute membership (+ optional attribute-attribute priors)
47
 
48
+ ### 3.2 Modeling Choice Rationale
49
 
50
+ - CLIP alone is strong semantically but can miss fine visual states.
51
+ - DINOv2 adds complementary visual detail.
52
+ - GNN introduces relational inductive bias, useful for correlated attributes (`plastic` with `material`, `broken` with `damage`).
53
 
54
+ ### 3.3 Baselines (Mandatory)
55
 
56
+ Implement before full GNN rollout:
57
 
58
+ 1. **Baseline A:** CLIP-only + MLP multi-label head
59
+ 2. **Baseline B:** DINO-only + MLP multi-label head
60
+ 3. **Baseline C:** CLIP+DINO fusion + MLP head (no graph)
61
+ 4. **Proposed:** CLIP+DINO + GNN
62
 
63
+ All gains must be reported against Baseline C to isolate graph contribution.
64
 
65
+ ---
66
 
67
+ ## 4) Data Strategy
68
 
69
+ ## 4.1 Dataset Selection (Phase-1 Priority)
70
 
71
+ Use this order:
72
 
73
+ 1. **Visual Genome** (object + attributes, fastest path for graph supervision)
74
+ 2. **MIT States / SUN Attributes** (state-centric signals, useful for adjective robustness)
75
+ 3. **Open Images V7** (scale-up if labels fit target adjectives)
76
 
77
+ Avoid LAION in Phase-1 training due to noisy weak labels; use only for optional pretraining or pseudo-label mining.
 
78
 
79
+ ## 4.2 Label Taxonomy
80
 
81
+ Normalize attributes into controlled groups:
82
 
83
+ - **Color:** blue, red, white, black, ...
84
+ - **Material:** wooden, plastic, metal, ...
85
+ - **Condition/State:** broken, clean, dirty, old, ...
86
 
87
+ Rules:
88
 
89
+ - lowercase, lemmatized labels
90
+ - synonym merge (`wood` -> `wooden`, `damaged` -> `broken` when valid)
91
+ - keep only attributes with minimum support threshold (for example >= 200 samples)
92
 
93
+ ## 4.3 Data Splits
94
 
95
+ - train/val/test by image IDs (no leakage)
96
+ - stratified split by high-level attribute groups
97
+ - maintain long-tail report for rare attributes
98
 
99
+ ## 4.4 Data Quality Gates
100
 
101
+ Before model training, enforce:
102
 
103
+ - duplicate image check
104
+ - invalid/empty label filtering
105
+ - per-attribute frequency report
106
+ - noisy label audit on random sample (manual spot check)
107
 
108
+ ---
109
 
110
+ ## 5) Graph Construction Plan
111
 
112
+ ## 5.1 Graph Types
113
 
114
+ Build two graph variants for experiments:
115
 
116
+ - **Variant 1 (Bipartite):** object <-> attribute
117
+ - **Variant 2 (Enriched):** object <-> attribute + attribute <-> attribute priors
118
 
119
+ Start with Variant 1 for stability, then ablate Variant 2.
 
 
120
 
121
+ ## 5.2 Node Features
122
 
123
+ - **Object node:** fused visual embedding (`[clip || dino]`)
124
+ - **Attribute node (default):** CLIP text embedding from prompt template:
125
+ - `a {attribute} chair`
126
+ - **Attribute node (ablation):** trainable vectors
127
 
128
+ ## 5.3 Edge Weights
129
 
130
+ Use weighted edges for confidence:
131
 
132
+ - labeled positive edge: weight = 1.0
133
+ - weak/pseudo edge (if used): weight in `[0.3, 0.8]`
134
+ - optional attribute prior edge from co-occurrence PMI or normalized co-frequency
135
 
136
+ ---
 
 
 
137
 
138
+ ## 6) Model Architecture
139
 
140
+ ## 6.1 Feature Fusion
141
 
142
+ Start with concatenation:
143
 
144
+ - `z = concat(z_clip, z_dino)`
145
 
146
+ Then ablate:
147
 
148
+ - gated fusion (`z = g * z_clip + (1 - g) * z_dino`)
149
+ - projected fusion (linear layers to shared dimension before concat)
150
 
151
+ ## 6.2 GNN Head
152
 
153
+ Recommended start:
154
 
155
+ - `GATConv(input_dim -> 512, heads=4)`
156
+ - `ReLU + Dropout(0.2)`
157
+ - `GATConv(512 -> 256, heads=2)`
158
+ - `Linear(256 -> num_attributes)` for object-node logits
159
 
160
+ Alternative for stability if needed: GraphSAGE.
161
 
162
+ ## 6.3 Loss Design
163
 
164
+ Primary:
165
 
166
+ - weighted BCE with class-frequency weights
167
 
168
+ Secondary:
169
 
170
+ - contrastive / InfoNCE on object embeddings:
171
+ - positives: same adjective group
172
+ - negatives: conflicting adjective groups
173
 
174
+ Total:
175
 
176
+ - `L = L_bce + lambda_contrast * L_contrast`
177
 
178
+ Tune `lambda_contrast` in `{0.05, 0.1, 0.2}`.
179
 
180
+ ---
181
 
182
+ ## 7) Training Strategy
183
 
184
+ ## 7.1 Two-Stage Optimization
 
185
 
186
+ Stage 1:
187
 
188
+ - freeze CLIP and DINO encoders
189
+ - train fusion + GNN head
190
 
191
+ Stage 2:
192
 
193
+ - unfreeze top N layers of encoders (N configurable)
194
+ - fine-tune with lower LR for encoders
195
 
196
+ This reduces instability and GPU cost early.
197
 
198
+ ## 7.2 Hyperparameter Defaults
 
199
 
200
+ - optimizer: AdamW
201
+ - LR head: `1e-3`
202
+ - LR encoder: `1e-5` (stage 2)
203
+ - weight decay: `1e-4`
204
+ - batch size: maximize stable GPU usage (target 32+ effective via grad accumulation)
205
+ - epochs: 30-60 with early stopping on val mAP
206
 
207
+ ## 7.3 Training Controls
208
 
209
+ - deterministic seed support
210
+ - mixed precision enabled
211
+ - gradient clipping (`1.0`)
212
+ - checkpoint by best val mAP
213
+ - scheduler: cosine decay with warmup
214
 
215
+ ---
216
 
217
+ ## 8) Evaluation Strategy
218
 
219
+ ## 8.1 Core Metrics
 
 
220
 
221
+ - mAP (primary)
222
+ - Macro-F1 and Micro-F1
223
+ - per-attribute AP and F1
224
+ - calibration metrics (ECE / reliability bins) if serving probabilities
225
 
226
+ ## 8.2 Embedding Metrics
227
 
228
+ - retrieval precision@K for same-adjective neighbors
229
+ - cluster compactness/separation (silhouette on adjective labels)
230
+ - UMAP/t-SNE visual audits (fixed random seed)
231
 
232
+ ## 8.3 Error Analysis
233
 
234
+ Every run should include:
 
 
 
235
 
236
+ - top false positives and false negatives per attribute
237
+ - confusion among correlated materials/colors
238
+ - performance by attribute frequency bucket (head/mid/tail)
239
 
240
+ ---
241
 
242
+ ## 9) Ablation Matrix (Required)
243
 
244
+ Minimum experiment grid:
245
 
246
+ 1. CLIP-only vs DINO-only vs fused
247
+ 2. no-graph vs bipartite graph vs enriched graph
248
+ 3. text-initialized attribute nodes vs trainable attribute nodes
249
+ 4. BCE only vs BCE + contrastive
250
+ 5. frozen encoders vs partial fine-tuning
251
 
252
+ Keep one variable changed per ablation for clean conclusions.
253
 
254
+ ---
255
 
256
+ ## 10) Execution Sequence (No Timeline)
257
 
258
+ ### Phase A: Data and Baselines
259
 
260
+ - finalize attribute taxonomy and label normalization
261
+ - build data loader + split pipeline
262
+ - train Baseline A/B/C
263
+ - output: baseline report and dataset diagnostics
264
 
265
+ ### Phase B: Graph Pipeline
266
 
267
+ - implement graph builder (Variant 1)
268
+ - train GNN model with frozen encoders
269
+ - evaluate against Baseline C
270
+ - output: first graph-vs-no-graph comparison
271
 
272
+ ### Phase C: Optimization and Ablations
273
 
274
+ - run stage-2 fine-tuning
275
+ - run required ablations
276
+ - tune `lambda_contrast`, fusion, graph depth
277
+ - output: ablation table + selected final config
278
 
279
+ ### Phase D: Robustness and Packaging
280
 
281
+ - run long-tail and error analysis
282
+ - package inference script, checkpoints, and reproducibility docs
283
+ - add minimal Gradio demo interface for inference
284
+ - generate final report with metrics and visualizations
285
+ - output: final model + execution docs + demo outputs
286
 
287
+ Gradio demo is an end-stage task and starts only after training, ablations, and final model selection are complete.
288
 
289
+ ---
290
 
291
+ ## 11) Repository Execution Structure
292
 
293
+ Suggested structure:
294
 
295
+ - `configs/` (dataset/model/train/eval yaml)
296
+ - `data/` (raw + processed metadata, ignore large binaries in git)
297
+ - `src/encoders/` (clip, dino wrappers)
298
+ - `src/graph/` (graph builder, priors, batching)
299
+ - `src/models/` (fusion, gnn heads, mlp baselines)
300
+ - `src/train/` (trainer, losses, schedulers)
301
+ - `src/eval/` (metrics, retrieval, visualization)
302
+ - `scripts/` (train, eval, infer)
303
+ - `reports/` (experiment tables, plots, analysis)
304
 
305
+ ---
306
 
307
+ ## 12) Risks and Mitigations
308
 
309
+ - **Risk:** label noise in attributes
310
+ **Mitigation:** filtering, confidence weights, manual audit sample.
311
 
312
+ - **Risk:** class imbalance hurts rare adjectives
313
+ **Mitigation:** weighted BCE, focal loss fallback, frequency-aware sampling.
314
 
315
+ - **Risk:** overfitting with small attribute subsets
316
+ **Mitigation:** stronger augmentation, early stopping, regularization.
317
 
318
+ - **Risk:** graph complexity without measurable gain
319
+ **Mitigation:** enforce baseline comparison and remove graph if gain is negligible.
320
 
321
+ ---
 
 
322
 
323
+ ## 13) Final Deliverables
324
 
325
+ - trained adjective-aware embedding model
326
+ - reproducible training and inference pipeline
327
+ - ablation and baseline comparison report
328
+ - embedding visualization and retrieval analysis
329
+ - concise model card (dataset, metrics, limits, known failure cases)
330
+ - minimal Gradio demo app for interactive attribute prediction
331
 
332
+ ---
 
333
 
334
+ ## 14) Immediate Next Actions
335
 
336
+ 1. Lock Phase-1 dataset (`Visual Genome`) and attribute list.
337
+ 2. Implement data normalization and split scripts.
338
+ 3. Train Baseline C (`CLIP+DINO+MLP`) as reference.
339
+ 4. Build bipartite graph constructor and run first GNN experiment.
340
+ 5. Record metrics in a single comparison table from day one.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plan/plan_draft.md ADDED
@@ -0,0 +1,335 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Adjective-Aware Object Embedding using CLIP, DINOv2, and Graph Neural Networks
2
+
3
+ ## 1. Project Objective
4
+
5
+ Build a system that learns **adjectives associated with objects** (e.g.,
6
+ chairs) and reshapes the embedding space so objects cluster based on
7
+ attributes like:
8
+
9
+ - broken
10
+ - blue
11
+ - wooden
12
+ - plastic
13
+ - dirty
14
+ - metal
15
+
16
+ Encoders used: - CLIP Vision Encoder - DINOv2 Vision Encoder - Graph
17
+ Neural Network layer for attribute reasoning
18
+
19
+ ------------------------------------------------------------------------
20
+
21
+ ## 2. System Architecture
22
+
23
+ Image │ ├── CLIP Encoder ├── DINOv2 Encoder │ └── Feature Fusion │ ▼
24
+ Object Embedding │ ▼ Graph Construction │ ▼ Graph Neural Network │ ▼
25
+ Adjective-aware embedding │ ▼ Attribute prediction
26
+
27
+ ------------------------------------------------------------------------
28
+
29
+ ## 3. Encoders
30
+
31
+ ### CLIP Vision Encoder
32
+
33
+ Common models: - ViT-B/32 - ViT-L/14
34
+
35
+ Output embedding size: 512--768
36
+
37
+ Benefits: - aligned with language - semantic understanding
38
+
39
+ ### DINOv2 Encoder
40
+
41
+ Common models: - vit-small - vit-base - vit-large
42
+
43
+ Output embedding size: 768--1024
44
+
45
+ Benefits: - strong visual structure representation - self-supervised
46
+ learning
47
+
48
+ ------------------------------------------------------------------------
49
+
50
+ ## 4. Feature Fusion
51
+
52
+ clip_embedding = CLIP(image)\
53
+ dino_embedding = DINO(image)
54
+
55
+ combined_embedding = concat(clip_embedding, dino_embedding)
56
+
57
+ Typical dimension:
58
+
59
+ 1536
60
+
61
+ ------------------------------------------------------------------------
62
+
63
+ ## 5. Graph Design
64
+
65
+ Graph nodes:
66
+
67
+ Object nodes\
68
+ Attribute nodes
69
+
70
+ Example:
71
+
72
+ Objects: chair_1 chair_2 chair_3
73
+
74
+ Attributes: blue broken wooden plastic dirty metal
75
+
76
+ Edges:
77
+
78
+ chair → blue\
79
+ chair → broken\
80
+ chair → plastic
81
+
82
+ Optional attribute relations:
83
+
84
+ plastic ↔ material\
85
+ blue ↔ color\
86
+ broken ↔ damage
87
+
88
+ ------------------------------------------------------------------------
89
+
90
+ ## 6. Node Features
91
+
92
+ ### Object nodes
93
+
94
+ Feature = fused embedding
95
+
96
+ dimension = 1536
97
+
98
+ ### Attribute nodes
99
+
100
+ Option 1 (recommended)
101
+
102
+ Use CLIP text embeddings:
103
+
104
+ "a blue chair"\
105
+ "a broken chair"\
106
+ "a wooden chair"
107
+
108
+ Option 2
109
+
110
+ Learn attribute embeddings (trainable vectors)
111
+
112
+ ------------------------------------------------------------------------
113
+
114
+ ## 7. GNN Model
115
+
116
+ Suggested architecture:
117
+
118
+ GATConv(input_dim,512)\
119
+ ReLU\
120
+ GATConv(512,256)\
121
+ Linear(256,1)
122
+
123
+ Prediction is computed from attribute nodes.
124
+
125
+ ------------------------------------------------------------------------
126
+
127
+ ## 8. Training Objectives
128
+
129
+ ### Attribute Prediction
130
+
131
+ Multi‑label classification
132
+
133
+ Loss:
134
+
135
+ Binary Cross Entropy
136
+
137
+ Example label:
138
+
139
+ chair_1: broken=1\
140
+ blue=0\
141
+ plastic=1
142
+
143
+ ### Contrastive Embedding Loss
144
+
145
+ Encourage clustering by adjectives.
146
+
147
+ Example:
148
+
149
+ Positive pair: blue chair A blue chair B
150
+
151
+ Negative pair: blue chair vs broken chair
152
+
153
+ Loss options: - Triplet loss - Contrastive loss - InfoNCE
154
+
155
+ ------------------------------------------------------------------------
156
+
157
+ ## 9. Datasets
158
+
159
+ ### Visual Genome
160
+
161
+ \~108k images with objects, attributes, and relationships.
162
+
163
+ Example annotation:
164
+
165
+ chair → wooden\
166
+ chair → old
167
+
168
+ Download: https://visualgenome.org
169
+
170
+ ------------------------------------------------------------------------
171
+
172
+ ### Open Images V7
173
+
174
+ \~9M images with detection and attribute labels.
175
+
176
+ Example:
177
+
178
+ chair → plastic\
179
+ chair → old
180
+
181
+ Download: https://storage.googleapis.com/openimages/web/index.html
182
+
183
+ ------------------------------------------------------------------------
184
+
185
+ ### MIT States Dataset
186
+
187
+ Object‑state dataset.
188
+
189
+ Examples:
190
+
191
+ broken chair\
192
+ painted chair\
193
+ clean chair
194
+
195
+ ------------------------------------------------------------------------
196
+
197
+ ### SUN Attribute Dataset
198
+
199
+ Dataset containing \~102 visual attributes.
200
+
201
+ Examples:
202
+
203
+ rusty\
204
+ shiny\
205
+ old\
206
+ colorful
207
+
208
+ ------------------------------------------------------------------------
209
+
210
+ ### COCO Dataset
211
+
212
+ Object detection dataset (\~330k images).
213
+
214
+ Attributes must be manually annotated.
215
+
216
+ Download: https://cocodataset.org
217
+
218
+ ------------------------------------------------------------------------
219
+
220
+ ### LAION‑400M
221
+
222
+ Large image‑text dataset with captions.
223
+
224
+ Example captions:
225
+
226
+ "a broken plastic chair"\
227
+ "a blue chair"
228
+
229
+ Attributes can be extracted using NLP.
230
+
231
+ Download: https://laion.ai
232
+
233
+ ------------------------------------------------------------------------
234
+
235
+ ### ImageNet‑Attribute variants
236
+
237
+ Researchers often annotate ImageNet objects with attributes such as:
238
+
239
+ metal\
240
+ wooden\
241
+ colorful
242
+
243
+ Useful for transfer learning.
244
+
245
+ ------------------------------------------------------------------------
246
+
247
+ ## 10. Data Preparation
248
+
249
+ Dataset pipeline:
250
+
251
+ images ↓ object detection (chair) ↓ extract attributes ↓ build
252
+ object‑attribute graph
253
+
254
+ Example dataset:
255
+
256
+ dataset/ chair_001.jpg chair_002.jpg
257
+
258
+ labels:
259
+
260
+ chair_001.jpg → \[blue,plastic\]\
261
+ chair_002.jpg → \[broken,wooden\]
262
+
263
+ ------------------------------------------------------------------------
264
+
265
+ ## 11. Training Pipeline
266
+
267
+ Image ↓ CLIP encoder ↓ DINOv2 encoder ↓ feature fusion ↓ graph
268
+ construction ↓ GNN forward pass ↓ attribute prediction ↓ loss
269
+ computation ↓ backpropagation
270
+
271
+ ------------------------------------------------------------------------
272
+
273
+ ## 12. Inference Pipeline
274
+
275
+ New Image ↓ CLIP + DINO ↓ embedding fusion ↓ graph node creation ↓ GNN
276
+ inference ↓ attribute scores
277
+
278
+ Example output:
279
+
280
+ broken: 0.91\
281
+ blue: 0.12\
282
+ plastic: 0.87\
283
+ wooden: 0.04
284
+
285
+ ------------------------------------------------------------------------
286
+
287
+ ## 13. Evaluation
288
+
289
+ Metrics:
290
+
291
+ - mean average precision
292
+ - F1 score
293
+ - multi‑label accuracy
294
+
295
+ Embedding analysis:
296
+
297
+ - t‑SNE
298
+ - UMAP
299
+
300
+ Goal: observe clusters based on adjectives.
301
+
302
+ ------------------------------------------------------------------------
303
+
304
+ ## 14. Future Extensions
305
+
306
+ Graph Transformer instead of GNN.
307
+
308
+ Scene graph learning:
309
+
310
+ chair → broken → leg
311
+
312
+ LLM integration to generate descriptions:
313
+
314
+ "This is a broken blue plastic chair."
315
+
316
+ ------------------------------------------------------------------------
317
+
318
+ ## 15. Deliverables
319
+
320
+ - adjective aware embedding model
321
+ - attribute prediction model
322
+ - graph dataset
323
+ - clustering visualizations
324
+
325
+ ------------------------------------------------------------------------
326
+
327
+ ## 16. Summary
328
+
329
+ The system combines:
330
+
331
+ CLIP semantic features\
332
+ DINOv2 visual features\
333
+ Graph neural network reasoning
334
+
335
+ to produce an **embedding space structured by object adjectives**.