Noob: Linear Algebra future for tfjs?

383 views
Skip to first unread message

Owen Densmore

unread,
Jun 5, 2019, 7:36:45 PM6/5/19
to TensorFlow.js Discussion
I'm searching for JS linear algebra libraries and found tfjs which is really tempting with it's huge ecology.

But the key question for me is where the JS TF implementation fits into the larger picture of TF, especially when compared with the python version. Is there interest in closing the gap between the two? Or is tfjs mainly destined to be a subset, although very useful for a large subset of learning problems?

Explicitly, I'd like eigenvalues & vectors, and SVD. The reason is that our team is using several computer vision techniques which use them. The Fundamental Matrix in Epipolar geometry, for example:

Thanks!

   -- Owen

Dirk Toewe

unread,
Jun 6, 2019, 3:34:31 PM6/6/19
to tf...@tensorflow.org

Hi Owen,

to track the state of Linear Algebra in TFJS, You might take a look at the following issue:

https://github.com/tensorflow/tfjs/issues/1516

In the meantime - as long as You don't need gradients - You could use one of the following JS libraries for Eigenvalues and SVD and do the rest in TensorflowJS:


Hope this helps
Dirk

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
Visit this group at https://groups.google.com/a/tensorflow.org/group/tfjs/.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/e0bcd61c-1591-4088-bc79-baf4b0dd1d88%40tensorflow.org.

Owen Densmore

unread,
Jun 7, 2019, 12:06:40 PM6/7/19
to TensorFlow.js Discussion

Thanks Dirk, that's spot on.

Your point about wasm ports of existing libraries is a good one. Most of the python math (numpy etc) are primarily C/Fortran with Python interfaces.

This may be of interest: https://github.com/iodide-project/pyodide 
The Python scientific stack, compiled to WebAssembly.

It provides transparent conversion of objects between Javascript and Python. When inside a browser, this means Python has full access to the Web APIs.
And https://github.com/iodide-project/iodide, it's "parent" notebook project.

I'm not sure the wasm is available in JavaScript or just the port of Python.


   -- Owen

Owen Densmore

unread,
Jun 7, 2019, 12:09:58 PM6/7/19
to TensorFlow.js Discussion

David Sarma

unread,
Jun 7, 2019, 7:31:05 PM6/7/19
to TensorFlow.js Discussion
Thanks for this link, I had been using Iodide notebooks, not realizing how Pyodide could be used independently of the notebook. If this might be helpful to get going with what's in that link, here's a little executable demo of how to round-trip a tensor through Pyodide Numpy: https://codepen.io/ds604/pen/db26a331bacd3e39c5c05a566a238234

<script>
// create js variable to import to python
a = 123
b = tf.tensor([123,456,789]).dataSync()

languagePluginLoader.then(() => {
    pyodide.loadPackage(['numpy','matplotlib']).then(() => {
        pyodide.runPython(`
        import js
        import numpy as np

        # import variable from js
        print(js.a)

        # create variable to send to js
        foo = [x*x for x in range(5)]
        print(foo)

        # create numpy array
        bar = np.array([1,2,3])
        print(bar)

        # import tensor and use with numpy
        b_py = np.array(js.b) + 100
        print(b_py)
        `)

        // get variable from python
        let foo_js = pyodide.pyimport('foo')
        console.log(foo_js)

        // get numpy array from python
        let bar_js = pyodide.pyimport('bar')
        console.log(bar_js)

        // round-trip tensor from python
        let b_js = pyodide.pyimport('b_py')
        tf.tensor(b_js).print()
    })
});
</script>


Reply all
Reply to author
Forward
0 new messages