Shanmuk4622 commited on
Commit
414d563
Β·
verified Β·
1 Parent(s): cfde47c

Upload eden_upload_weights.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. eden_upload_weights.py +105 -0
eden_upload_weights.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ eden_upload_weights.py
3
+ Uploads .pth model weights to their respective HF repos.
4
+ Skips files already present on HF. Shows size + progress per file.
5
+ """
6
+ from huggingface_hub import HfApi, create_repo, upload_file, list_repo_files
7
+ import os, glob
8
+
9
+ TOKEN = os.environ.get("HF_TOKEN", "")
10
+ USER = "Shanmuk4622"
11
+ BASE = os.path.dirname(os.path.abspath(__file__))
12
+
13
+ api = HfApi(token=TOKEN)
14
+ print(f"Logged in as: {api.whoami()['name']}\n")
15
+
16
+ def parse_arch_ds(fn):
17
+ fn = fn.lower().replace("\\", "/")
18
+ ds, arch = "unknown", "unknown"
19
+ if "cifar100" in fn: ds = "CIFAR-100"
20
+ elif "cifar10" in fn: ds = "CIFAR-10"
21
+ elif "imagenet" in fn: ds = "Custom-ImageNet300"
22
+ if "efficientnet" in fn: arch = "EfficientNetV2"
23
+ elif "convnext" in fn: arch = "ConvNeXtV2"
24
+ elif "mobilevit" in fn: arch = "MobileViTv3"
25
+ elif "resnet50" in fn: arch = "ResNet50"
26
+ elif "resnet18" in fn: arch = "ResNet18"
27
+ elif "vgg16" in fn: arch = "VGG16"
28
+ elif "alexnet" in fn: arch = "AlexNet"
29
+ elif "inception" in fn: arch = "InceptionV3"
30
+ elif "densenet" in fn: arch = "DenseNet121"
31
+ elif "unet" in fn: arch = "UNet"
32
+ return arch, ds
33
+
34
+ def mb(path):
35
+ return os.path.getsize(path) / 1_048_576
36
+
37
+ def already_uploaded(repo_id, filename):
38
+ try:
39
+ files = list(list_repo_files(repo_id, token=TOKEN, repo_type="model"))
40
+ return filename in files
41
+ except:
42
+ return False
43
+
44
+ # ── Collect all .pth files ────────────────────────────────────────────────────
45
+ pth_files = sorted(glob.glob(os.path.join(BASE, "**", "*.pth"), recursive=True))
46
+
47
+ # Build upload plan: (local_path, repo_id, filename)
48
+ plan = []
49
+ skipped_unknown = []
50
+
51
+ for pth in pth_files:
52
+ rel = os.path.relpath(pth, BASE)
53
+ arch, ds = parse_arch_ds(rel)
54
+ if arch == "unknown" or ds == "unknown":
55
+ skipped_unknown.append(rel)
56
+ continue
57
+ repo_id = f"{USER}/EDEN-{arch}-{ds.replace(' ', '-')}"
58
+ filename = os.path.basename(pth)
59
+ plan.append((pth, repo_id, filename, rel))
60
+
61
+ total_mb = sum(mb(p[0]) for p in plan)
62
+ print(f"Files to upload : {len(plan)}")
63
+ print(f"Total size : {total_mb:.1f} MB")
64
+ print(f"Skipped (unknown arch/dataset): {len(skipped_unknown)}")
65
+ if skipped_unknown:
66
+ for s in skipped_unknown:
67
+ print(f" - {s}")
68
+ print()
69
+
70
+ # ── Upload ────────────────────────────────────────────────────────────────────
71
+ ok, skip, fail = 0, 0, 0
72
+
73
+ for i, (local_path, repo_id, filename, rel) in enumerate(plan, 1):
74
+ size = mb(local_path)
75
+ prefix = f"[{i:02d}/{len(plan)}] {filename} ({size:.1f} MB)"
76
+
77
+ # Check if already on HF
78
+ if already_uploaded(repo_id, filename):
79
+ print(f" ⏭ {prefix} β†’ already on HF, skipping")
80
+ skip += 1
81
+ continue
82
+
83
+ try:
84
+ print(f" ⬆ {prefix} β†’ {repo_id} ...")
85
+ upload_file(
86
+ path_or_fileobj=local_path,
87
+ path_in_repo=filename,
88
+ repo_id=repo_id,
89
+ token=TOKEN,
90
+ repo_type="model",
91
+ )
92
+ print(f" βœ“ DONE")
93
+ ok += 1
94
+ except Exception as e:
95
+ print(f" βœ— FAILED: {e}")
96
+ fail += 1
97
+
98
+ print()
99
+ print("="*60)
100
+ print(f"WEIGHTS UPLOAD SUMMARY")
101
+ print(f" Uploaded : {ok}")
102
+ print(f" Skipped : {skip} (already on HF)")
103
+ print(f" Failed : {fail}")
104
+ print(f" Check : https://huggingface.co/{USER}")
105
+ print("="*60)