File size: 3,122 Bytes
b759a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da86f7f
b759a14
175ba40
b759a14
 
 
 
 
 
 
 
 
 
 
 
 
da86f7f
b759a14
 
afa0345
175ba40
b759a14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
import sys
import requests

"""
Submission script for the Robustness task.

Submission Requirements (read carefully to avoid automatic rejection):

1. FILE FORMAT
----------------
- The file must be a PyTorch state dict saved as a .pt file.
- Save only the state dict, not the full model instance:
      torch.save(model.state_dict(), "model.pt")  # correct
      torch.save(model, "model.pt")               # wrong

2. MODEL ARCHITECTURE
----------------------
- You must specify the model architecture using the model-name field.
- Allowed values: resnet18, resnet34, resnet50
- The architecture must match the state dict you are submitting.

3. MODEL REQUIREMENTS
----------------------
- Input shape must be (1, 3, 32, 32)
- Output shape must be (1, 9)
- The final fc layer must be replaced to output 9 classes

4. EVALUATION
--------------
- Your model must achieve clean accuracy greater than 50% to be accepted.
- Submissions below this threshold will be automatically rejected.
- Score = 0.5 * clean accuracy + 0.5 * robustness accuracy

5. TECHNICAL LIMITS
--------------------
- Only one submission per group every 60 minutes.
- If your submission fails due to an error on your side, the cooldown is 2 minutes.

Your submission will fail if:
- The file is not a valid .pt state dict
- The model-name does not match the submitted state dict
- The output shape is not (1, 9)
- The input shape is not (1, 3, 32, 32)
- Clean accuracy is below 50%
"""

BASE_URL = "http://34.63.153.158"
API_KEY = "YOUR_API_KEY_HERE"  # replace with your actual API key

MODEL_PATH = "PATH/TO/YOUR/MODEL.pt"  # replace with your actual model path
MODEL_NAME = "resnet18"  # replace with your actual model architecture - resnet18, resnet34, or resnet50

SUBMIT = True  # set to True to enable submission

TASK_ID = "03-robustness" # donot change


def die(msg):
    print(f"{msg}", file=sys.stderr)
    sys.exit(1)


if SUBMIT:
    if not os.path.isfile(MODEL_PATH):
        die(f"File not found: {MODEL_PATH}")

    try:
        with open(MODEL_PATH, "rb") as f:
            files = {"file": (os.path.basename(MODEL_PATH), f, "application/x-pytorch")}
            resp = requests.post(
                f"{BASE_URL}/submit/{TASK_ID}",
                headers={"X-API-Key": API_KEY},
                files=files,
                data={"model_name": MODEL_NAME},
                # timeout=(10, 520),
            )

        try:
            body = resp.json()
        except Exception:
            body = {"raw_text": resp.text}

        if resp.status_code == 413:
            die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")

        resp.raise_for_status()

        print("Successfully submitted.")
        print("Server response:", body)

    except requests.exceptions.RequestException as e:
        detail = getattr(e, "response", None)
        print(f"Submission error: {e}")
        if detail is not None:
            try:
                print("Server response:", detail.json())
            except Exception:
                print("Server response (text):", detail.text)
        sys.exit(1)