Git Product home page Git Product logo

Comments (3)

Tiamo666 avatar Tiamo666 commented on September 2, 2024

@michuanhaohao Thanks for your great work.
But I had a suggestion that when compute the shortest distance will cost O(MN) extra space, where M, N is the size of the dist_mat. We can reduce the extra space from O(MN) to O(N). I implemented it as following:

def shortest_path(dist_mat):
    """
    Args:
    dist_mat: pytorch Variable, available shape:
      1) [m, n]
      2) [m, n, N], N is batch size
      3) [m, n, *], * can be arbitrary additional dimensions
      Returns:
    dist: three cases corresponding to `dist_mat`:
      1) scalar
      2) pytorch Tensor, with shape [N]
      3) pytorch Tensor, with shape [*]
    """
    if dist_mat.dim() == 3:
        M, N, B = dist_mat.size()
        helper = torch.zeros(N, B)
    elif dist_mat.dim() == 2:
        M, N = dist.size()
        helper = torch.zeros(N)
    for i in range(M):
        for j in range(N):
            if i == 0 and j == 0:
                helper[j] = dist_mat[i][j]
            elif i == 0:
                helper[j] = helper[j-1] + dist_mat[i][j]
            elif j == 0:
                helper[j] = helper[j] + dist_mat[i][j]
            else:
                helper[j] = torch.min(helper[j-1], helper[j]) + dist_mat[i][j]
    return helper[-1]

I think we can even do better to reduce the extra space to O(min(N, M))

from alignedreid.

michuanhaohao avatar michuanhaohao commented on September 2, 2024

Thank you for you job! If results can be reproduced by your new implementation, you can make a pull request and become a contributor of this project.

from alignedreid.

Tiamo666 avatar Tiamo666 commented on September 2, 2024

OK, but I was a little busy with other things recently, I'll make a pull request if I can reimplement the result.

from alignedreid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.