Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aloscene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from .renderer import Renderer

from typing import Union


def batch_list(tensors):
return SpatialAugmentedTensor.batch_list(tensors)
Expand All @@ -30,7 +32,7 @@ def render(
views: list,
renderer: str = "cv",
size=None,
record_file: str = None,
record_file: Union[str, None] = None,
fps=30,
grid_size=None,
skip_views=False,
Expand Down
18 changes: 12 additions & 6 deletions aloscene/bounding_boxes_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __new__(
x,
boxes_format: str,
absolute: bool,
labels: Union[dict, Labels] = None,
labels: Union[dict, Labels, None] = None,
frame_size=None,
names=("N", None),
*args,
Expand Down Expand Up @@ -102,7 +102,7 @@ def __new__(
def __init__(self, x, *args, **kwargs):
super().__init__(x)

def append_labels(self, labels: Labels, name: str = None):
def append_labels(self, labels: Labels, name: Union[str, None] = None):
"""Attach a set of labels to the boxes. The attached set of labels are supposed to be equal to the
number of points. In other words, the N dimensions must match in both tensor.
Parameters
Expand Down Expand Up @@ -342,7 +342,7 @@ def rel_pos(self):
tensor.frame_size = None
return tensor

def get_with_format(self, boxes_format: str) :
def get_with_format(self, boxes_format: str):
"""Set boxes into the desired format (Inplace operation)
Parameters
----------
Expand Down Expand Up @@ -425,7 +425,13 @@ def area(self) -> torch.Tensor:

_GLOBAL_COLOR_SET = np.random.uniform(0, 1, (300, 3))

def get_view(self, frame: Tensor = None, size: tuple = None, labels_set: str = None, **kwargs):
def get_view(
self,
frame: Union[Tensor, None] = None,
size: Union[tuple, None] = None,
labels_set: Union[str, None] = None,
**kwargs,
):
"""Create a view of the boxes a frame
Parameters
----------
Expand Down Expand Up @@ -890,7 +896,7 @@ def _spatial_shift(self, shift_y: float, shift_x: float, **kwargs):

return n_boxes

def as_boxes(self, boxes) :
def as_boxes(self, boxes):
"""Convert the current boxes state into the given `boxes` state, following the same `boxes_format`, the same
`frame_size` (if any) and the same `padded_size` (if any).
Parameters
Expand All @@ -915,7 +921,7 @@ def as_boxes(self, boxes) :

return n_boxes

def remove_padding(self) :
def remove_padding(self):
"""This method can be usefull when one use a padded Frame but only want to learn on the non-padded area.
Thefore the target points will remain unpadded while keeping information about the real padded size.
Thus, this method will simply remove the memorized padded information.
Expand Down
4 changes: 2 additions & 2 deletions aloscene/bounding_boxes_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BoundingBoxes3D(aloscene.tensors.AugmentedTensor):
"""

@staticmethod
def __new__(cls, x, labels: Union[dict, Labels] = None, names=("N", None), *args, **kwargs):
def __new__(cls, x, labels: Union[dict, Labels, None] = None, names=("N", None), *args, **kwargs):
tensor = super().__new__(cls, x, *args, names=names, **kwargs)
assert tensor.shape[-1] == 7
tensor.add_child("labels", labels, align_dim=["N"], mergeable=True)
Expand Down Expand Up @@ -441,7 +441,7 @@ def giou3d_with(self, boxes2, enclosing_type="smallest", ret_iou3d=False) -> Uni
"""
return self.giou3d(self, boxes2, enclosing_type, ret_iou3d)

def get_view(self, frame, size: tuple = None, mode: str = "3D", **kwargs) -> View:
def get_view(self, frame, size: Union[tuple, None] = None, mode: str = "3D", **kwargs) -> View:
"""Create a View instance from a Frame

Parameters
Expand Down
10 changes: 5 additions & 5 deletions aloscene/camera_calib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# from __future__ import annotations
from typing import Tuple
from typing import Tuple, Union
from aloscene.tensors.augmented_tensor import AugmentedTensor
import aloscene

Expand Down Expand Up @@ -48,10 +48,10 @@ class CameraIntrinsic(AugmentedTensor):
def __new__(
cls,
x=None,
focal_length: float = None,
plane_size: tuple = None,
principal_point: tuple = None,
skew: tuple = None,
focal_length: Union[float, None] = None,
plane_size: Union[tuple, None] = None,
principal_point: Union[tuple, None] = None,
skew: Union[float, None] = None,
*args,
names=(None, None),
**kwargs,
Expand Down
22 changes: 16 additions & 6 deletions aloscene/depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aloscene.renderer import View
from aloscene.utils.depth_utils import coords2rtheta, add_colorbar
import numpy as np
from typing import Union

from aloscene.io.depth import load_depth

Expand All @@ -35,7 +36,7 @@ class Depth(aloscene.tensors.SpatialAugmentedTensor):
def __new__(
cls,
x,
occlusion: Mask = None,
occlusion: Union[Mask, None] = None,
is_absolute=True,
is_planar=True,
scale=None,
Expand Down Expand Up @@ -166,7 +167,7 @@ def encode_absolute(

return n_depth

def append_occlusion(self, occlusion: Mask, name: str = None):
def append_occlusion(self, occlusion: Mask, name: Union[str, None] = None):
"""Attach an occlusion mask to the depth tensor.

Parameters
Expand Down Expand Up @@ -207,7 +208,9 @@ def __get_view__(

return View(depth_color, title=title)

def as_points3d(self, camera_intrinsic: aloscene.CameraIntrinsic = None, projection=None, distortion=None):
def as_points3d(
self, camera_intrinsic: Union[aloscene.CameraIntrinsic, None] = None, projection=None, distortion=None
):
"""Compute the 3D coordinates of points 2D points based on their respective depth.

Parameters
Expand Down Expand Up @@ -292,7 +295,10 @@ def as_points3d(self, camera_intrinsic: aloscene.CameraIntrinsic = None, project
return aloscene.Points3D(points_3d, names=target_names, device=self.device)

def as_disp(
self, camera_side: str = None, baseline: float = None, camera_intrinsic: aloscene.CameraIntrinsic = None
self,
camera_side: Union[str, None] = None,
baseline: Union[float, None] = None,
camera_intrinsic: Union[aloscene.CameraIntrinsic, None] = None,
):
"""Create a disparity augmented tensor from the current Depth augmented tensor.
To use this method, one must know the target `camera_side` ("left" or "right"). Also, if not set on the
Expand Down Expand Up @@ -344,7 +350,9 @@ def as_disp(
)
return disp

def as_euclidean(self, camera_intrinsic: aloscene.CameraIntrinsic = None, projection=None, distortion=None):
def as_euclidean(
self, camera_intrinsic: Union[aloscene.CameraIntrinsic, None] = None, projection=None, distortion=None
):
"""Create a new Depth augmented tensor whose data is the euclidean depth (distance) from camera to world points.
To use this method, we must know intrinsic matrix of camera, projection model and distortion coefficient
(if exists).
Expand Down Expand Up @@ -384,7 +392,9 @@ def as_euclidean(self, camera_intrinsic: aloscene.CameraIntrinsic = None, projec
euclidean.is_planar = False
return euclidean

def as_planar(self, camera_intrinsic: aloscene.CameraIntrinsic = None, projection=None, distortion=None):
def as_planar(
self, camera_intrinsic: Union[aloscene.CameraIntrinsic, None] = None, projection=None, distortion=None
):
"""Create a new planar depth augmented tensor from the euclidean depth between camera to world points with
corresponding depth. To use this method, we must know intrinsic matrix of camera, projection model and
distortion coefficient (if exists).
Expand Down
17 changes: 9 additions & 8 deletions aloscene/disparity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import matplotlib
import torch
from typing import Union

import aloscene
from aloscene import Mask
Expand Down Expand Up @@ -31,9 +32,9 @@ class Disparity(aloscene.tensors.SpatialAugmentedTensor):
def __new__(
cls,
x,
occlusion: Mask = None,
occlusion: Union[Mask, None] = None,
disp_format="unsigned",
png_negate: bool = None,
png_negate: Union[bool, None] = None,
*args,
names=("C", "H", "W"),
**kwargs,
Expand All @@ -58,7 +59,7 @@ def __new__(
def __init__(self, x, *args, **kwargs):
super().__init__(x)

def append_occlusion(self, occlusion: Mask, name: str = None):
def append_occlusion(self, occlusion: Mask, name: Union[str, None] = None):
"""Attach an occlusion mask to the frame.

Parameters
Expand Down Expand Up @@ -136,7 +137,7 @@ def unsigned(self):
disp = torch.absolute(disp)
return disp

def signed(self, camera_side: str = None):
def signed(self, camera_side: Union[str, None] = None):
"""
Returns a copy of disparity map in signed disparity format
"""
Expand All @@ -154,10 +155,10 @@ def signed(self, camera_side: str = None):

def as_depth(
self,
baseline: float = None,
focal_length: float = None,
camera_side: float = None,
camera_intrinsic: aloscene.CameraIntrinsic = None,
baseline: Union[float, None] = None,
focal_length: Union[float, None] = None,
camera_side: Union[float, None] = None,
camera_intrinsic: Union[aloscene.CameraIntrinsic, None] = None,
max_depth=np.inf,
):
"""Return a Depth augmented tensor based on the given `baseline` & `focal_length`.
Expand Down
5 changes: 3 additions & 2 deletions aloscene/flow.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union
import aloscene
from aloscene import Mask
from aloscene.io.flow import load_flow
Expand All @@ -17,7 +18,7 @@ class Flow(aloscene.tensors.SpatialAugmentedTensor):
"""

@staticmethod
def __new__(cls, x, occlusion: Mask = None, *args, names=("C", "H", "W"), **kwargs):
def __new__(cls, x, occlusion: Union[Mask, None] = None, *args, names=("C", "H", "W"), **kwargs):
if isinstance(x, str):
# load flow from path
x = load_flow(x)
Expand All @@ -29,7 +30,7 @@ def __new__(cls, x, occlusion: Mask = None, *args, names=("C", "H", "W"), **kwar
def __init__(self, x, *args, **kwargs):
super().__init__(x)

def append_occlusion(self, occlusion: Mask, name: str = None):
def append_occlusion(self, occlusion: Mask, name: Union[str, None] = None):
"""Attach an occlusion mask to the frame.

Parameters
Expand Down
40 changes: 20 additions & 20 deletions aloscene/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ class Frame(aloscene.tensors.SpatialAugmentedTensor):
def __new__(
cls,
x,
boxes2d: Union[dict, BoundingBoxes2D] = None,
boxes3d: Union[dict, BoundingBoxes3D] = None,
labels: Union[dict, Labels] = None,
flow: Union[dict, Flow] = None,
segmentation: Union[dict, Mask] = None,
disparity: Union[dict, Disparity] = None,
points2d: Union[dict, Points2D] = None,
points3d: Union[dict, Points3D] = None,
depth: Union[dict, Depth] = None,
boxes2d: Union[dict, BoundingBoxes2D, None] = None,
boxes3d: Union[dict, BoundingBoxes3D, None] = None,
labels: Union[dict, Labels, None] = None,
flow: Union[dict, Flow, None] = None,
segmentation: Union[dict, Mask, None] = None,
disparity: Union[dict, Disparity, None] = None,
points2d: Union[dict, Points2D, None] = None,
points3d: Union[dict, Points3D, None] = None,
depth: Union[dict, Depth, None] = None,
normalization="255",
mean_std=None,
names=("C", "H", "W"),
Expand Down Expand Up @@ -152,7 +152,7 @@ def save(self, tgt_path: str):
"""
torchvision.utils.save_image(self.cpu().norm01().as_tensor(), tgt_path)

def append_labels(self, labels: Labels, name: str = None):
def append_labels(self, labels: Labels, name: Union[str, None] = None):
"""Attach a set of labels to the frame. This can be usefull for classification
or multi label classification. The rank of the label must be >= 1

Expand All @@ -172,7 +172,7 @@ def append_labels(self, labels: Labels, name: str = None):
"""
self._append_child("labels", labels, name)

def append_boxes2d(self, boxes: BoundingBoxes2D, name: str = None):
def append_boxes2d(self, boxes: BoundingBoxes2D, name: Union[str, None] = None):
"""Attach a set of BoundingBoxes2D to the frame.

Parameters
Expand All @@ -197,7 +197,7 @@ def append_boxes2d(self, boxes: BoundingBoxes2D, name: str = None):
"""
self._append_child("boxes2d", boxes, name)

def append_points2d(self, points: Points2D, name: str = None):
def append_points2d(self, points: Points2D, name: Union[str, None] = None):
"""Attach a set of points to the frame.

Parameters
Expand All @@ -210,7 +210,7 @@ def append_points2d(self, points: Points2D, name: str = None):
"""
self._append_child("points2d", points, name)

def append_points3d(self, points_3d: Points3D, name: str = None):
def append_points3d(self, points_3d: Points3D, name: Union[str, None] = None):
"""Attach a set of points to the frame.

Parameters
Expand All @@ -223,7 +223,7 @@ def append_points3d(self, points_3d: Points3D, name: str = None):
"""
self._append_child("points3d", points_3d, name)

def append_boxes3d(self, boxes_3d: BoundingBoxes3D, name: str = None):
def append_boxes3d(self, boxes_3d: BoundingBoxes3D, name: Union[str, None] = None):
"""Attach BoundingBoxes3D to the frame

Parameters
Expand All @@ -247,7 +247,7 @@ def append_boxes3d(self, boxes_3d: BoundingBoxes3D, name: str = None):
"""
self._append_child("boxes3d", boxes_3d, name)

def append_flow(self, flow, name: str = None):
def append_flow(self, flow, name: Union[str, None] = None):
"""Attach a flow to the frame.

Parameters
Expand All @@ -266,7 +266,7 @@ def append_flow(self, flow, name: str = None):
"""
self._append_child("flow", flow, name)

def append_disparity(self, disparity, name: str = None):
def append_disparity(self, disparity, name: Union[str, None] = None):
"""Attach a disparity map to the frame.

Parameters
Expand All @@ -285,7 +285,7 @@ def append_disparity(self, disparity, name: str = None):
"""
self._append_child("disparity", disparity, name)

def append_depth(self, depth, name: str = None):
def append_depth(self, depth, name: Union[str, None] = None):
"""Attach a depth map to the frame.

Parameters
Expand All @@ -304,7 +304,7 @@ def append_depth(self, depth, name: str = None):
"""
self._append_child("depth", depth, name)

def append_segmentation(self, segmentation: Mask, name: str = None):
def append_segmentation(self, segmentation: Mask, name: Union[str, None] = None):
"""Attach a segmentation to the frame.

Parameters
Expand All @@ -318,7 +318,7 @@ def append_segmentation(self, segmentation: Mask, name: str = None):
"""
self._append_child("segmentation", segmentation, name)

def append_pose(self, pose: Pose, name: str = None):
def append_pose(self, pose: Pose, name: Union[str, None] = None):
"""Attach a pose to the frame.

Parameters
Expand All @@ -331,7 +331,7 @@ def append_pose(self, pose: Pose, name: str = None):
"""
self._append_child("pose", pose, name)

def append_scene_flow(self, scene_flow: SceneFlow, name: str = None):
def append_scene_flow(self, scene_flow: SceneFlow, name: Union[str, None] = None):
"""Attach a scene flow to the frame.

Parameters
Expand Down
Loading