Skip to content

Commit

Permalink
Merge https://github.com/argoai/argoverse-api into upgrade-numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminrwilson committed Jul 25, 2021
2 parents 5db8263 + e728aa5 commit e3cd8c1
Show file tree
Hide file tree
Showing 7 changed files with 1,103,149 additions and 16 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ Make sure that you can run `python -c "import argoverse"` in python, and you are
### (optional) Install mayavi
* Some visualizations may require `mayavi`. See instructions on how to install Mayavi [here](https://docs.enthought.com/mayavi/mayavi/installation.html).

### (optional) Stereo tutorial dependencies
* You will need to install four dependencies to run the [stereo tutorial](https://github.com/argoai/argoverse-api/blob/master/demo_usage/competition_stereo_tutorial.ipynb):

* **Open3D**: See instructions on how to install [here](https://github.com/intel-isl/Open3D).
* **OpenCV contrib**: See instructions on how to install [here](https://pypi.org/project/opencv-contrib-python).
* **Plotly**: See instructions on how to install [here](https://github.com/plotly/plotly.py).
* **Numba**: See instructions on how to install [here](http://numba.pydata.org/).

### (optional) Remake the object-oriented label folders
* The `track_labels_amodal` folders contains object-oriented labels (in contrast to per-frame labels in `per_sweep_annotations_amodal` folders. Run following script to remake `track_labels_amodal` folders and fix existing issues:

Expand Down
66 changes: 58 additions & 8 deletions argoverse/evaluation/stereo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from typing import List

import cv2
import disparity_interpolation
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from numba import njit

from argoverse.evaluation.stereo.constants import (
DEFAULT_ABS_ERROR_THRESHOLDS,
Expand Down Expand Up @@ -128,7 +128,8 @@ def accumulate_stereo_metrics(abs_error_thresholds: List[int]) -> pd.DataFrame:
return pd.DataFrame([[0] * num_fields], columns=columns)


def interpolate_disparity(disp: np.ndarray) -> np.ndarray:
@njit(nogil=True) # type: ignore
def interpolate_disparity(disparity: np.ndarray) -> np.ndarray:
"""Interpolate disparity image to inpaint holes.
The predicted disparity map might contain holes which need to be interpolated for a dense result.
Expand All @@ -140,15 +141,64 @@ def interpolate_disparity(disp: np.ndarray) -> np.ndarray:
The expected run time for the Argoverse stereo image with 2056 × 2464 pixels is ~50 ms.
Args:
disp: Array of shape (M, N) representing a float32 single-channel disparity map.
disparity: Array of shape (M, N) representing a float32 single-channel disparity map.
Returns:
disp_interp: Array of shape (M, N) representing a float32 single-channel interpolated disparity map.
disparity: Array of shape (M, N) representing a float32 single-channel interpolated disparity map.
"""
disp[disp == 0] = -1
disp_interp = disparity_interpolation.disparity_interpolator(disp)

return disp_interp
height, width = disparity.shape

disparity = np.where(disparity == 0, -1, disparity) # Set invalid disparities to -1

for v in range(height):
count = 0
for u in range(width):
# If disparity is valid
if disparity[v, u] >= 0:
# At least one pixel requires interpolation
if count >= 1:
# First and last value for interpolation
u1 = u - count
u2 = u - 1
# Set pixel to min disparity
if u1 > 0 and u2 < width - 1:
d_ipol = min(disparity[v, u1 - 1], disparity[v, u2 + 1])
for u_curr in range(u1, u2 + 1):
disparity[v, u_curr] = d_ipol
count = 0
else:
count += 1

# Extrapolate to the left
for u in range(width):
if disparity[v, u] >= 0:
for u2 in range(u):
disparity[v, u2] = disparity[v, u]
break

# Extrapolate to the right
for u in range(width - 1, -1, -1):
if disparity[v, u] >= 0:
for u2 in range(u + 1, width):
disparity[v, u2] = disparity[v, u]
break

for u in range(0, width):
# Extrapolate to the top
for v in range(0, height):
if disparity[v, u] >= 0:
for v2 in range(0, v):
disparity[v2, u] = disparity[v, u]
break

# Extrapolate to the bottom
for v in range(height - 1, -1, -1):
if disparity[v, u] >= 0:
for v2 in range(v + 1, height):
disparity[v2, u] = disparity[v, u]
break

return disparity


def write_disparity_error_image(
Expand Down
2 changes: 2 additions & 0 deletions argoverse/sensor_dataset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ class ArgoverseConfig(SensorDatasetConfig):
ring_rear_right=SensorConfig(RING_CAMERA_HEIGHT, RING_CAMERA_WIDTH, "ring_rear_right"),
stereo_front_left=SensorConfig(STEREO_CAMERA_HEIGHT, STEREO_CAMERA_WIDTH, "stereo_front_left"),
stereo_front_right=SensorConfig(STEREO_CAMERA_HEIGHT, STEREO_CAMERA_WIDTH, "stereo_front_right"),
stereo_front_left_rect=SensorConfig(STEREO_CAMERA_HEIGHT, STEREO_CAMERA_WIDTH, "stereo_front_left_rect"),
stereo_front_right_rect=SensorConfig(STEREO_CAMERA_HEIGHT, STEREO_CAMERA_WIDTH, "stereo_front_right_rect"),
)
Loading

0 comments on commit e3cd8c1

Please sign in to comment.