Delete task_template.py
Browse files- task_template.py +0 -182
task_template.py
DELETED
|
@@ -1,182 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import requests
|
| 3 |
-
import sys
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
# --------------------------------
|
| 7 |
-
# LOADING THE GRADIENTS
|
| 8 |
-
# --------------------------------
|
| 9 |
-
|
| 10 |
-
"""
|
| 11 |
-
Gradient contents (gradients/model{i}.pt):
|
| 12 |
-
|
| 13 |
-
- "gradients": dict {parameter_name -> gradient tensor}, mirroring the
|
| 14 |
-
model's named_parameters()
|
| 15 |
-
- "family": "mlp" or "cnn"
|
| 16 |
-
- "activation": "relu" | "tanh" | "sigmoid"
|
| 17 |
-
- "feature_shape": (C, H, W) of the input to the first fully-connected layer
|
| 18 |
-
- "batch_size": 128
|
| 19 |
-
"""
|
| 20 |
-
|
| 21 |
-
grad = torch.load(os.path.join("gradients", "model1.pt"), weights_only=False)
|
| 22 |
-
print("gradient file keys:", list(grad))
|
| 23 |
-
print(" family:", grad["family"], "| activation:", grad["activation"],
|
| 24 |
-
"| feature_shape:", grad["feature_shape"], "| batch_size:", grad["batch_size"])
|
| 25 |
-
print(" gradient tensors:")
|
| 26 |
-
for name, g in grad["gradients"].items():
|
| 27 |
-
print(f" {name:14} {tuple(g.shape)}")
|
| 28 |
-
|
| 29 |
-
# --------------------------------
|
| 30 |
-
# LOADING THE MODEL (white-box)
|
| 31 |
-
# --------------------------------
|
| 32 |
-
|
| 33 |
-
"""
|
| 34 |
-
Model contents (models/model{i}.pt):
|
| 35 |
-
|
| 36 |
-
A plain state_dict {parameter_name -> weight tensor}
|
| 37 |
-
Further information regarding the model can be found in the corresponding gradient file.
|
| 38 |
-
"""
|
| 39 |
-
|
| 40 |
-
state = torch.load(os.path.join("models", "model1.pt"), weights_only=False)
|
| 41 |
-
print("\nmodel state_dict keys:", list(state))
|
| 42 |
-
for name, w in state.items():
|
| 43 |
-
print(f" {name:14} {tuple(w.shape)}")
|
| 44 |
-
|
| 45 |
-
# --------------------------------
|
| 46 |
-
# SUBMISSION FORMAT
|
| 47 |
-
# --------------------------------
|
| 48 |
-
|
| 49 |
-
"""
|
| 50 |
-
The submission must be a .pt file that torch.load()s to a dict with EXACTLY
|
| 51 |
-
the keys "model1" ... "model10". Each value is a tensor of your reconstructed
|
| 52 |
-
images for that model:
|
| 53 |
-
|
| 54 |
-
- shape: (128, 3, 64, 64)
|
| 55 |
-
- dtype: float32
|
| 56 |
-
- pixel values in the [0, 1] range
|
| 57 |
-
|
| 58 |
-
The 128 images do not have to be in any particular order: each is matched to
|
| 59 |
-
the nearest ground-truth image (one-to-one, no reuse) and scored by SSIM.
|
| 60 |
-
"""
|
| 61 |
-
|
| 62 |
-
# Example submission:
|
| 63 |
-
|
| 64 |
-
submission = {
|
| 65 |
-
f"model{i}": torch.rand(128, 3, 64, 64, dtype=torch.float32) # values in [0, 1]
|
| 66 |
-
for i in range(1, 10 + 1)
|
| 67 |
-
}
|
| 68 |
-
torch.save(submission, "example_submission.pt")
|
| 69 |
-
|
| 70 |
-
# --------------------------------
|
| 71 |
-
# SUBMISSION PROCESS
|
| 72 |
-
# --------------------------------
|
| 73 |
-
|
| 74 |
-
"""
|
| 75 |
-
FL Audit Task — Participant Submission Guide
|
| 76 |
-
========================================================
|
| 77 |
-
|
| 78 |
-
You will upload a single **.pt** file that torch.load()s to a dictionary with
|
| 79 |
-
keys **model1** through **model10**, each mapping to a tensor of 128
|
| 80 |
-
reconstructed images. The evaluator loads your file, runs shape/dtype/range
|
| 81 |
-
checks, and then scores it against the private ground-truth images.
|
| 82 |
-
|
| 83 |
-
Follow these rules carefully to avoid automatic rejection.
|
| 84 |
-
|
| 85 |
-
1) File format
|
| 86 |
-
--------------
|
| 87 |
-
- **Extension:** `.pt` (a Torch-saved dictionary)
|
| 88 |
-
- **Content:** must contain EXACTLY the keys `model1`, `model2`, ..., `model10`
|
| 89 |
-
(no more, no fewer; note: no underscore).
|
| 90 |
-
- **Max file size:** 300 MB (hard limit). Larger files are rejected.
|
| 91 |
-
|
| 92 |
-
2) Per-model tensor requirements
|
| 93 |
-
--------------------------------
|
| 94 |
-
Each value `submission["model{i}"]` must be:
|
| 95 |
-
- **Shape:** exactly `(128, 3, 64, 64)`.
|
| 96 |
-
- **Dtype:** a floating-point tensor (it is cast to float32).
|
| 97 |
-
- **Range:** all pixel values in `[0, 1]`.
|
| 98 |
-
- **Finite:** no NaN or Inf values.
|
| 99 |
-
|
| 100 |
-
3) Scoring
|
| 101 |
-
----------
|
| 102 |
-
For each model your 128 images are matched one-to-one (no reuse) to that model's
|
| 103 |
-
128 private images via a Hungarian assignment that maximises the total SSIM (the
|
| 104 |
-
matching is done per model, not across models). Your score is the mean matched-pair
|
| 105 |
-
SSIM. During the hackathon the leaderboard shows your score on a fixed 30% subset of
|
| 106 |
-
the images; the final ranking uses the held-out 70%.
|
| 107 |
-
|
| 108 |
-
4) Typical failure messages & what they mean
|
| 109 |
-
--------------------------------------------
|
| 110 |
-
- "File extension must be .pt (a torch-saved dict of model1..model10)."
|
| 111 |
-
→ Wrong extension.
|
| 112 |
-
- "Submission must be a dict with keys 'model1'..'model10', got a ..."
|
| 113 |
-
→ The file did not load to a dictionary.
|
| 114 |
-
- "Missing key(s): [...]." / "Unexpected key(s): [...]."
|
| 115 |
-
→ Your keys are not exactly model1..model10.
|
| 116 |
-
- "model{i}: images must have shape (128, 3, 64, 64), got (...)."
|
| 117 |
-
→ Shape mismatch (wrong count or resolution -- remember to upsample to 64x64).
|
| 118 |
-
- "model{i}: images must be a float tensor (dtype ... given)."
|
| 119 |
-
→ Submit float images, not uint8/integers.
|
| 120 |
-
- "model{i}: pixel values must be in [0, 1], got min ... max ..."
|
| 121 |
-
→ Rescale your images into [0, 1].
|
| 122 |
-
- "model{i}: images contain NaN or Inf values."
|
| 123 |
-
→ Clean up invalid values before submitting.
|
| 124 |
-
- "File too large: limit 314572800 bytes."
|
| 125 |
-
→ Your file exceeds 300 MB.
|
| 126 |
-
"""
|
| 127 |
-
|
| 128 |
-
BASE_URL = "http://35.192.205.84"
|
| 129 |
-
API_KEY = "YOUR_API_KEY_HERE"
|
| 130 |
-
|
| 131 |
-
TASK_ID = "21-fl-audit"
|
| 132 |
-
FILE_PATH = "example_submission.pt"
|
| 133 |
-
SUBMIT = False # set True to actually upload FILE_PATH
|
| 134 |
-
|
| 135 |
-
def die(msg):
|
| 136 |
-
print(f"{msg}", file=sys.stderr)
|
| 137 |
-
sys.exit(1)
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
if not SUBMIT:
|
| 141 |
-
print("SUBMIT is False -- set SUBMIT = True (and your API_KEY/FILE_PATH) to upload.")
|
| 142 |
-
sys.exit(0)
|
| 143 |
-
|
| 144 |
-
if not os.path.isfile(FILE_PATH):
|
| 145 |
-
die(f"File not found: {FILE_PATH}")
|
| 146 |
-
|
| 147 |
-
try:
|
| 148 |
-
with open(FILE_PATH, "rb") as f:
|
| 149 |
-
files = {
|
| 150 |
-
"file": (os.path.basename(FILE_PATH), f, "application/octet-stream"),
|
| 151 |
-
}
|
| 152 |
-
resp = requests.post(
|
| 153 |
-
f"{BASE_URL}/submit/{TASK_ID}",
|
| 154 |
-
headers={"X-API-Key": API_KEY},
|
| 155 |
-
files=files,
|
| 156 |
-
timeout=(10, 120),
|
| 157 |
-
)
|
| 158 |
-
try:
|
| 159 |
-
body = resp.json()
|
| 160 |
-
except Exception:
|
| 161 |
-
body = {"raw_text": resp.text}
|
| 162 |
-
|
| 163 |
-
if resp.status_code == 413:
|
| 164 |
-
die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")
|
| 165 |
-
|
| 166 |
-
resp.raise_for_status()
|
| 167 |
-
|
| 168 |
-
submission_id = body.get("submission_id")
|
| 169 |
-
print("Successfully submitted.")
|
| 170 |
-
print("Server response:", body)
|
| 171 |
-
if submission_id:
|
| 172 |
-
print(f"Submission ID: {submission_id}")
|
| 173 |
-
|
| 174 |
-
except requests.exceptions.RequestException as e:
|
| 175 |
-
detail = getattr(e, "response", None)
|
| 176 |
-
print(f"Submission error: {e}")
|
| 177 |
-
if detail is not None:
|
| 178 |
-
try:
|
| 179 |
-
print("Server response:", detail.json())
|
| 180 |
-
except Exception:
|
| 181 |
-
print("Server response (text):", detail.text)
|
| 182 |
-
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|