Upload evaluation/main_model_evaluation.py with huggingface_hub
Browse files
evaluation/main_model_evaluation.py
CHANGED
|
@@ -1073,34 +1073,33 @@ class ColorHierarchyEvaluator:
|
|
| 1073 |
|
| 1074 |
# Extract specialized hierarchy embeddings (dims 16-79)
|
| 1075 |
print("\n📝 Extracting specialized text hierarchy embeddings (dims 16-79)...")
|
| 1076 |
-
text_hierarchy_embeddings_spec = text_full_embeddings[:, self.color_emb_dim:self.color_emb_dim+self.hierarchy_emb_dim]
|
| 1077 |
print(f" Specialized text hierarchy embeddings shape: {text_hierarchy_embeddings_spec.shape}")
|
| 1078 |
text_hierarchy_metrics = self.compute_similarity_metrics(text_hierarchy_embeddings_spec, text_hierarchies_full)
|
| 1079 |
# Use ensemble: combine specialized (64D) + full (512D)
|
| 1080 |
text_hierarchy_class = self.evaluate_classification_performance(
|
| 1081 |
text_hierarchy_embeddings_spec, text_hierarchies_full,
|
| 1082 |
"Text Hierarchy Embeddings (Ensemble)", "Hierarchy",
|
| 1083 |
-
full_embeddings=text_full_embeddings, ensemble_weight=
|
| 1084 |
)
|
| 1085 |
text_hierarchy_metrics.update(text_hierarchy_class)
|
| 1086 |
results['text_hierarchy'] = text_hierarchy_metrics
|
| 1087 |
|
| 1088 |
# Image hierarchy embeddings with ensemble
|
| 1089 |
print("\n🖼️ Extracting specialized image hierarchy embeddings (dims 16-79)...")
|
| 1090 |
-
image_hierarchy_embeddings_spec = image_full_embeddings[:, self.color_emb_dim:self.color_emb_dim+self.hierarchy_emb_dim]
|
| 1091 |
print(f" Specialized image hierarchy embeddings shape: {image_hierarchy_embeddings_spec.shape}")
|
| 1092 |
image_hierarchy_metrics = self.compute_similarity_metrics(image_hierarchy_embeddings_spec, image_hierarchies_full)
|
| 1093 |
image_hierarchy_class = self.evaluate_classification_performance(
|
| 1094 |
image_hierarchy_embeddings_spec, image_hierarchies_full,
|
| 1095 |
"Image Hierarchy Embeddings (Ensemble)", "Hierarchy",
|
| 1096 |
-
full_embeddings=image_full_embeddings, ensemble_weight=
|
| 1097 |
)
|
| 1098 |
image_hierarchy_metrics.update(image_hierarchy_class)
|
| 1099 |
results['image_hierarchy'] = image_hierarchy_metrics
|
| 1100 |
|
| 1101 |
# Cleanup
|
| 1102 |
del text_full_embeddings, image_full_embeddings
|
| 1103 |
-
del text_color_embeddings_spec, image_color_embeddings_spec
|
| 1104 |
del text_hierarchy_embeddings_spec, image_hierarchy_embeddings_spec
|
| 1105 |
torch.cuda.empty_cache() if torch.cuda.is_available() else None
|
| 1106 |
|
|
@@ -1165,7 +1164,7 @@ class ColorHierarchyEvaluator:
|
|
| 1165 |
text_color_class = self.evaluate_classification_performance(
|
| 1166 |
text_color_embeddings_spec, text_colors_full,
|
| 1167 |
"Text Color Embeddings (Ensemble)", "Color",
|
| 1168 |
-
full_embeddings=text_full_embeddings, ensemble_weight=
|
| 1169 |
)
|
| 1170 |
text_color_metrics.update(text_color_class)
|
| 1171 |
results['text_color'] = text_color_metrics
|
|
@@ -1178,7 +1177,7 @@ class ColorHierarchyEvaluator:
|
|
| 1178 |
image_color_class = self.evaluate_classification_performance(
|
| 1179 |
image_color_embeddings_spec, image_colors_full,
|
| 1180 |
"Image Color Embeddings (Ensemble)", "Color",
|
| 1181 |
-
full_embeddings=image_full_embeddings, ensemble_weight=
|
| 1182 |
)
|
| 1183 |
image_color_metrics.update(image_color_class)
|
| 1184 |
results['image_color'] = image_color_metrics
|
|
|
|
| 1073 |
|
| 1074 |
# Extract specialized hierarchy embeddings (dims 16-79)
|
| 1075 |
print("\n📝 Extracting specialized text hierarchy embeddings (dims 16-79)...")
|
| 1076 |
+
text_hierarchy_embeddings_spec = text_full_embeddings[:, self.color_emb_dim:self.color_emb_dim+self.hierarchy_emb_dim]
|
| 1077 |
print(f" Specialized text hierarchy embeddings shape: {text_hierarchy_embeddings_spec.shape}")
|
| 1078 |
text_hierarchy_metrics = self.compute_similarity_metrics(text_hierarchy_embeddings_spec, text_hierarchies_full)
|
| 1079 |
# Use ensemble: combine specialized (64D) + full (512D)
|
| 1080 |
text_hierarchy_class = self.evaluate_classification_performance(
|
| 1081 |
text_hierarchy_embeddings_spec, text_hierarchies_full,
|
| 1082 |
"Text Hierarchy Embeddings (Ensemble)", "Hierarchy",
|
| 1083 |
+
full_embeddings=text_full_embeddings, ensemble_weight=1
|
| 1084 |
)
|
| 1085 |
text_hierarchy_metrics.update(text_hierarchy_class)
|
| 1086 |
results['text_hierarchy'] = text_hierarchy_metrics
|
| 1087 |
|
| 1088 |
# Image hierarchy embeddings with ensemble
|
| 1089 |
print("\n🖼️ Extracting specialized image hierarchy embeddings (dims 16-79)...")
|
| 1090 |
+
image_hierarchy_embeddings_spec = image_full_embeddings[:, self.color_emb_dim:self.color_emb_dim+self.hierarchy_emb_dim]
|
| 1091 |
print(f" Specialized image hierarchy embeddings shape: {image_hierarchy_embeddings_spec.shape}")
|
| 1092 |
image_hierarchy_metrics = self.compute_similarity_metrics(image_hierarchy_embeddings_spec, image_hierarchies_full)
|
| 1093 |
image_hierarchy_class = self.evaluate_classification_performance(
|
| 1094 |
image_hierarchy_embeddings_spec, image_hierarchies_full,
|
| 1095 |
"Image Hierarchy Embeddings (Ensemble)", "Hierarchy",
|
| 1096 |
+
full_embeddings=image_full_embeddings, ensemble_weight=1
|
| 1097 |
)
|
| 1098 |
image_hierarchy_metrics.update(image_hierarchy_class)
|
| 1099 |
results['image_hierarchy'] = image_hierarchy_metrics
|
| 1100 |
|
| 1101 |
# Cleanup
|
| 1102 |
del text_full_embeddings, image_full_embeddings
|
|
|
|
| 1103 |
del text_hierarchy_embeddings_spec, image_hierarchy_embeddings_spec
|
| 1104 |
torch.cuda.empty_cache() if torch.cuda.is_available() else None
|
| 1105 |
|
|
|
|
| 1164 |
text_color_class = self.evaluate_classification_performance(
|
| 1165 |
text_color_embeddings_spec, text_colors_full,
|
| 1166 |
"Text Color Embeddings (Ensemble)", "Color",
|
| 1167 |
+
full_embeddings=text_full_embeddings, ensemble_weight=1
|
| 1168 |
)
|
| 1169 |
text_color_metrics.update(text_color_class)
|
| 1170 |
results['text_color'] = text_color_metrics
|
|
|
|
| 1177 |
image_color_class = self.evaluate_classification_performance(
|
| 1178 |
image_color_embeddings_spec, image_colors_full,
|
| 1179 |
"Image Color Embeddings (Ensemble)", "Color",
|
| 1180 |
+
full_embeddings=image_full_embeddings, ensemble_weight=1 # 40% specialized, 60% full
|
| 1181 |
)
|
| 1182 |
image_color_metrics.update(image_color_class)
|
| 1183 |
results['image_color'] = image_color_metrics
|