maitri01 commited on
Commit
7c6f54d
·
verified ·
1 Parent(s): e7b5c56

Upload 4 files

Browse files
Files changed (4) hide show
  1. model.pt +3 -0
  2. priv.pt +3 -0
  3. pub.pt +3 -0
  4. task_template.py +131 -0
model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea740792eb2eef9c3372cb0621918c59dc59db2858cdb107d643c5f3eb41422d
3
+ size 44772858
priv.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0bcff62dfaaf44cc9dc30d09f5c3bcdd931e1788cfafdd7e4ee768fb28f6dae7
3
+ size 134968350
pub.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5dfa9e4f69301797806e60ae27b5301ec991749c561a97fb88e185c54b903458
3
+ size 134712490
task_template.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import torch
4
+ import pandas as pd
5
+ import requests
6
+ import random
7
+ import argparse
8
+
9
+ from pathlib import Path
10
+ from torch.utils.data import Dataset
11
+ from torchvision.models import resnet18
12
+
13
+
14
+ # config
15
+ PUB_PATH = "pub.pt"
16
+ PRIV_PATH = "priv.pt"
17
+ MODEL_PATH = "model.pt"
18
+ OUTPUT_CSV = Path("submission.csv")
19
+
20
+ BASE_URL = "http://35.192.205.84:80"
21
+ API_KEY = "YOUR_API_KEY_HERE"
22
+ TASK_ID = "your-mia-task-id"
23
+
24
+
25
+
26
+ # dataset classes
27
+ class TaskDataset(Dataset):
28
+ def __init__(self, transform=None):
29
+ self.ids = []
30
+ self.imgs = []
31
+ self.labels = []
32
+ self.transform = transform
33
+
34
+ def __getitem__(self, index):
35
+ id_ = self.ids[index]
36
+ img = self.imgs[index]
37
+ if self.transform is not None:
38
+ img = self.transform(img)
39
+ label = self.labels[index]
40
+ return id_, img, label
41
+
42
+ def __len__(self):
43
+ return len(self.ids)
44
+
45
+
46
+ class MembershipDataset(TaskDataset):
47
+ def __init__(self, transform=None):
48
+ super().__init__(transform)
49
+ self.membership = []
50
+
51
+ def __getitem__(self, index):
52
+ id_, img, label = super().__getitem__(index)
53
+ return id_, img, label, self.membership[index]
54
+
55
+
56
+ # load datasets
57
+ print("Loading datasets...")
58
+ pub_ds = torch.load(PUB_PATH, weights_only=False)
59
+ priv_ds = torch.load(PRIV_PATH, weights_only=False)
60
+
61
+
62
+ # load model
63
+ print("Loading model...")
64
+ model = resnet18(weights=None)
65
+ model.conv1 = torch.nn.Conv2d(3, 64, 3, 1, 1, bias=False)
66
+ model.maxpool = torch.nn.Identity()
67
+ model.fc = torch.nn.Linear(512, 9)
68
+
69
+ model.load_state_dict(torch.load(MODEL_PATH, map_location="cpu"))
70
+ model.eval()
71
+
72
+
73
+ # create random submission
74
+ print("Creating random submission...")
75
+ ids = [str(i) for i in priv_ds.ids]
76
+
77
+ df = pd.DataFrame({
78
+ "id": ids,
79
+ "score": [random.random() for _ in ids]
80
+ })
81
+
82
+ df.to_csv(OUTPUT_CSV, index=False)
83
+ print("Saved:", OUTPUT_CSV)
84
+
85
+
86
+ # submit
87
+ def die(msg):
88
+ print(msg, file=sys.stderr)
89
+ sys.exit(1)
90
+
91
+ parser = argparse.ArgumentParser(description="Submit a JSONL file to the server.")
92
+ args = parser.parse_args()
93
+
94
+ submit_path = OUTPUT_CSV
95
+
96
+ if not submit_path.exists():
97
+ die(f"File not found: {submit_path}")
98
+
99
+ try:
100
+ with open(submit_path, "rb") as f:
101
+ resp = requests.post(
102
+ f"{BASE_URL}/submit/{TASK_ID}",
103
+ headers={"X-API-Key": API_KEY},
104
+ files={"file": (submit_path.name, f, "application/jsonl")},
105
+ timeout=(10, 600),
106
+ )
107
+ try:
108
+ body = resp.json()
109
+ except Exception:
110
+ body = {"raw_text": resp.text}
111
+
112
+ if resp.status_code == 413:
113
+ die("Upload rejected: file too large (HTTP 413).")
114
+
115
+ resp.raise_for_status()
116
+
117
+ print("Successfully submitted.")
118
+ print("Server response:", body)
119
+ submission_id = body.get("submission_id")
120
+ if submission_id:
121
+ print(f"Submission ID: {submission_id}")
122
+
123
+ except requests.exceptions.RequestException as e:
124
+ detail = getattr(e, "response", None)
125
+ print(f"Submission error: {e}")
126
+ if detail is not None:
127
+ try:
128
+ print("Server response:", detail.json())
129
+ except Exception:
130
+ print("Server response (text):", detail.text)
131
+ sys.exit(1)