IvoHoese commited on
Commit
6cab0d8
·
verified ·
1 Parent(s): f2546ab

Upload task_template.py

Browse files
Files changed (1) hide show
  1. task_template.py +178 -0
task_template.py ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import requests
3
+ import sys
4
+ import os
5
+ import numpy as np
6
+
7
+ # --------------------------------
8
+ # AUXILIARY DATASET
9
+ # --------------------------------
10
+
11
+ """
12
+ Auxiliary dataset contents:
13
+
14
+ -"images": Tensor containing the 1000 images, has shape (1000, 3, 32, 32)
15
+ -"labels": List of true labels for the images, has shape (1000)
16
+ """
17
+
18
+ # Load the dataset
19
+ dataset = torch.load("auxiliary_dataset.pt", weights_only=False)
20
+
21
+ print("Images shape:", dataset["images"].shape)
22
+ print("Labels shape:", dataset["labels"].shape)
23
+ print("First 10 labels:", dataset["labels"][:10])
24
+ print("First image tensor:", dataset["images"][:1])
25
+
26
+ # --------------------------------
27
+ # SUBMISSION FORMAT
28
+ # --------------------------------
29
+
30
+ """
31
+ The submission must be a .npz file of the following format:
32
+
33
+ -"images": Tensor containing the reconstructed images with shape (100, 3, 32, 32).
34
+ These images do not have to be in any particular order.
35
+ The dtype must be float32, with values in [0, 1] range.
36
+ """
37
+
38
+ # Example Submission:
39
+
40
+ reconstructed_images = torch.randint(0, 256, size=(100, 3, 32, 32), dtype=torch.uint8)
41
+
42
+ reconstructed_images = reconstructed_images.float() / 255.0 # normalize to [0, 1] range
43
+
44
+ images_np = reconstructed_images.detach().cpu().numpy()
45
+
46
+ np.savez_compressed("example_submission.npz", images=images_np)
47
+
48
+ # --------------------------------
49
+ # SUBMISSION PROCESS
50
+ # --------------------------------
51
+
52
+ """
53
+ Data Reconstruction Task — Participant Submission Guide
54
+ ========================================================
55
+
56
+ You will upload a single **.npz** file that contains ONLY an array named **'images'**.
57
+ The evaluator will load your file, run shape/dtype checks,
58
+ and then score it by comparing to the training dataset.
59
+
60
+ Follow these rules carefully to avoid automatic rejection.
61
+
62
+ 1) File format
63
+ --------------
64
+ - **Extension:** `.npz` (NumPy compressed archive)
65
+ - **Content:** must contain exactly one required key: `'images'`
66
+ - **Max file size:** 200 MB (hard limit). Larger files are rejected.
67
+
68
+ 2) Array requirements
69
+ ---------------------
70
+ Let `G` be the ground-truth tensor loaded:
71
+
72
+ - **Shape:** `images.shape` must match `G["images"].shape` **exactly**.
73
+ - If `G["images"]` is `(N, 3, H, W)`, your array must also be `(N, 3, H, W)`.
74
+ - No extra samples; no fewer; no different dimensions.
75
+ - **Dtype:** `images.dtype` must match `G["images"].dtype` **exactly**.
76
+ - If the GT uses `float32`, you must submit `float32`.
77
+ - Safe cast example: `images = np.asarray(images, dtype=np.float32)`
78
+ - **Contiguity:** The server will convert to a contiguous Torch tensor; standard NumPy arrays are fine.
79
+
80
+
81
+ 3) Typical failure messages & what they mean
82
+ --------------------------------------------
83
+ - "File must be .npz and contain an 'images' array."
84
+ → Wrong extension or missing `'images'` key.
85
+ - "File too large: X bytes (limit 209715200)."
86
+ → Your file exceeds 200 MB.
87
+ - "Failed to read .npz: ..."
88
+ → The file is corrupted or not a valid `.npz` created with `allow_pickle=False`.
89
+ - "Failed to convert 'images' to torch tensor: ..."
90
+ → Your `'images'` array has an unsupported dtype or structure (e.g., object array).
91
+ - "Submitted images must have shape (N, C, H, W), but got (...)."
92
+ → Shape mismatch with the ground-truth images.
93
+ - "Submitted images must be of type torch.float32, but got torch.float64."
94
+ → Dtype mismatch with the ground-truth images.
95
+ """
96
+
97
+ BASE_URL = "http://35.192.205.84:80"
98
+ API_KEY = "YOUR_API_KEY_HERE"
99
+
100
+ TASK_ID = "12-data-reconstruction"
101
+
102
+ # Path to the .npz file containing the images you want to get logits for
103
+
104
+ QUERY_PATH = "/PATH/FILE.npz"
105
+
106
+ # Path to the .npz file you want to send
107
+
108
+ FILE_PATH = "/PATH/FILE.npz"
109
+
110
+
111
+ GET_LOGITS = False # set True to get logits from the API
112
+ SUBMIT = False # set True to submit your solution
113
+
114
+
115
+ def die(msg):
116
+ print(f"{msg}", file=sys.stderr)
117
+ sys.exit(1)
118
+
119
+ if GET_LOGITS:
120
+
121
+ with open(QUERY_PATH, "rb") as f:
122
+ files = {"npz": (QUERY_PATH, f, "application/octet-stream")}
123
+ response = requests.post(
124
+ f"{BASE_URL}/{TASK_ID}/logits",
125
+ files=files,
126
+ headers={"X-API-Key": API_KEY},
127
+ )
128
+
129
+ if response.status_code == 200:
130
+ data = response.json()
131
+ print("Request successful")
132
+ print(data)
133
+
134
+ else:
135
+ print("Request failed")
136
+ print("Status code:", response.status_code)
137
+ print("Detail:", response.text)
138
+
139
+ if SUBMIT:
140
+ if not os.path.isfile(FILE_PATH):
141
+ die(f"File not found: {FILE_PATH}")
142
+
143
+ try:
144
+ with open(FILE_PATH, "rb") as f:
145
+ files = {
146
+ "file": (os.path.basename(FILE_PATH), f, "application/octet-stream"),
147
+ }
148
+ resp = requests.post(
149
+ f"{BASE_URL}/submit/{TASK_ID}",
150
+ headers={"X-API-Key": API_KEY},
151
+ files=files,
152
+ timeout=(10, 120),
153
+ )
154
+ try:
155
+ body = resp.json()
156
+ except Exception:
157
+ body = {"raw_text": resp.text}
158
+
159
+ if resp.status_code == 413:
160
+ die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")
161
+
162
+ resp.raise_for_status()
163
+
164
+ submission_id = body.get("submission_id")
165
+ print("Successfully submitted.")
166
+ print("Server response:", body)
167
+ if submission_id:
168
+ print(f"Submission ID: {submission_id}")
169
+
170
+ except requests.exceptions.RequestException as e:
171
+ detail = getattr(e, "response", None)
172
+ print(f"Submission error: {e}")
173
+ if detail is not None:
174
+ try:
175
+ print("Server response:", detail.json())
176
+ except Exception:
177
+ print("Server response (text):", detail.text)
178
+ sys.exit(1)