Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue1038 Index error bugfix using tensor dimension checks, reshaping of tensor dimensions prevents out-of-range errors as well as additional dynamics.py performance optimizations #1049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Nov 12, 2024

  1. Issue1038 Index error bugfix using tensor dimension checks and reshap…

    …ing of tensors prevents out-of-range errors as well as additional dynamics.py performance optimizations.
    
    Resolve the following issues: Index error due to tensor dim mismatch and appears to minimize extra single pixel seeds often encountered in previous masks created with cellpose versions prior to 3.1.0.
    
    Deprecation Warning Resolved:
    
    By replacing .T with .mT and .permute(1, 0), the code adheres to PyTorch's updated tensor manipulation methods, eliminating the deprecation warning and preventing future errors when PyTorch removes support for .T on higher-dimensional tensors.
    IndexError Resolved:
    
    The added dimension checks and reshaping ensure that tensors have the expected number of dimensions before any operations that assume a specific shape. This prevents the IndexError caused by attempting to access non-existent dimensions.
    Enhanced Robustness:
    
    Handling cases with no seeds and adding error logging make the code more robust, allowing it to gracefully manage unexpected input scenarios without crashing.
    Simplified Functionality:
    
    By returning only p from follow_flows, the code eliminates unnecessary data handling and reduces the risk of mismanaging tuple unpacking, thereby streamlining the flow of data through the functions.
    
    dynamics-optimized.py is a drop in replacement for dynamic.py that has further optimizations described below.
    
    Replaced Custom Max Pooling: Leveraged PyTorch's optimized pooling functions (F.max_pool2d, F.max_pool3d) instead of custom implementations to enhance performance and reduce memory usage.
    
    Enhanced Numba Parallelization: Enabled parallel processing in Numba-accelerated functions by setting parallel=True, allowing multi-core CPU utilization for faster computations.
    
    In-Place Tensor Operations: Utilized in-place operations wherever possible to minimize memory overhead and accelerate tensor manipulations.
    
    Reduced CPU-GPU Transfers: Maintained data on the GPU during processing to avoid the latency associated with frequent data transfers between CPU and GPU.
    
    Preallocated and Reused Tensors: Allocated large tensors outside of iterative loops and reused them to improve cache performance and reduce memory allocations.
    derekthirstrup committed Nov 12, 2024
    Configuration menu
    Copy the full SHA
    4b0d706 View commit details
    Browse the repository at this point in the history