Skip to content

Commit

Permalink
Merge pull request #222 from argoai/use-global-constants
Browse files Browse the repository at this point in the history
Import global constants from config
  • Loading branch information
johnwlambert committed May 13, 2021
2 parents de2872c + 37897b6 commit dab09db
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,54 +1,76 @@
SensorDatasetConfig:
_target_: argoverse.sensor_dataset_config.SensorDatasetConfig
dataset_name: argoverse1.1
dataset_name: argoverse-v1.1
ring_cam_fps: 30
stereo_cam_fps: 5

# all ring cameras are `landscape` aspect ratio
sensors:
camera_sensors:
_target_: argoverse.sensor_dataset_config.SensorSuiteConfig

ring_front_center:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_front_center

ring_front_left:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_front_left

ring_front_right:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_front_right

ring_side_left:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_side_left

ring_side_right:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_side_right

ring_rear_left:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_rear_left

ring_rear_right:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 1200
img_width: 1920
name: ring_rear_right

stereo_front_right:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 2056
img_width: 2464
name: stereo_front_right

stereo_front_left:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 2056
img_width: 2464
name: stereo_front_left

# Rectified stereo images
stereo_front_left_rect:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 2056
img_width: 2464
name: stereo_front_left_rect

stereo_front_right_rect:
_target_: argoverse.sensor_dataset_config.SensorConfig
img_height: 2056
img_width: 2464
name: stereo_front_right_rect
59 changes: 37 additions & 22 deletions argoverse/sensor_dataset_config.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
from typing import NamedTuple, Optional
from dataclasses import dataclass
from typing import Optional

import hydra
from hydra.utils import instantiate
from omegaconf import MISSING


class SensorConfig(NamedTuple):
"""Image dimensions for each sensor are provided in pixels."""
@dataclass(frozen=True)
class SensorConfig:
"""Image dimensions for each camera sensor are provided in pixels."""

img_height: int
img_width: int
img_height: int = MISSING
img_width: int = MISSING
name: str = MISSING


class SensorSuiteConfig(NamedTuple):
"""Contains information about image dimensions for each sensor."""
@dataclass(frozen=True)
class SensorSuiteConfig:
"""Contains information about image dimensions for each camera sensor."""

ring_front_center: SensorConfig
ring_front_left: SensorConfig
ring_front_right: SensorConfig
ring_side_left: SensorConfig
ring_side_right: SensorConfig
ring_rear_left: SensorConfig
ring_rear_right: SensorConfig
stereo_front_right: Optional[SensorConfig]
stereo_front_left: Optional[SensorConfig]
ring_front_center: SensorConfig = MISSING
ring_front_left: SensorConfig = MISSING
ring_front_right: SensorConfig = MISSING
ring_side_left: SensorConfig = MISSING
ring_side_right: SensorConfig = MISSING
ring_rear_left: SensorConfig = MISSING
ring_rear_right: SensorConfig = MISSING
stereo_front_right: Optional[SensorConfig] = None
stereo_front_left: Optional[SensorConfig] = None
stereo_front_right_rect: Optional[SensorConfig] = None
stereo_front_left_rect: Optional[SensorConfig] = None

def has_camera(self, camera_name: str) -> bool:
"""Check to see if metadata regarding a camera of interest is present."""
if camera_name not in self.__dict__.keys():
return False
# ensure field is not empty
return getattr(self, camera_name) is not None

class SensorDatasetConfig(NamedTuple):

@dataclass(frozen=True)
class SensorDatasetConfig:
"""Global constants regarding frame rate and image dimensions."""

dataset_name: str
ring_cam_fps: int
stereo_cam_fps: int
sensors: SensorSuiteConfig
dataset_name: str = MISSING
ring_cam_fps: int = MISSING
stereo_cam_fps: int = MISSING
camera_sensors: SensorSuiteConfig = MISSING


DATASET_NAME = "argoverse1.1"
DATASET_NAME = "argoverse-v1.1"

with hydra.initialize_config_module(config_module="argoverse.config"):
cfg = hydra.compose(config_name=f"{DATASET_NAME}.yaml")
Expand Down
16 changes: 4 additions & 12 deletions argoverse/utils/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
CAMERA_LIST,
RECTIFIED_STEREO_CAMERA_LIST,
RING_CAMERA_LIST,
RING_IMG_HEIGHT,
RING_IMG_WIDTH,
STEREO_CAMERA_LIST,
STEREO_IMG_HEIGHT,
STEREO_IMG_WIDTH,
get_image_dims_for_camera,
)
from argoverse.utils.se3 import SE3
from argoverse.utils.transform import quat2rotmat
Expand Down Expand Up @@ -329,14 +326,9 @@ def get_calibration_config(calibration: Dict[str, Any], camera_name: str) -> Cam
camera_extrinsic_matrix = get_camera_extrinsic_matrix(camera_calibration)
camera_intrinsic_matrix = get_camera_intrinsic_matrix(camera_calibration)

