Skip to content

Commit 0256164

Browse files
authored
Turn on ruff linter, fix final 7 bugs (#78)
This PR turns on the linter; we can't merge until we address the final linter bugs. - `ruff` is enabled as a GitHub Action, so that we see errors in the PRs in github format - `ruff` locally is added (with the same version) to `.pre-commit-config.yml`
1 parent 4ceabcf commit 0256164

File tree

7 files changed

+70
-11
lines changed

7 files changed

+70
-11
lines changed

.github/workflows/ruff.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Ruff linter
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
ruff:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-python@v4
16+
with:
17+
python-version: 3.11.5
18+
19+
- uses: chartboost/ruff-action@v1
20+
with:
21+
version: 0.5.4
22+
args: check --output-format github

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ci:
2+
skip: [ruff]
3+
14
repos:
25
- repo: https://github.com/pre-commit/pre-commit-hooks
36
rev: v4.6.0
@@ -10,5 +13,9 @@ repos:
1013
- repo: https://github.com/astral-sh/ruff-pre-commit
1114
rev: v0.5.4
1215
hooks:
16+
- id: ruff
17+
types_or: [ python, pyi ]
18+
args: [ --fix ]
19+
1320
- id: ruff-format
1421
types_or: [ python, pyi ]

demos/differentiable_renderer/patch_tracking/demo_utils.py

+21
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ def transform_from_axis_angle(axis, angle):
6767
vec_transform_axis_angle = jax.vmap(transform_from_axis_angle, (None, 0))
6868

6969

70+
def unproject_depth(depth, intrinsics):
71+
"""Unprojects a depth image into a point cloud.
72+
73+
Args:
74+
depth (jnp.ndarray): The depth image. Shape (H, W)
75+
intrinsics (b.camera.Intrinsics): The camera intrinsics.
76+
Returns:
77+
jnp.ndarray: The point cloud. Shape (H, W, 3)
78+
"""
79+
mask = (depth < intrinsics.far) * (depth > intrinsics.near)
80+
depth = depth * mask + intrinsics.far * (1.0 - mask)
81+
y, x = jnp.mgrid[: depth.shape[0], : depth.shape[1]]
82+
x = (x - intrinsics.cx) / intrinsics.fx
83+
y = (y - intrinsics.cy) / intrinsics.fy
84+
point_cloud_image = jnp.stack([x, y, jnp.ones_like(x)], axis=-1) * depth[:, :, None]
85+
return point_cloud_image
86+
87+
88+
unproject_depth_vec = jax.vmap(unproject_depth, (0, None))
89+
90+
7091
### Convenience wrapper for common code used in demos ###
7192
def get_renderer_boxdata_and_patch():
7293
width = 100

demos/sparse_model/sparse_model_cotracker.py

-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ def viz_params(params, start_t, end_t):
382382
),
383383
)
384384

385-
print(loss_function(SECOND_T, params, cluster_assignments, gt_info))
386-
387385
cluster_assignments = cluster_assignments.at[top_indices].set(
388386
cluster_assignments.max() + 1
389387
)

demos/tracking_online_learning.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ def enumerative_proposal(trace, addressses, key, all_deltas):
244244
# )
245245

246246
# Outliers are AND of the RGB and Depth outlier masks
247-
outler_mask = outliers
248-
rr.log("outliers", rr.Image(jnp.tile((outler_mask * 1.0)[..., None], (1, 1, 3))))
247+
outlier_mask = outliers
248+
rr.log("outliers", rr.Image(jnp.tile((outlier_mask * 1.0)[..., None], (1, 1, 3))))
249249

250250
# Get the point cloud corresponding to the outliers
251251
point_cloud = b3d.xyz_from_depth(trace["observed_rgb_depth"][1], fx, fy, cx, cy)[
252-
outler_mask
252+
outlier_mask
253253
]
254-
point_cloud_colors = trace["observed_rgb_depth"][0][outler_mask]
254+
point_cloud_colors = trace["observed_rgb_depth"][0][outlier_mask]
255255

256256
# Segment the outlier cloud.
257257
assignment = b3d.segment_point_cloud(point_cloud)
@@ -334,9 +334,10 @@ def enumerative_proposal(trace, addressses, key, all_deltas):
334334
)[0]
335335
b3d.rerun_visualize_trace_t(trace, t)
336336
rr.set_time_sequence("frame", t)
337-
outler_mask = jnp.logical_and(rgb_outliers, depth_outliers)
338337

339338
rgb_inliers, rgb_outliers = b3d.get_rgb_inlier_outlier_from_trace(trace)
340339
depth_inliers, depth_outliers = b3d.get_depth_inlier_outlier_from_trace(trace)
341340

342-
rr.log("outliers", rr.Image(jnp.tile((outler_mask * 1.0)[..., None], (1, 1, 3))))
341+
outlier_mask = jnp.logical_and(rgb_outliers, depth_outliers)
342+
343+
rr.log("outliers", rr.Image(jnp.tile((outlier_mask * 1.0)[..., None], (1, 1, 3))))

src/b3d/io/utils.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,15 @@ def video_input_from_mp4(
172172
downsize=1,
173173
reverse_color_channel=False,
174174
):
175+
info = load_video_info(video_fname)
176+
177+
if info is None:
178+
return None
179+
175180
if times is None:
181+
T = info.timesteps
176182
times = np.arange(T, step=step)
177183

178-
info = load_video_info(video_fname)
179184
intr = np.load(intrinsics_fname, allow_pickle=True)
180185
vid = load_video_to_numpy(
181186
video_fname,

src/b3d/renderer/renderer_original.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ def interpolate_fwd(self, attr, rast, faces):
7575
return output, (attr, rast, faces)
7676

7777

78+
# def rasterize_bwd(self, saved_tensors, diffs):
79+
# pos, tri = saved_tensors
80+
# return jnp.zeros_like(pos), jnp.zeros_like(tri)
81+
82+
7883
def interpolate_bwd(self, saved_tensors, diffs):
79-
_attr, _rast, _faces = saved_tensors
80-
return jnp.zeros_like(pos), jnp.zeros_like(tri)
84+
attr, rast, faces = saved_tensors
85+
return jnp.zeros_like(attr), jnp.zeros_like(rast), jnp.zeros_like(faces)
8186

8287

8388
interpolate_prim.defvjp(interpolate_fwd, interpolate_bwd)

0 commit comments

Comments
 (0)