Giter Club home page Giter Club logo

gimbal's People

Contributors

ezhang94 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

calebweinreb

gimbal's Issues

`triangulate` is really slow (because of `jax.numpy.linalg.svd`)

I found it was about 10X faster to move to CPU and use the opencv triangulation method. The output is exactly the same...

def opencv_triangulate(Ps, ys, camera_pairs=[]):
    C = len(Ps)
    batch_shape = ys.shape[1:-1]
    if not camera_pairs:
        camera_pairs = [(i,j) for i in range(C) for j in range(i+1, C)]
    Xs = jnp.empty((len(camera_pairs), *batch_shape, 3))
    for i, (c0, c1) in enumerate(camera_pairs):
        Xs = Xs.at[i].set(opencv_triangulate_dlt(Ps[(c0,c1),:,:], ys[(c0,c1),...]))
    return jnp.median(Xs, axis=0)


def opencv_triangulate_dlt(Ps, ys):
    batch_shape = ys.shape[1:-1]
    Ps = np.array(Ps)
    ys = np.array(ys).reshape(2,-1,2)
    X_hom = cv2.triangulatePoints(Ps[0],Ps[1],ys[0].T,ys[1].T)
    X = (X_hom[:3] / X_hom[3]).T.reshape(*batch_shape,3)
    return jnp.array(X)


print('Observations shape:', ys.shape)

t = time.time()
X1 = opencv_triangulate(Ps, ys, camera_pairs=[])
print('Runtime with opencv:', time.time()-t)

t = time.time()
X2 = gimbal.util.triangulate(Ps, ys, camera_pairs=[]).block_until_ready()
print('Runtime with jax:', time.time()-t)

print('Mean squared difference of output:', jnp.nanmean((X1-X2)**2))

Output is

Observations shape: (6, 5000, 23, 2)
Runtime with opencv: 6.574772834777832
Runtime with jax: 68.68624544143677
Mean squared difference of output: 9.889472634621758e-23

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.