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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
eden_fix_missing_repos.py
|
| 3 |
+
Creates the missing CIFAR-10 repos for classic models (test2/test3)
|
| 4 |
+
that were skipped during the initial README generation, then re-uploads
|
| 5 |
+
their CSV logs.
|
| 6 |
+
"""
|
| 7 |
+
from huggingface_hub import HfApi, create_repo, upload_file
|
| 8 |
+
import os, glob
|
| 9 |
+
|
| 10 |
+
TOKEN = os.environ.get("HF_TOKEN", "")
|
| 11 |
+
USER = "Shanmuk4622"
|
| 12 |
+
BASE = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
|
| 14 |
+
api = HfApi(token=TOKEN)
|
| 15 |
+
print(f"Logged in as: {api.whoami()['name']}\n")
|
| 16 |
+
|
| 17 |
+
HARDWARE = {
|
| 18 |
+
"gpu": "NVIDIA GeForce GTX 1080 Ti (11 GB VRAM, 250 W TDP)",
|
| 19 |
+
"cpu": "Intel Xeon W-2125 (4 cores / 8 threads @ 4.00 GHz)",
|
| 20 |
+
"ram": "63.66 GB System RAM",
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# ββ Missing repos: classic models on CIFAR-10 βββββββββββββββββββββββββββββββββ
|
| 24 |
+
MISSING = [
|
| 25 |
+
("AlexNet", "CIFAR-10", "test2", "AlexNet_CIFAR10.py"),
|
| 26 |
+
("DenseNet121","CIFAR-10", "test2", "DenseNet121_CIFAR10.py"),
|
| 27 |
+
("InceptionV3","CIFAR-10", "test2", "InceptionV3_CIFAR10.py"),
|
| 28 |
+
("ResNet18", "CIFAR-10", "test2", "ResNet18_CIFAR10.py"),
|
| 29 |
+
("ResNet50", "CIFAR-10", "test2", "ResNet50_CIFAR10.py"),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
def make_readme(arch, dataset, folder):
|
| 33 |
+
phase = "Baseline β Standard Full Training (Reference Study)"
|
| 34 |
+
technique = (
|
| 35 |
+
"Standard full fine-tuning used as the **Brute-Force Baseline** for "
|
| 36 |
+
"energy comparison. All layers trained from epoch 1 with a fixed learning "
|
| 37 |
+
"rate and no gradient accumulation. Included for transparent EAG benchmarking."
|
| 38 |
+
)
|
| 39 |
+
arch_tag = arch.lower()
|
| 40 |
+
ds_size = "60,000 images β 10 classes (32Γ32 px)"
|
| 41 |
+
|
| 42 |
+
return f"""---
|
| 43 |
+
language: en
|
| 44 |
+
license: apache-2.0
|
| 45 |
+
tags:
|
| 46 |
+
- image-classification
|
| 47 |
+
- green-ai
|
| 48 |
+
- energy-efficiency
|
| 49 |
+
- computer-vision
|
| 50 |
+
- {arch_tag}
|
| 51 |
+
- eden-framework
|
| 52 |
+
- reference-study
|
| 53 |
+
- sustainable-ai
|
| 54 |
+
datasets:
|
| 55 |
+
- cifar10
|
| 56 |
+
metrics:
|
| 57 |
+
- accuracy
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
# EDEN-{arch}-{dataset} β *{phase}*
|
| 61 |
+
|
| 62 |
+
> **Primary KPI:** EAG (Energy-to-Accuracy Gradient) β see Green Delta Table below.
|
| 63 |
+
|
| 64 |
+
## Abstract
|
| 65 |
+
This model is part of **Project EDEN (Energy-Driven Evolution of Networks)**.
|
| 66 |
+
It serves as the **Brute-Force Baseline** for the {arch} architecture on {dataset},
|
| 67 |
+
providing a transparent energy reference for EAG benchmarking against EDEN-optimized models.
|
| 68 |
+
|
| 69 |
+
**Applied Technique:** {phase}
|
| 70 |
+
|
| 71 |
+
## Profiling Environment
|
| 72 |
+
| Component | Specification |
|
| 73 |
+
|---|---|
|
| 74 |
+
| **GPU** | {HARDWARE['gpu']} |
|
| 75 |
+
| **CPU** | {HARDWARE['cpu']} |
|
| 76 |
+
| **RAM** | {HARDWARE['ram']} |
|
| 77 |
+
| **Dataset** | {dataset} β {ds_size} |
|
| 78 |
+
|
| 79 |
+
## π’ Green Delta Table
|
| 80 |
+
*This is the reference baseline. Compare against EDEN-optimized models for EAG.*
|
| 81 |
+
|
| 82 |
+
| Metric | {arch} Baseline | EDEN Optimized | Ξ |
|
| 83 |
+
|---|---|---|---|
|
| 84 |
+
| Accuracy | See CSV log | See SOTA repo | β |
|
| 85 |
+
| Total Energy (J) | See CSV log | See SOTA repo | β |
|
| 86 |
+
| **EAG Score** | β | See SOTA repo | ΞAcc/ΞJoules |
|
| 87 |
+
|
| 88 |
+
## E2AM Algorithm β Applied Phase
|
| 89 |
+
{technique}
|
| 90 |
+
|
| 91 |
+
## Cite This Research
|
| 92 |
+
```bibtex
|
| 93 |
+
@misc{{eden2025,
|
| 94 |
+
title = {{Project EDEN: Energy-Driven Evolution of Networks}},
|
| 95 |
+
author = {{EDEN Research Team}},
|
| 96 |
+
year = {{2025}},
|
| 97 |
+
note = {{Hugging Face: Shanmuk4622}},
|
| 98 |
+
url = {{https://huggingface.co/{USER}}}
|
| 99 |
+
}}
|
| 100 |
+
```
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
def safe_upload(local_path, repo_id, repo_filename):
|
| 104 |
+
try:
|
| 105 |
+
upload_file(
|
| 106 |
+
path_or_fileobj=local_path,
|
| 107 |
+
path_in_repo=repo_filename,
|
| 108 |
+
repo_id=repo_id,
|
| 109 |
+
token=TOKEN,
|
| 110 |
+
repo_type="model",
|
| 111 |
+
)
|
| 112 |
+
print(f" β {repo_filename} β {repo_id}")
|
| 113 |
+
except Exception as e:
|
| 114 |
+
print(f" β {repo_filename} β {repo_id} | {e}")
|
| 115 |
+
|
| 116 |
+
# ββ STEP 1: Create missing repos + upload READMEs βββββββββββββββββββββββββββββ
|
| 117 |
+
print("="*60)
|
| 118 |
+
print("STEP 1 β Creating missing CIFAR-10 repos & READMEs")
|
| 119 |
+
print("="*60)
|
| 120 |
+
|
| 121 |
+
readme_dir = os.path.join(BASE, "hf_readmes")
|
| 122 |
+
os.makedirs(readme_dir, exist_ok=True)
|
| 123 |
+
|
| 124 |
+
for arch, dataset, folder, _ in MISSING:
|
| 125 |
+
repo_name = f"EDEN-{arch}-{dataset}"
|
| 126 |
+
repo_id = f"{USER}/{repo_name}"
|
| 127 |
+
|
| 128 |
+
# Write README locally
|
| 129 |
+
readme_content = make_readme(arch, dataset, folder)
|
| 130 |
+
readme_path = os.path.join(readme_dir, f"{repo_name}_README.md")
|
| 131 |
+
with open(readme_path, "w", encoding="utf-8") as f:
|
| 132 |
+
f.write(readme_content)
|
| 133 |
+
|
| 134 |
+
# Create repo + upload README
|
| 135 |
+
create_repo(repo_id, token=TOKEN, repo_type="model", exist_ok=True, private=False)
|
| 136 |
+
safe_upload(readme_path, repo_id, "README.md")
|
| 137 |
+
|
| 138 |
+
# ββ STEP 2: Re-upload the failed CSVs βββββββββββββββββββββββββββββββββββββββββ
|
| 139 |
+
print("\n" + "="*60)
|
| 140 |
+
print("STEP 2 β Re-uploading failed CIFAR-10 CSV logs")
|
| 141 |
+
print("="*60)
|
| 142 |
+
|
| 143 |
+
def parse_arch_ds(fn):
|
| 144 |
+
fn = fn.lower().replace("\\", "/")
|
| 145 |
+
ds, arch = "unknown", "unknown"
|
| 146 |
+
if "cifar100" in fn: ds = "CIFAR-100"
|
| 147 |
+
elif "cifar10" in fn: ds = "CIFAR-10"
|
| 148 |
+
elif "imagenet" in fn: ds = "Custom-ImageNet300"
|
| 149 |
+
if "efficientnet" in fn: arch = "EfficientNetV2"
|
| 150 |
+
elif "convnext" in fn: arch = "ConvNeXtV2"
|
| 151 |
+
elif "mobilevit" in fn: arch = "MobileViTv3"
|
| 152 |
+
elif "resnet50" in fn: arch = "ResNet50"
|
| 153 |
+
elif "resnet18" in fn: arch = "ResNet18"
|
| 154 |
+
elif "vgg16" in fn: arch = "VGG16"
|
| 155 |
+
elif "alexnet" in fn: arch = "AlexNet"
|
| 156 |
+
elif "inception" in fn: arch = "InceptionV3"
|
| 157 |
+
elif "densenet" in fn: arch = "DenseNet121"
|
| 158 |
+
elif "unet" in fn: arch = "UNet"
|
| 159 |
+
return arch, ds
|
| 160 |
+
|
| 161 |
+
# Only target CIFAR-10 CSVs for classic models
|
| 162 |
+
target_archs = {"AlexNet", "DenseNet121", "InceptionV3", "ResNet18", "ResNet50"}
|
| 163 |
+
|
| 164 |
+
for csv in sorted(glob.glob(os.path.join(BASE, "**", "*.csv"), recursive=True)):
|
| 165 |
+
if any(skip in csv for skip in ["green_ai_", "experiment_summary", "repository"]):
|
| 166 |
+
continue
|
| 167 |
+
arch, ds = parse_arch_ds(csv)
|
| 168 |
+
if arch not in target_archs or ds != "CIFAR-10":
|
| 169 |
+
continue
|
| 170 |
+
repo_id = f"{USER}/EDEN-{arch}-{ds}"
|
| 171 |
+
safe_upload(csv, repo_id, os.path.basename(csv))
|
| 172 |
+
|
| 173 |
+
print("\n" + "="*60)
|
| 174 |
+
print("FIX COMPLETE β Check https://huggingface.co/Shanmuk4622")
|
| 175 |
+
print("="*60)
|