You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shared utility functions and classes used across all shape-completion submodules. Provides I/O, tensor operations, coordinate transforms, camera geometry, logging, configuration helpers, and visualization utilities.
65+ public functions and classes across four modules: utils.py, logging.py, voxelizer.py, and runtime.py.
Load .npy, .npz, mesh, or image data packed inside an HDF5 container
save_command_and_args_to_file(path, args=)
Persist the CLI invocation and parsed arguments to a text file
fromutilsimportload_mesh, save_mesh# Load mesh (auto-detects format, falls back through backends)vertices, faces=load_mesh("model.obj")
vertices, faces=load_mesh("model.ply", load_with="trimesh")
# Save mesh with vertex colorssave_mesh("output.ply", vertices, faces, colors=vertex_colors)
Tensor and Array Operations
Function
Description
to_tensor(x, unsqueeze=, device=)
Convert scalar, list, ndarray, or Tensor to a CUDA/CPU Tensor (recursively handles lists)
to_numpy(x, squeeze=)
Convert Tensor to ndarray (handles GPU, detach, squeeze); passes through non-tensors
to_scalar(x)
Extract a Python scalar from any 0-d Tensor or ndarray
unsqueeze_as(tensor, other)
Unsqueeze trailing dims of tensor to match other's ndim
normalize(val, a=, b=, p_min=, p_max=)
Min-max normalize to [a, b] with optional percentile clipping; works on both Tensor and ndarray
filter_dict(d, keep=, remove=)
Filter a dict by whitelisted or blacklisted key sets
subsample_indices(data, n, replace=)
Random subsample of n indices from data, with optional replacement
Invert a (4,4) or (B,4,4) homogeneous transform; uses R^T when rotation is orthonormal, else full inverse
apply_trafo(points, trafo)
Apply a (4,4) or (B,4,4) rigid transform to (N,3) or (B,N,3) points
look_at(eye, target, up=)
Compute a 4x4 camera pose (inverse extrinsic) in OpenGL convention
convert_coordinates(pts, in_fmt, out_fmt)
Convert 3D point coordinates between "opencv", "opengl", and "blender" conventions
convert_extrinsic(ext, in_fmt, out_fmt)
Convert a 4x4 camera extrinsic between coordinate conventions
pitch_from_trafo(trafo, roll=, degrees=)
Extract pitch angle (x-axis rotation) from a 4x4 transform, correcting for gimbal lock
rot_from_euler(axes, upper_hemisphere)
Random Euler rotation matrix with optional upper-hemisphere constraint
fromutilsimportlook_at, apply_trafo, inv_trafo, convert_coordinatesimportnumpyasnp# Camera look-at matrix (OpenGL convention)cam_pose=look_at(eye=np.array([0, 0, 2]), target=np.array([0, 0, 0]))
# Transform points from camera to world framepoints_world=apply_trafo(points_cam, inv_trafo(cam_pose))
# Convert between coordinate conventionspoints_gl=convert_coordinates(points_cv, "opencv", "opengl")
Supported coordinate conventions:
OpenCV: x-right, y-down, z-forward
OpenGL: x-right, y-up, z-backward
Blender: x-right, y-forward, z-up
Camera and Intrinsic Utilities
Function
Description
invert_intrinsic(K)
Analytically invert a 3x3 intrinsic matrix (fast path for zero-skew case)
adjust_intrinsic(K, width, height, box=, size=)
Adjust intrinsic matrix after crop and/or resize; supports batched K
Log function execution time; also usable as context manager. Supports custom log levels and CUDA sync.
@default_on_exception(default, exceptions=)
Return a default value on exception; logs the error; clears CUDA cache on OOM
@get_args(print_args=)
Capture and optionally print function arguments as a dict
fromutilsimportmeasure_runtime, default_on_exception@measure_runtimedeftrain_epoch():
... # Logs: "train_epoch takes 45.2000s"# Also works as a context managerwithmeasure_runtime("data loading"):
load_data() # Logs: "data loading took 1.2345s"@default_on_exception(default=[], exceptions=(FileNotFoundError, ValueError))defload_data(path):
... # Returns [] on FileNotFoundError or ValueError