Skip to content

Conversation

@leshy
Copy link
Contributor

@leshy leshy commented Jan 30, 2026

Remove CUDA/CuPy backend and consolidate Image into a simple dataclass with NumPy-only data storage.

This CUDA backend was always strictly slower and implementation was horrible and made our Image class barely readable

@greptile-apps
Copy link

greptile-apps bot commented Jan 30, 2026

Greptile Overview

Greptile Summary

Consolidated the Image class from a multi-backend wrapper architecture (supporting both CUDA/CuPy and NumPy backends) into a simple pure-NumPy dataclass implementation.

Key Changes

  • Removed CUDA backend: Deleted 960-line CudaImage.py, AbstractImage.py base class, and NumpyImage.py implementation (2,561 lines total removed)
  • Simplified Image class: Converted to @dataclass with direct NumPy array storage (data: np.ndarray)
  • Preserved API compatibility: Legacy to_cuda/to_gpu parameters are silently ignored in from_numpy() and from_file() methods
  • Updated imports: Changed 9 files to import ImageFormat directly from Image module instead of AbstractImage
  • Removed backend-specific methods: Deleted rectify_image_cpu/cuda variants, consolidated to single rectify_image()
  • Updated depth conversion: Replaced removed to_depth_meters() method with inline conversion logic in object_scene_registration.py
  • Deleted tests: Removed 1,079 lines of backend-specific tests that are no longer applicable

Migration Path

The changes maintain backward compatibility by:

  • Keeping the same public API surface (properties, methods)
  • Silently ignoring legacy CUDA-related parameters
  • Preserving all image format conversions and encoding/decoding methods

Confidence Score: 4/5

  • Safe to merge with minimal risk - well-executed simplification that removes complexity
  • The refactoring is thorough and comprehensive. All imports have been updated, backward compatibility is maintained via parameter ignoring, and no CUDA-specific code remains in the codebase. The score is 4/5 rather than 5/5 because: (1) the removal of 1,079 lines of tests means some edge cases may no longer be covered, and (2) runtime testing would be valuable to confirm the depth conversion logic in object_scene_registration.py works correctly
  • dimos/perception/object_scene_registration.py - verify the manual depth conversion logic matches the behavior of the removed to_depth_meters() method

Important Files Changed

Filename Overview
dimos/msgs/sensor_msgs/Image.py Consolidated Image class from multi-backend wrapper to pure NumPy dataclass, removed CUDA/CuPy backend entirely
dimos/msgs/sensor_msgs/image_impls/AbstractImage.py Deleted AbstractImage base class - no longer needed with single NumPy implementation
dimos/msgs/sensor_msgs/image_impls/CudaImage.py Removed CUDA backend implementation (960 lines deleted)
dimos/perception/common/utils.py Updated rectify_image to work with NumPy-only Image, removed rectify_image_cpu/cuda variants
dimos/perception/object_scene_registration.py Replaced to_depth_meters() call with manual depth conversion logic

Sequence Diagram

sequenceDiagram
    participant User
    participant Image
    participant NumPy
    participant OpenCV
    participant TurboJPEG
    
    Note over Image: Before: Multi-backend (CudaImage/NumpyImage)
    Note over Image: After: Pure NumPy dataclass
    
    User->>Image: from_numpy(np_array)
    Image->>NumPy: np.asarray(data)
    Image-->>User: Image instance
    
    User->>Image: from_file(path)
    Image->>OpenCV: cv2.imread()
    OpenCV-->>Image: numpy array
    Image-->>User: Image instance
    
    User->>Image: to_rgb() / to_bgr()
    Image->>OpenCV: cv2.cvtColor()
    OpenCV-->>Image: converted array
    Image-->>User: new Image
    
    User->>Image: lcm_jpeg_encode()
    Image->>Image: to_bgr()
    Image->>TurboJPEG: encode(bgr_data)
    TurboJPEG-->>Image: jpeg bytes
    Image-->>User: LCM encoded bytes
    
    User->>Image: lcm_jpeg_decode(bytes)
    Image->>TurboJPEG: decode(jpeg_data)
    TurboJPEG-->>Image: bgr array
    Image-->>User: Image instance
    
    Note over Image: All data stored as np.ndarray
    Note over Image: No CUDA/CuPy backend
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@leshy leshy force-pushed the refactor/simplify-image branch from 216b060 to e97da39 Compare January 30, 2026 16:30
- Rewrite Image.py as a simple dataclass with NumPy-only data
- Delete image_impls/ directory (AbstractImage, CudaImage, NumpyImage)
- Remove unused methods (solve_pnp, csrt_tracker, from_depth, to_depth_meters)
- Update all imports across codebase
- Simplify rectify_image to CPU-only path
@leshy leshy force-pushed the refactor/simplify-image branch from e97da39 to c8c564c Compare January 30, 2026 16:32
leshy added 2 commits January 31, 2026 01:04
Fixes mypy no-any-return error by fully typing the ndarray as
np.ndarray[Any, np.dtype[Any]] instead of suppressing with type ignore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants