bulkobubulko commited on
Commit
d60b992
·
verified ·
1 Parent(s): 8476088

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. LICENSE.md +13 -0
  2. README.md +20 -0
  3. example_notebook.ipynb +0 -0
  4. params.json +23 -0
  5. script.py +126 -0
LICENSE.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2025 Dmytro Mishkin, Jack Langerman
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ # Handcrafted solution example for the S23DR competition
5
+
6
+ This repo provides a minimalistic example of a wireframe estimation submission to S23DR competition.
7
+ We recommend you take a look at [this example](https://github.com/s23dr/hoho2025/blob/main/hoho2025/example_solutions.py), for detailed code of this submission. It also provides useful I/O and visualization functions.
8
+
9
+ This example seeks to simply provide minimal code which succeeds at reading the dataset and producing a solution (in this case two vertices at the origin and edge of zero length connecting them).
10
+
11
+ `script.py` - is the main file which is run by the competition space. It should produce `submission.parquet` as the result of the run. Please see the additional comments in the `script.py` file.
12
+
13
+
14
+ # How to submit
15
+
16
+ Use the notebook [example_notebook.ipynb](example_notebook.ipynb)
17
+
18
+
19
+
20
+
example_notebook.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
params.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "competition_id": "usm3d/S23DR2025",
3
+ "competition_type": "script",
4
+ "metric": "custom",
5
+ "token": "hf_******",
6
+ "team_id": "xxxxxxxxx_your_team_name_xxxxxxxxxx",
7
+ "submission_id": "xxxxxxxxx_your_sub_id_xxxxxxxxxx",
8
+ "submission_id_col": "order_id",
9
+ "submission_cols": [
10
+ "order_id",
11
+ "wf_vertices",
12
+ "wf_edges",
13
+ "wf_classifications"
14
+ ],
15
+ "submission_rows": 267,
16
+ "output_path": "/tmp/model",
17
+ "submission_repo": "<your submission repo>",
18
+ "time_limit": 7200,
19
+ "dataset": "usm3d/hoho25k_test_x",
20
+ "submission_filenames": [
21
+ "submission.parquet"
22
+ ]
23
+ }
script.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### This is example of the script that will be run in the test environment.
2
+
3
+ ### You can change the rest of the code to define and test your solution.
4
+ ### However, you should not change the signature of the provided function.
5
+ ### The script saves "submission.parquet" file in the current directory.
6
+ ### You can use any additional files and subdirectories to organize your code.
7
+
8
+ from pathlib import Path
9
+ from tqdm import tqdm
10
+ import pandas as pd
11
+ import numpy as np
12
+ from datasets import load_dataset
13
+ from typing import Dict
14
+ from joblib import Parallel, delayed
15
+ import os
16
+ import json
17
+ import gc
18
+ from hoho2025.example_solutions import predict_wireframe
19
+ # check the https://github.com/s23dr/hoho2025/blob/main/hoho2025/example_solutions.py for the example solution
20
+
21
+ def empty_solution():
22
+ '''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
23
+ return np.zeros((2,3)), [(0, 1)]
24
+
25
+ class Sample(Dict):
26
+ def pick_repr_data(self, x):
27
+ if hasattr(x, 'shape'):
28
+ return x.shape
29
+ if isinstance(x, (str, float, int)):
30
+ return x
31
+ if isinstance(x, list):
32
+ return [type(x[0])] if len(x) > 0 else []
33
+ return type(x)
34
+
35
+ def __repr__(self):
36
+ # return str({k: v.shape if hasattr(v, 'shape') else [type(v[0])] if isinstance(v, list) else type(v) for k,v in self.items()})
37
+ return str({k: self.pick_repr_data(v) for k,v in self.items()})
38
+
39
+
40
+ if __name__ == "__main__":
41
+ print ("------------ Loading dataset------------ ")
42
+ param_path = Path('params.json')
43
+ print(param_path)
44
+ with param_path.open() as f:
45
+ params = json.load(f)
46
+ print(params)
47
+ import os
48
+
49
+ print('pwd:')
50
+ os.system('pwd')
51
+ print(os.system('ls -lahtr'))
52
+ print('/tmp/data/')
53
+ print(os.system('ls -lahtr /tmp/data/'))
54
+ print('/tmp/data/data')
55
+ print(os.system('ls -lahtrR /tmp/data/data'))
56
+
57
+
58
+ data_path_test_server = Path('/tmp/data')
59
+ data_path_local = Path().home() / '.cache/huggingface/datasets/usm3d___hoho25k_test_x/'
60
+
61
+ if data_path_test_server.exists():
62
+ # data_path = data_path_test_server
63
+ TEST_ENV = True
64
+ else:
65
+ # data_path = data_path_local
66
+ TEST_ENV = False
67
+ from huggingface_hub import snapshot_download
68
+ _ = snapshot_download(
69
+ repo_id=params['dataset'],
70
+ local_dir="/tmp/data",
71
+ repo_type="dataset",
72
+ )
73
+ data_path = data_path_test_server
74
+
75
+
76
+ print(data_path)
77
+
78
+ # dataset = load_dataset(params['dataset'], trust_remote_code=True, use_auth_token=params['token'])
79
+ # data_files = {
80
+ # "validation": [str(p) for p in [*data_path.rglob('*validation*.arrow')]+[*data_path.rglob('*public*/**/*.tar')]],
81
+ # "test": [str(p) for p in [*data_path.rglob('*test*.arrow')]+[*data_path.rglob('*private*/**/*.tar')]],
82
+ # }
83
+ data_files = {
84
+ "validation": [str(p) for p in data_path.rglob('*public*/**/*.tar')],
85
+ "test": [str(p) for p in data_path.rglob('*private*/**/*.tar')],
86
+ }
87
+ print(data_files)
88
+ dataset = load_dataset(
89
+ str(data_path / 'hoho25k_test_x.py'),
90
+ data_files=data_files,
91
+ trust_remote_code=True,
92
+ writer_batch_size=100
93
+ )
94
+
95
+ print('load with webdataset')
96
+
97
+
98
+ print(dataset, flush=True)
99
+
100
+ print('------------ Now you can do your solution ---------------')
101
+ solution = []
102
+
103
+ def process_sample(sample, i):
104
+ try:
105
+ pred_vertices, pred_edges = predict_wireframe(sample)
106
+ except:
107
+ pred_vertices, pred_edges = empty_solution()
108
+ if i %10 == 0:
109
+ gc.collect()
110
+ return {
111
+ 'order_id': sample['order_id'],
112
+ 'wf_vertices': pred_vertices.tolist(),
113
+ 'wf_edges': pred_edges
114
+ }
115
+ num_cores = 4
116
+
117
+ for subset_name in dataset.keys():
118
+ print (f"Predicting {subset_name}")
119
+ for i, sample in enumerate(tqdm(dataset[subset_name])):
120
+ res = process_sample(sample, i)
121
+ solution.append(res)
122
+
123
+ print('------------ Saving results ---------------')
124
+ sub = pd.DataFrame(solution, columns=["order_id", "wf_vertices", "wf_edges"])
125
+ sub.to_parquet("submission.parquet")
126
+ print("------------ Done ------------ ")