Denys Rozumnyi commited on
Commit
f816b95
·
1 Parent(s): a83935b
__pycache__/geom_solver.cpython-39.pyc CHANGED
Binary files a/__pycache__/geom_solver.cpython-39.pyc and b/__pycache__/geom_solver.cpython-39.pyc differ
 
__pycache__/my_solution.cpython-39.pyc CHANGED
Binary files a/__pycache__/my_solution.cpython-39.pyc and b/__pycache__/my_solution.cpython-39.pyc differ
 
geom_solver.py CHANGED
@@ -33,6 +33,8 @@ class GeomSolver(object):
33
  width = cameras[1].width
34
  N = len(gestalt_to_colmap_cams)
35
  K = to_K(*human_entry['cameras'][1].params)[None].repeat(N, 0)
 
 
36
  R = np.stack([quaternion_to_rotation_matrix(human_entry['images'][gestalt_to_colmap_cams[ind]].qvec) for ind in range(N)])
37
  T = np.stack([human_entry['images'][gestalt_to_colmap_cams[ind]].tvec for ind in range(N)])
38
 
@@ -97,6 +99,8 @@ class GeomSolver(object):
97
  if closest_nn < kmeans_th:
98
  break
99
  centers = temp_centers
 
 
100
  # image_ids = np.array([p.id for p in points3D.values()])
101
  # pyt_centers = torch.from_numpy(centers).to(device)
102
 
 
33
  width = cameras[1].width
34
  N = len(gestalt_to_colmap_cams)
35
  K = to_K(*human_entry['cameras'][1].params)[None].repeat(N, 0)
36
+ # print(gestalt_to_colmap_cams, N, human_entry['images'])
37
+ print(human_entry['images'].keys())
38
  R = np.stack([quaternion_to_rotation_matrix(human_entry['images'][gestalt_to_colmap_cams[ind]].qvec) for ind in range(N)])
39
  T = np.stack([human_entry['images'][gestalt_to_colmap_cams[ind]].tvec for ind in range(N)])
40
 
 
99
  if closest_nn < kmeans_th:
100
  break
101
  centers = temp_centers
102
+ if centers is None:
103
+ centers = temp_centers
104
  # image_ids = np.array([p.id for p in points3D.values()])
105
  # pyt_centers = torch.from_numpy(centers).to(device)
106
 
my_solution.py CHANGED
@@ -36,8 +36,11 @@ def convert_entry_to_human_readable(entry):
36
 
37
  def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
38
  # return (entry['__key__'], *my_empty_solution())
39
- solver = GeomSolver(entry)
40
- vertices, edges = solver.get_vertices()
 
 
 
41
 
42
  if visualize:
43
  from hoho.viz3d import plot_estimate_and_gt
 
36
 
37
  def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
38
  # return (entry['__key__'], *my_empty_solution())
39
+ # try:
40
+ # solver = GeomSolver(entry)
41
+ # vertices, edges = solver.get_vertices()
42
+ # else:
43
+ vertices, edges = my_empty_solution()
44
 
45
  if visualize:
46
  from hoho.viz3d import plot_estimate_and_gt
