Skip to content

Commit 8337b2f

Browse files
authored
use 32 feats for BEV/voxel by default. Add nfeats arg to PCA block (#27)
1 parent 2424b61 commit 8337b2f

5 files changed

Lines changed: 40 additions & 12 deletions

File tree

config/image_processing/radiov3_siglip2_pca.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
-
99
type: pca
1010
args:
11-
fp: physics_atv_visual_mapping/pca/radio_v3b_siglip2.pt
11+
fp: physics_atv_visual_mapping/pca/radio_v3b_siglip2.pt
12+
n_features: 32

config/terrain_estimation/voxel_to_bev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
type: terrain_aware_bev_feature_splat
8989
args:
9090
metainfo_key: vfm
91-
n_features: 16
91+
n_features: 32
9292
terrain_layer: terrain
9393
terrain_mask_layer: min_elevation_filtered_inflated_mask
9494
overhang: 2.0

physics_atv_visual_mapping/image_processing/processing_blocks/pca.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PCABlock(ImageProcessingBlock):
1111
Block that applies a precomputed PCA to the image
1212
"""
1313

14-
def __init__(self, fp, models_dir, device):
14+
def __init__(self, fp, models_dir, n_features=-1, device='cuda'):
1515
full_fp = os.path.join(models_dir, fp)
1616
pca = torch.load(full_fp, weights_only=False)
1717

@@ -28,6 +28,10 @@ def __init__(self, fp, models_dir, device):
2828
"V": pca["V"].to(device),
2929
}
3030

31+
self.n_features = n_features
32+
33+
assert self.n_features <= self.pca["V"].shape[-1]
34+
3135
def run(self, image, intrinsics, image_orig):
3236
_pmean = self.pca["mean"].view(1, 1, -1)
3337
_pv = self.pca["V"].unsqueeze(0)
@@ -40,11 +44,15 @@ def run(self, image, intrinsics, image_orig):
4044
image.shape[0], _pv.shape[-1], image.shape[2], image.shape[3]
4145
)
4246

47+
if self.n_features >= 0:
48+
img_out = img_out[:, :self.n_features]
49+
4350
return img_out, intrinsics
4451

4552
@property
4653
def output_feature_keys(self):
54+
N = self.pca["V"].shape[-1] if self.n_features == -1 else self.n_features
4755
return FeatureKeyList(
48-
label=[f"{self.base_label}_{i}" for i in range(self.pca["V"].shape[-1])],
49-
metainfo=["vfm" for i in range(self.pca["V"].shape[-1])]
56+
label=[f"{self.base_label}_{i}" for i in range(N)],
57+
metainfo=["vfm" for i in range(N)]
5058
)

scripts/offline_processing/multiproc.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,34 @@
2727
for rdir in sorted(run_dirs):
2828
print('\t' + rdir)
2929

30-
base_cmd = "python3 get_voxel_inpainting_supervision.py --run_dir {}"
30+
# base_cmd = "python3 get_voxel_inpainting_supervision.py --run_dir {}"
31+
32+
base_cmd = "python3 sdf_to_traj.py --run_dir {}"
33+
base_cmd2 = "python3 sdf_to_traj.py --run_dir {} --bev_dir bev_map_inpaint_reduce"
3134

3235
success_dirs = []
3336
fail_dirs = []
3437

3538
for ri, run_dir in enumerate(run_dirs):
3639
print("Proc {} ({}/{})".format(run_dir, ri+1, len(run_dirs)))
3740

38-
# cmd = base_cmd.format(args.config_fp, run_dir)
39-
cmd = base_cmd.format(run_dir)
41+
# cmd = base_cmd.format(run_dir)
42+
43+
# res = subprocess.run(cmd.split(" "))
44+
45+
# if res.returncode == 0:
46+
# success_dirs.append(run_dir)
47+
# else:
48+
# fail_dirs.append(run_dir)
49+
50+
51+
cmd1 = base_cmd.format(run_dir)
52+
cmd2 = base_cmd2.format(run_dir)
4053

41-
res = subprocess.run(cmd.split(" "))
54+
res = subprocess.run(cmd1.split(" "))
55+
res2 = subprocess.run(cmd2.split(" "))
4256

43-
if res.returncode == 0:
57+
if (res.returncode == 0) and (res2.returncode == 0):
4458
success_dirs.append(run_dir)
4559
else:
4660
fail_dirs.append(run_dir)

scripts/offline_processing/sdf_to_traj.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@
5757
mindists = torch.linalg.norm(coords.unsqueeze(1) - poses.unsqueeze(0), dim=-1).min(dim=1)[0]
5858
mindists = mindists.reshape(*metadata.N)
5959

60-
bev_grid.bev_grid.feature_keys += FeatureKeyList(label=['dist_to_traj'], metainfo=['spatial'])
61-
bev_grid.bev_grid.data = torch.cat([bev_grid.bev_grid.data, mindists.unsqueeze(-1)], dim=-1)
60+
## remove spatial if there
61+
idxs = [i for i,k in enumerate(bev_grid.bev_grid.feature_keys.label) if k != 'dist_to_traj']
62+
_fks = bev_grid.bev_grid.feature_keys[idxs]
63+
_data = bev_grid.bev_grid.data[..., idxs]
64+
65+
bev_grid.bev_grid.feature_keys = _fks + FeatureKeyList(label=['dist_to_traj'], metainfo=['spatial'])
66+
bev_grid.bev_grid.data = torch.cat([_data, mindists.unsqueeze(-1)], dim=-1)
6267

6368
bev_grid.to_kitti(bev_dir, i)
6469

0 commit comments

Comments
 (0)