maitri01 commited on
Commit
b759a14
·
verified ·
1 Parent(s): f7f7edb

Upload 3 files

Browse files
Files changed (3) hide show
  1. submission.py +98 -0
  2. task_template.py +45 -0
  3. train.npz +3 -0
submission.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import requests
4
+
5
+ """
6
+ Submission script for the Robustness task.
7
+
8
+ Submission Requirements (read carefully to avoid automatic rejection):
9
+
10
+ 1. FILE FORMAT
11
+ ----------------
12
+ - The file must be a PyTorch state dict saved as a .pt file.
13
+ - Save only the state dict, not the full model instance:
14
+ torch.save(model.state_dict(), "model.pt") # correct
15
+ torch.save(model, "model.pt") # wrong
16
+
17
+ 2. MODEL ARCHITECTURE
18
+ ----------------------
19
+ - You must specify the model architecture using the model-name field.
20
+ - Allowed values: resnet18, resnet34, resnet50
21
+ - The architecture must match the state dict you are submitting.
22
+
23
+ 3. MODEL REQUIREMENTS
24
+ ----------------------
25
+ - Input shape must be (1, 3, 32, 32)
26
+ - Output shape must be (1, 9)
27
+ - The final fc layer must be replaced to output 9 classes
28
+
29
+ 4. EVALUATION
30
+ --------------
31
+ - Your model must achieve clean accuracy greater than 50% to be accepted.
32
+ - Submissions below this threshold will be automatically rejected.
33
+ - Score = 0.5 * clean accuracy + 0.5 * robustness accuracy
34
+
35
+ 5. TECHNICAL LIMITS
36
+ --------------------
37
+ - Only one submission per group every 60 minutes.
38
+ - If your submission fails due to an error on your side, the cooldown is 2 minutes.
39
+
40
+ Your submission will fail if:
41
+ - The file is not a valid .pt state dict
42
+ - The model-name does not match the submitted state dict
43
+ - The output shape is not (1, 9)
44
+ - The input shape is not (1, 3, 32, 32)
45
+ - Clean accuracy is below 50%
46
+ """
47
+
48
+ BASE_URL = "http://34.63.153.158"
49
+ API_KEY = "YOUR_API_KEY_HERE" # replace with your actual API key
50
+
51
+ MODEL_PATH = "PATH/TO/YOUR/MODEL.pt" # replace with your actual model path
52
+ MODEL_NAME = "resnet18" # replace with your actual model architecture - resnet18, resnet34, or resnet50
53
+
54
+ SUBMIT = True # set to True to enable submission
55
+
56
+
57
+ def die(msg):
58
+ print(f"{msg}", file=sys.stderr)
59
+ sys.exit(1)
60
+
61
+
62
+ if SUBMIT:
63
+ if not os.path.isfile(MODEL_PATH):
64
+ die(f"File not found: {MODEL_PATH}")
65
+
66
+ try:
67
+ with open(MODEL_PATH, "rb") as f:
68
+ files = {"file": (os.path.basename(MODEL_PATH), f, "application/x-pytorch")}
69
+ resp = requests.post(
70
+ f"{BASE_URL}/robustness",
71
+ headers={"X-API-Key": API_KEY},
72
+ files=files,
73
+ data={"model-name": MODEL_NAME},
74
+ timeout=(10, 120),
75
+ )
76
+
77
+ try:
78
+ body = resp.json()
79
+ except Exception:
80
+ body = {"raw_text": resp.text}
81
+
82
+ if resp.status_code == 413:
83
+ die("Upload rejected: file too large (HTTP 413). Reduce size and try again.")
84
+
85
+ resp.raise_for_status()
86
+
87
+ print("Successfully submitted.")
88
+ print("Server response:", body)
89
+
90
+ except requests.exceptions.RequestException as e:
91
+ detail = getattr(e, "response", None)
92
+ print(f"Submission error: {e}")
93
+ if detail is not None:
94
+ try:
95
+ print("Server response:", detail.json())
96
+ except Exception:
97
+ print("Server response (text):", detail.text)
98
+ sys.exit(1)
task_template.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ import numpy as np
4
+ from torch.utils.data import DataLoader, TensorDataset
5
+ from torchvision.models import resnet18, resnet34, resnet50
6
+
7
+ # the dataset is provided as a .npz file (compressed numpy archive)
8
+ # it contains two arrays:
9
+ # images: uint8 array of shape (N, 3, 32, 32), values in [0, 255]
10
+ # labels: integer class labels in range [0, 8]
11
+ # we divide images by 255.0 to get float values in [0, 1]
12
+
13
+ data = np.load("train.npz")
14
+ images = torch.from_numpy(data["images"]).float() / 255.0
15
+ labels = torch.from_numpy(data["labels"]).long()
16
+
17
+ dataset = TensorDataset(images, labels)
18
+ loader = DataLoader(dataset, batch_size=256, shuffle=True)
19
+
20
+ print("Dataset size:", len(dataset))
21
+ print("Image shape:", images.shape)
22
+ print("Label range:", labels.min().item(), "to", labels.max().item())
23
+
24
+ NUM_CLASSES = 9
25
+
26
+ # pick one of: resnet18, resnet34, resnet50
27
+ model = resnet18(weights=None)
28
+ model.fc = nn.Linear(model.fc.in_features, NUM_CLASSES)
29
+
30
+ # resnet34 example
31
+ # model = resnet34(weights=None)
32
+ # model.fc = nn.Linear(model.fc.in_features, NUM_CLASSES)
33
+
34
+ # resnet50 example
35
+ # model = resnet50(weights=None)
36
+ # model.fc = nn.Linear(model.fc.in_features, NUM_CLASSES)
37
+
38
+ # sanity check -- output shape must be (1, 9)
39
+ model.eval()
40
+ with torch.no_grad():
41
+ out = model(torch.randn(1, 3, 32, 32))
42
+ print("Output shape:", out.shape)
43
+
44
+ # save only the state dict, not the full model instance
45
+ torch.save(model.state_dict(), "model.pt")
train.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e21c23fb3f019cfbbfc59465d0612f4d1fb460016a06727f73ceb53c7da40aab
3
+ size 126604007