if camera_name in STEREO_CAMERA_LIST or camera_name in RECTIFIED_STEREO_CAMERA_LIST:
img_width = STEREO_IMG_WIDTH
img_height = STEREO_IMG_HEIGHT
elif camera_name in RING_CAMERA_LIST:
img_width = RING_IMG_WIDTH
img_height = RING_IMG_HEIGHT
else:
raise ValueError(f"Unknown camera name: {camera_name}")
img_width, img_height = get_image_dims_for_camera(camera_name)
if img_width is None or img_height is None:
raise ValueError(f"Specified camera has unknown dimensions: {camera_name}")

return CameraConfig(
camera_extrinsic_matrix,
Expand Down
17 changes: 6 additions & 11 deletions argoverse/utils/camera_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import logging
from typing import List, Optional, Tuple

from argoverse.sensor_dataset_config import ArgoverseConfig

"""
Since we use images of different sizes (ring vs. stereo), we cannot
fix the image size throughout -- must be adaptive.
"""
STEREO_IMG_WIDTH = 2464
STEREO_IMG_HEIGHT = 2056

RING_IMG_WIDTH = 1920
RING_IMG_HEIGHT = 1200

RING_CAMERA_LIST = [
"ring_front_center",
Expand Down Expand Up @@ -42,12 +39,10 @@ def get_image_dims_for_camera(camera_name: str) -> Tuple[Optional[int], Optional
Returns:
Tuple of [img_width, image_height] in pixels
"""
if camera_name in RING_CAMERA_LIST:
img_width = RING_IMG_WIDTH
img_height = RING_IMG_HEIGHT
elif camera_name in STEREO_CAMERA_LIST:
img_width = STEREO_IMG_WIDTH
img_height = STEREO_IMG_HEIGHT
if ArgoverseConfig.camera_sensors.has_camera(camera_name):
camera_sensor_config = getattr(ArgoverseConfig.camera_sensors, camera_name)
img_width = camera_sensor_config.img_width
img_height = camera_sensor_config.img_height
else:
logger.error(f"{camera_name} not recognized")
return None, None
Expand Down
8 changes: 5 additions & 3 deletions demo_usage/cuboids_to_bboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import cv2
import imageio
import numpy as np
from typing_extensions import Final

from argoverse.data_loading.object_label_record import json_label_dict_to_obj_record
from argoverse.data_loading.simple_track_dataloader import SimpleArgoverseTrackingDataLoader
from argoverse.map_representation.map_api import ArgoverseMap
from argoverse.sensor_dataset_config import ArgoverseConfig
from argoverse.utils.calibration import (
CameraConfig,
get_calibration_config,
Expand All @@ -39,9 +41,9 @@
Number = Union[int, float]

# jigger lane pixel values by [-10,10] range
LANE_COLOR_NOISE = 20
STEREO_FPS = 5
RING_CAM_FPS = 30
LANE_COLOR_NOISE: Final = 20
STEREO_FPS: Final = ArgoverseConfig.stereo_cam_fps
RING_CAM_FPS: Final = ArgoverseConfig.ring_cam_fps


def plot_lane_centerlines_in_img(
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"matplotlib",
"motmetrics==1.1.3",
"numpy==1.19",
"omegaconf==2.1.0.dev26",
"opencv-python>=4.1.0.25",
"pandas>=0.23.1",
"pillow",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_sensor_dataset_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import hydra
from hydra.utils import instantiate

from argoverse.sensor_dataset_config import SensorDatasetConfig


def test_sensor_dataset_config():
"""Ensure that config fields are populated correctly from YAML."""
dataset_name = "argoverse-v1.1"

with hydra.initialize_config_module(config_module="argoverse.config"):
cfg = hydra.compose(config_name=f"{dataset_name}.yaml")
argoverse_config: SensorDatasetConfig = instantiate(cfg.SensorDatasetConfig)

# check a few camera names
assert argoverse_config.camera_sensors.has_camera("ring_rear_left")
assert argoverse_config.camera_sensors.has_camera("stereo_front_left_rect")
assert not argoverse_config.camera_sensors.has_camera("ring_rear_dummyname")

# check sample camera dimensions
assert argoverse_config.camera_sensors.ring_rear_left.img_width == 1920
assert argoverse_config.camera_sensors.ring_rear_left.img_height == 1200

# check other properties
assert argoverse_config.dataset_name == "argoverse-v1.1"
assert argoverse_config.ring_cam_fps == 30
assert argoverse_config.stereo_cam_fps == 5

0 comments on commit dab09db

Please sign in to comment.