script_cuda.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### This is example of the script that will be run in the test environment.
2
+ ### Some parts of the code are compulsory and you should NOT CHANGE THEM.
3
+ ### They are between '''---compulsory---''' comments.
4
+ ### You can change the rest of the code to define and test your solution.
5
+ ### However, you should not change the signature of the provided function.
6
+ ### The script would save "submission.parquet" file in the current directory.
7
+ ### The actual logic of the solution is implemented in the `handcrafted_solution.py` file.
8
+ ### The `handcrafted_solution.py` file is a placeholder for your solution.
9
+ ### You should implement the logic of your solution in that file.
10
+ ### You can use any additional files and subdirectories to organize your code.
11
+
12
+ '''---compulsory---'''
13
+ # import subprocess
14
+ # from pathlib import Path
15
+ # def install_package_from_local_file(package_name, folder='packages'):
16
+ # """
17
+ # Installs a package from a local .whl file or a directory containing .whl files using pip.
18
+
19
+ # Parameters:
20
+ # path_to_file_or_directory (str): The path to the .whl file or the directory containing .whl files.
21
+ # """
22
+ # try:
23
+ # pth = str(Path(folder) / package_name)
24
+ # subprocess.check_call([subprocess.sys.executable, "-m", "pip", "install",
25
+ # "--no-index", # Do not use package index
26
+ # "--find-links", pth, # Look for packages in the specified directory or at the file
27
+ # package_name]) # Specify the package to install
28
+ # print(f"Package installed successfully from {pth}")
29
+ # except subprocess.CalledProcessError as e:
30
+ # print(f"Failed to install package from {pth}. Error: {e}")
31
+
32
+ # install_package_from_local_file('hoho')
33
+
34
+ import hoho; hoho.setup() # YOU MUST CALL hoho.setup() BEFORE ANYTHING ELSE
35
+ # import subprocess
36
+ # import importlib
37
+ # from pathlib import Path
38
+ # import subprocess
39
+
40
+
41
+ # ### The function below is useful for installing additional python wheels.
42
+ # def install_package_from_local_file(package_name, folder='packages'):
43
+ # """
44
+ # Installs a package from a local .whl file or a directory containing .whl files using pip.
45
+
46
+ # Parameters:
47
+ # path_to_file_or_directory (str): The path to the .whl file or the directory containing .whl files.
48
+ # """
49
+ # try:
50
+ # pth = str(Path(folder) / package_name)
51
+ # subprocess.check_call([subprocess.sys.executable, "-m", "pip", "install",
52
+ # "--no-index", # Do not use package index
53
+ # "--find-links", pth, # Look for packages in the specified directory or at the file
54
+ # package_name]) # Specify the package to install
55
+ # print(f"Package installed successfully from {pth}")
56
+ # except subprocess.CalledProcessError as e:
57
+ # print(f"Failed to install package from {pth}. Error: {e}")
58
+
59
+
60
+ # pip download webdataset -d packages/webdataset --platform manylinux1_x86_64 --python-version 38 --only-binary=:all:
61
+ # install_package_from_local_file('webdataset')
62
+ # install_package_from_local_file('tqdm')
63
+
64
+ ### Here you can import any library or module you want.
65
+ ### The code below is used to read and parse the input dataset.
66
+ ### Please, do not modify it.
67
+
68
+ import webdataset as wds
69
+ from tqdm import tqdm
70
+ from typing import Dict
71
+ import pandas as pd
72
+ from transformers import AutoTokenizer
73
+ import os
74
+ import time
75
+ import io
76
+ from PIL import Image as PImage
77
+ import numpy as np
78
+
79
+ from hoho.read_write_colmap import read_cameras_binary, read_images_binary, read_points3D_binary
80
+ from hoho import proc, Sample
81
+
82
+ def convert_entry_to_human_readable(entry):
83
+ out = {}
84
+ already_good = ['__key__', 'wf_vertices', 'wf_edges', 'edge_semantics', 'mesh_vertices', 'mesh_faces', 'face_semantics', 'K', 'R', 't']
85
+ for k, v in entry.items():
86
+ if k in already_good:
87
+ out[k] = v
88
+ continue
89
+ if k == 'points3d':
90
+ out[k] = read_points3D_binary(fid=io.BytesIO(v))
91
+ if k == 'cameras':
92
+ out[k] = read_cameras_binary(fid=io.BytesIO(v))
93
+ if k == 'images':
94
+ out[k] = read_images_binary(fid=io.BytesIO(v))
95
+ if k in ['ade20k', 'gestalt']:
96
+ out[k] = [PImage.open(io.BytesIO(x)).convert('RGB') for x in v]
97
+ if k == 'depthcm':
98
+ out[k] = [PImage.open(io.BytesIO(x)) for x in entry['depthcm']]
99
+ return out
100
+
101
+ '''---end of compulsory---'''
102
+
103
+ ### The part below is used to define and test your solution.
104
+
105
+ from pathlib import Path
106
+ def save_submission(submission, path):
107
+ """
108
+ Saves the submission to a specified path.
109
+
110
+ Parameters:
111
+ submission (List[Dict[]]): The submission to save.
112
+ path (str): The path to save the submission to.
113
+ """
114
+ sub = pd.DataFrame(submission, columns=["__key__", "wf_vertices", "wf_edges"])
115
+ sub.to_parquet(path)
116
+ print(f"Submission saved to {path}")
117
+
118
+ if __name__ == "__main__":
119
+ from my_solution import predict
120
+ print ("------------ Loading dataset------------ ")
121
+ params = hoho.get_params()
122
+ dataset = hoho.get_dataset(decode=None, split='all', dataset_type='webdataset')
123
+
124
+ print('------------ Now you can do your solution ---------------')
125
+ solution = []
126
+ for i, sample in enumerate(tqdm(dataset)):
127
+ key, pred_vertices, pred_edges = predict(sample)
128
+ solution.append({
129
+ '__key__': key,
130
+ 'wf_vertices': pred_vertices.tolist(),
131
+ 'wf_edges': pred_edges
132
+ })
133
+ if i % 100 == 0:
134
+ # incrementally save the results in case we run out of time
135
+ print(f"Processed {i} samples")
136
+ # save_submission(solution, Path(params['output_path']) / "submission.parquet")
137
+ print('------------ Saving results ---------------')
138
+ save_submission(solution, Path(params['output_path']) / "submission.parquet")
139
+ print("------------ Done ------------ ")
testing.ipynb CHANGED
@@ -77,7 +77,7 @@
77
  {
78
  "data": {
79
  "application/vnd.jupyter.widget-view+json": {
80
- "model_id": "3f548919ce4144888673384b58214377",
81
  "version_major": 2,
82
  "version_minor": 0
83
  },
@@ -137,17 +137,17 @@
137
  },
138
  {
139
  "cell_type": "code",
140
- "execution_count": 9,
141
  "id": "70c53366-f1fe-47d7-b815-1eb2f1431f69",
142
  "metadata": {},
143
  "outputs": [
144
  {
145
  "data": {
146
  "text/plain": [
147
- "[]"
148
  ]
149
  },
150
- "execution_count": 9,
151
  "metadata": {},
152
  "output_type": "execute_result"
153
  }
@@ -158,7 +158,7 @@
158
  "# solver = GeomSolver(entry)\n",
159
  "# vertices, edges = solver.get_vertices(True)\n",
160
  "key, vertices, edges = predict(entry)\n",
161
- "vertices.shape\n",
162
  "\n"
163
  ]
164
  },
 
77
  {
78
  "data": {
79
  "application/vnd.jupyter.widget-view+json": {
80
+ "model_id": "85ac5882d0aa416789bacb2b3dc94d36",
81
  "version_major": 2,
82
  "version_minor": 0
83
  },
 
137
  },
138
  {
139
  "cell_type": "code",
140
+ "execution_count": 10,
141
  "id": "70c53366-f1fe-47d7-b815-1eb2f1431f69",
142
  "metadata": {},
143
  "outputs": [
144
  {
145
  "data": {
146
  "text/plain": [
147
+ "'bff985e367e'"
148
  ]
149
  },
150
+ "execution_count": 10,
151
  "metadata": {},
152
  "output_type": "execute_result"
153
  }
 
158
  "# solver = GeomSolver(entry)\n",
159
  "# vertices, edges = solver.get_vertices(True)\n",
160
  "key, vertices, edges = predict(entry)\n",
161
+ "key\n",
162
  "\n"
163
  ]
164
  },