Update submission.py
Browse files- submission.py +123 -0
submission.py
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import requests
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# --------------------------------
|
| 8 |
+
# SUBMISSION PROCESS
|
| 9 |
+
# --------------------------------
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
Example submission script for the Stolen Model Detection Task.
|
| 13 |
+
|
| 14 |
+
Submission Requirements (read carefully to avoid automatic rejection):
|
| 15 |
+
|
| 16 |
+
1. CSV FORMAT
|
| 17 |
+
----------------
|
| 18 |
+
- The file **must be a CSV** with extension `.csv`.
|
| 19 |
+
- It must contain **exactly two columns**, named:
|
| 20 |
+
id, score
|
| 21 |
+
→ Column names must match exactly (lowercase, no extra spaces).
|
| 22 |
+
→ Column order does not matter, but both must be present.
|
| 23 |
+
|
| 24 |
+
2. ROW COUNT AND IDENTIFIERS
|
| 25 |
+
-------------------------------
|
| 26 |
+
- Your file must contain **exactly 360 rows**.
|
| 27 |
+
- Each row corresponds to one unique `id` in the range **0–359** (inclusive).
|
| 28 |
+
- Every id must appear **exactly once**.
|
| 29 |
+
- Do **not** add, remove, or rename any IDs.
|
| 30 |
+
- Do **not** include duplicates or missing entries.
|
| 31 |
+
- The evaluator checks:
|
| 32 |
+
id.min() == 0
|
| 33 |
+
id.max() == 359
|
| 34 |
+
id.unique().size == 360
|
| 35 |
+
|
| 36 |
+
3. STEALING CONFIDENCE SCORES
|
| 37 |
+
----------------------
|
| 38 |
+
- The `score` column must contain **numeric values** representing your model’s predicted confidence
|
| 39 |
+
that the corresponding subset is a **stolen** model.
|
| 40 |
+
|
| 41 |
+
Examples of valid score values:
|
| 42 |
+
- Probabilities: values in [0.0, 1.0]
|
| 43 |
+
- Raw model scores: any finite numeric values (will be ranked for TPR@FPR=0.05)
|
| 44 |
+
|
| 45 |
+
- Do **not** submit string labels like "yes"/"no" or "stolen"/"not stolen".
|
| 46 |
+
- The evaluator converts your `score` column to numeric using `pd.to_numeric()`.
|
| 47 |
+
→ Any non-numeric, NaN, or infinite entries will cause automatic rejection.
|
| 48 |
+
|
| 49 |
+
4. TECHNICAL LIMITS
|
| 50 |
+
----------------------
|
| 51 |
+
- Maximum file size: **20 MB**
|
| 52 |
+
- Encoding: UTF-8 recommended.
|
| 53 |
+
- Avoid extra columns, blank lines, or formulas.
|
| 54 |
+
- Ensure all values are numeric and finite.
|
| 55 |
+
- Supported data types: int, float (e.g., float32, float64)
|
| 56 |
+
|
| 57 |
+
5. VALIDATION SUMMARY
|
| 58 |
+
------------------------
|
| 59 |
+
Your submission will fail if:
|
| 60 |
+
- Columns don’t match exactly ("id", "score")
|
| 61 |
+
- Row count differs from 360
|
| 62 |
+
- Any id is missing, duplicated, or outside [0, 359]
|
| 63 |
+
- Any score value is NaN, Inf, or non-numeric
|
| 64 |
+
- File is too large or not a valid CSV
|
| 65 |
+
|
| 66 |
+
One key metric is computed:
|
| 67 |
+
1. **TPR@FPR=0.05 (True Positive Rate at False Positive Rate = 0.05)**
|
| 68 |
+
— measures the ability to correctly identify stolen models while keeping the false positive rate at 5%.
|
| 69 |
+
"""
|
| 70 |
+
BASE_URL = "http://34.63.153.158"
|
| 71 |
+
API_KEY = "YOUR_API_KEY_HERE" # replace with your actual API key
|
| 72 |
+
|
| 73 |
+
TASK_ID = "19-stolen-model-detection"
|
| 74 |
+
FILE_PATH = "PATH/TO/YOUR/SUBMISSION.csv" # replace with your actual file path
|
| 75 |
+
|
| 76 |
+
SUBMIT = True # Set to True to enable submission
|
| 77 |
+
|
| 78 |
+
def die(msg):
|
| 79 |
+
print(f"{msg}", file=sys.stderr)
|
| 80 |
+
sys.exit(1)
|
| 81 |
+
|
| 82 |
+
if SUBMIT:
|
| 83 |
+
if not os.path.isfile(FILE_PATH):
|
| 84 |
+
die(f"File not found: {FILE_PATH}")
|
| 85 |
+
|
| 86 |
+
try:
|
| 87 |
+
with open(FILE_PATH, "rb") as f:
|
| 88 |
+
files = {
|
| 89 |
+
# (fieldname) -> (filename, fileobj, content_type)
|
| 90 |
+
"file": (os.path.basename(FILE_PATH), f, "csv"),
|
| 91 |
+
}
|
| 92 |
+
resp = requests.post(
|
| 93 |
+
f"{BASE_URL}/submit/{TASK_ID}",
|
| 94 |
+
headers={"X-API-Key": API_KEY},
|
| 95 |
+
files=files,
|
| 96 |
+
timeout=(10, 120), # (connect timeout, read timeout)
|
| 97 |
+
)
|
| 98 |
+
# Helpful output even on non-2xx
|
| 99 |
+
try:
|
| 100 |
+
body = resp.json()
|
| 101 |
+
except Exception:
|
| 102 |
+
body = {"raw_text": resp.text}
|
| 103 |
+
|
| 104 |
+
if resp.status_code == 413:
|
| 105 |
+
die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")
|
| 106 |
+
|
| 107 |
+
resp.raise_for_status()
|
| 108 |
+
|
| 109 |
+
submission_id = body.get("submission_id")
|
| 110 |
+
print("Successfully submitted.")
|
| 111 |
+
print("Server response:", body)
|
| 112 |
+
if submission_id:
|
| 113 |
+
print(f"Submission ID: {submission_id}")
|
| 114 |
+
|
| 115 |
+
except requests.exceptions.RequestException as e:
|
| 116 |
+
detail = getattr(e, "response", None)
|
| 117 |
+
print(f"Submission error: {e}")
|
| 118 |
+
if detail is not None:
|
| 119 |
+
try:
|
| 120 |
+
print("Server response:", detail.json())
|
| 121 |
+
except Exception:
|
| 122 |
+
print("Server response (text):", detail.text)
|
| 123 |
+
sys.exit(1)
|