Commit ·
8f748c3
1
Parent(s): 29e5ee8
Update tuned hyperparameters
Browse filesFiles changed (6)
- __pycache__/script.cpython-313.pycAdded
- script.py+6-6
- search_hyperparams.pyAdded+97
- submission.jsonAdded
- test_local.pyAdded+58
- test_local_real.pyAdded+47
14 unmodified lines1516171819202122232425262714 unmodified linesfrom sklearn.cluster import DBSCANfrom hoho2025 import example_solutions as hoho_exampleVERTEX_MERGE_EPS = 0.5EDGE_MIN_LENGTH = 0.5EDGE_MIN_SUPPORT_IMAGES = 2EDGE_MAX_ANGLE_DEG = 25.0VERTEX_MAX_COLMAP_DIST = 4.0VERTEX_MIN_EDGE_DEGREE = 2VERTEX_MIN_VIEW_COUNT = 2def empty_solution(sample):'''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''14 unmodified lines1516171819202122232425262714 unmodified linesfrom sklearn.cluster import DBSCANfrom hoho2025 import example_solutions as hoho_exampleVERTEX_MERGE_EPS = 1.0EDGE_MIN_LENGTH = 0.5EDGE_MIN_SUPPORT_IMAGES = 1EDGE_MAX_ANGLE_DEG = 45.0VERTEX_MAX_COLMAP_DIST = 2.0VERTEX_MIN_EDGE_DEGREE = 1VERTEX_MIN_VIEW_COUNT = 1def empty_solution(sample):'''Return a minimal valid solution, i.e. 2 vertices and 1 edge.'''
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697import ioimport jsonimport numpy as npimport sysimport osimport reimport importlibimport randomfrom datasets import load_datasetfrom hoho2025.metric_helper import hss
print("Loading dataset from Hugging Face streaming (usm3d/hoho22k_2026_trainval)...")dataset = load_dataset('usm3d/hoho22k_2026_trainval', split='train', streaming=True, trust_remote_code=True)# Fetch first 3 samples into memory to speed up searchsamples = []for idx, s in enumerate(dataset): if idx >= 100: break samples.append(s)
def set_hyperparameters(eps, min_len, min_support, max_angle, max_dist, min_degree, min_view): with open('script.py', 'r') as f: content = f.read()
content = re.sub(r'VERTEX_MERGE_EPS = .+', f'VERTEX_MERGE_EPS = {eps}', content) content = re.sub(r'EDGE_MIN_LENGTH = .+', f'EDGE_MIN_LENGTH = {min_len}', content) content = re.sub(r'EDGE_MIN_SUPPORT_IMAGES = .+', f'EDGE_MIN_SUPPORT_IMAGES = {min_support}', content) content = re.sub(r'EDGE_MAX_ANGLE_DEG = .+', f'EDGE_MAX_ANGLE_DEG = {max_angle}', content) content = re.sub(r'VERTEX_MAX_COLMAP_DIST = .+', f'VERTEX_MAX_COLMAP_DIST = {max_dist}', content) content = re.sub(r'VERTEX_MIN_EDGE_DEGREE = .+', f'VERTEX_MIN_EDGE_DEGREE = {min_degree}', content) content = re.sub(r'VERTEX_MIN_VIEW_COUNT = .+', f'VERTEX_MIN_VIEW_COUNT = {min_view}', content)
with open('script.py', 'w') as f: f.write(content)
import script
def evaluate(): importlib.reload(script) scores = [] for sample in samples: try: pred_v, pred_e, _ = script.predict_wireframe_safely(sample) except Exception: pred_v, pred_e = np.zeros((2, 3)), [(0, 1)] gt_v = sample.get('wf_vertices') gt_e = sample.get('wf_edges') res = hss(pred_v, pred_e, gt_v, gt_e) scores.append(res.hss) # Cache cleaning to prevent memory leaks over many trials import gc gc.collect() return sum(scores) / len(scores) if scores else 0
best_score = -1.0best_params = None
# Baseline is around 0.34space = { 'eps': [0.1, 0.5, 1.0], 'min_len': [0.0, 0.2, 0.5], 'min_support': [1, 2], 'max_angle': [25.0, 45.0], 'max_dist': [2.0, 4.0], 'min_degree': [1, 2], 'min_view': [1, 2]}
trials = 50print(f"Running Random Search for {trials} trials...")
for i in range(trials): p = {k: random.choice(v) for k, v in space.items()} set_hyperparameters( p['eps'], p['min_len'], p['min_support'], p['max_angle'], p['max_dist'], p['min_degree'], p['min_view'] ) score = evaluate() print(f"Trial {i+1} Score: {score:.4f} | Params: {p}") if score > best_score: best_score = score best_params = p
print(f"\n--- BEST RESULT ---")print(f"Best HSS Score: {best_score:.4f}")print("Best Parameters:")for k, v in best_params.items(): print(f" {k}: {v}")
# Restore best params to script.pyset_hyperparameters( best_params['eps'], best_params['min_len'], best_params['min_support'], best_params['max_angle'], best_params['max_dist'], best_params['min_degree'], best_params['min_view'])12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import ioimport jsonimport tarfileimport zipfileimport numpy as npimport sysimport osfrom datasets import load_datasetfrom hoho2025.metric_helper import hss
# Import the solution script locallyimport script
print("Loading dataset from local parquet...")dataset = load_dataset('parquet', data_files={"train": "/tmp/data/data/train-00000-of-00002.parquet"})print(f"Loaded {len(dataset['train'])} examples.")
scores = []
for idx, sample in enumerate(dataset['train']): if idx >= 5: # Just test first 5 break
order_id = sample.get('order_id', str(idx)) print(f"\n--- Testing order_id: {order_id} ---") # 1. Evaluate prediction # This will likely fall back to empty_solution due to missing 'gestalt' pred_v, pred_e, _ = script.predict_wireframe_safely(sample)
# 2. Extract Ground Truth from ZIP gt_v = None gt_e = None try: with zipfile.ZipFile(io.BytesIO(sample['data']), "r") as zf: if 'gt_vertices.npy' in zf.namelist(): gt_v = np.load(io.BytesIO(zf.read('gt_vertices.npy'))) if 'gt_edges.npy' in zf.namelist(): gt_e = np.load(io.BytesIO(zf.read('gt_edges.npy'))) except Exception as e: print(f"Failed to read ZIP contents for GT: {e}") continue if gt_v is None or gt_e is None: print("Missing ground truth for this sample.") continue
# 3. Compute HSS metric Score res = hss(pred_v, pred_e, gt_v, gt_e) scores.append(res.hss) print(f"Predicted Vertices: {len(pred_v)} | Predicted Edges: {len(pred_e)}") print(f"GT Vertices: {len(gt_v)} | GT Edges: {len(gt_e)}") print(f"HSS Score: {res.hss:.4f}")
avg_score = sum(scores) / len(scores) if scores else 0print(f"\nAverage HSS Score on subset: {avg_score:.4f}")1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import ioimport jsonimport numpy as npimport sysimport osfrom datasets import load_datasetfrom hoho2025.metric_helper import hss
# Import the solution script locallyimport script
print("Loading dataset from Hugging Face streaming (usm3d/hoho22k_2026_trainval)...")dataset = load_dataset('usm3d/hoho22k_2026_trainval', split='train', streaming=True, trust_remote_code=True)
scores = []
for idx, sample in enumerate(dataset): if idx >= 3: # Just test first 3 (evaluating takes time for 2D parsing) break
order_id = sample.get('order_id', str(idx)) print(f"\n--- Testing order_id: {order_id} ---") # Run the original example solutions baseline from hoho2025 import example_solutions base_v, base_e = example_solutions.predict_wireframe(sample)
# Evaluate user's filtered prediction pred_v, pred_e, _ = script.predict_wireframe_safely(sample)
gt_v = sample.get('wf_vertices') gt_e = sample.get('wf_edges') if gt_v is None or gt_e is None: print("Missing ground truth for this sample.") continue
# 3. Compute HSS metric Score base_res = hss(base_v, base_e, gt_v, gt_e) res = hss(pred_v, pred_e, gt_v, gt_e) scores.append(res.hss) print(f"BASELINE Predict -> Vertices: {len(base_v)} | Edges: {len(base_e)} | HSS: {base_res.hss:.4f}") print(f"FILTERED Predict -> Vertices: {len(pred_v)} | Edges: {len(pred_e)} | HSS: {res.hss:.4f}")
avg_score = sum(scores) / len(scores) if scores else 0print(f"\nAverage FILTERED HSS Score on subset: {avg_score:.4f}")__pycache__/script.cpython-313.pycAdded
script.py+6-6
search_hyperparams.pyAdded+97
submission.jsonAdded
test_local.pyAdded+58
test_local_real.pyAdded+47