Tfjs: Can I code Tensorflow Js In Google Colab ?

Created on 5 May 2018  Â·  6Comments  Â·  Source: tensorflow/tfjs

Hi there, I like Tensorflow JS. But I want to use Tensorflow JS in Google Colab for research. Maybe you can explain some solutions. Thank you very much!

Most helpful comment

Colab isn't quite ready for full-fledged JavaScript notebooks. I would
recommend using https://beta.observablehq.com/ for now.

On Sat, May 5, 2018 at 12:32 PM, Timothée Bernard notifications@github.com
wrote:

Hi @LunaLuan https://github.com/LunaLuan, yes it is possible but
currently a little bit tricky.

Taking inspiration from this conversation
https://github.com/googlecolab/colabtools/issues/13, I just created an
example that you can access here: Google Colaboratory + TensorflowJS
example
https://colab.research.google.com/drive/1PH7VCBQHeDbvGi3F3m-pRADRvDxxPfY1
.

Couple of comments:

  • Installed tfjs version is 0.7.0.
  • I invite you to fork this colab and try more complex operations like
    loadModel(), predict() to see how far we can go!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/tfjs/issues/268#issuecomment-386817703,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDLzVHgj04CzXB-0tn3GFkTnhXZkOBrks5tvdQfgaJpZM4TzreX
.

All 6 comments

Hi @LunaLuan, yes it is possible but currently a little bit tricky.

Taking inspiration from this conversation, I just created an example that you can access here: Google Colaboratory + TensorflowJS example.

Currently, you won't be able to fork it and run within your Google Drive but I'll later explain how to proceed (this is the tricky part).

Colab isn't quite ready for full-fledged JavaScript notebooks. I would
recommend using https://beta.observablehq.com/ for now.

On Sat, May 5, 2018 at 12:32 PM, Timothée Bernard notifications@github.com
wrote:

Hi @LunaLuan https://github.com/LunaLuan, yes it is possible but
currently a little bit tricky.

Taking inspiration from this conversation
https://github.com/googlecolab/colabtools/issues/13, I just created an
example that you can access here: Google Colaboratory + TensorflowJS
example
https://colab.research.google.com/drive/1PH7VCBQHeDbvGi3F3m-pRADRvDxxPfY1
.

Couple of comments:

  • Installed tfjs version is 0.7.0.
  • I invite you to fork this colab and try more complex operations like
    loadModel(), predict() to see how far we can go!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/tfjs/issues/268#issuecomment-386817703,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABDLzVHgj04CzXB-0tn3GFkTnhXZkOBrks5tvdQfgaJpZM4TzreX
.

But ObservableHQ doesn't have the GPU advantages of training a model on Google's servers...?

Running TensorFlow.js in Jupyter Notebooks require a special Jupyter kernel
for Node.js (iJavaScript https://github.com/n-riesco/ijavascript). I
haven't figured out a way to install that in Google CoLab directly yet.
However, you can run this from your own Jupyter Notebook environment. See
the thread I posted not long ago on Twitter:
https://twitter.com/sqcai/status/1104475647391481856

On Mon, Apr 8, 2019 at 7:46 AM Erik Katerborg notifications@github.com
wrote:

But ObservableHQ doesn't have the GPU advantages of training a model on
Google's servers...?

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/tensorflow/tfjs/issues/268#issuecomment-480798426,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AQC5fjrAsY7cLWtDZTqlfe1Z-tpV8WObks5veywxgaJpZM4TzreX
.

--

Shanqing Cai
Software Engineer
Google
[email protected]

Docs for importing modules into your JavaScript Notebook once setup

Working on an iPad Pro today and managed to get this going. Was not sure how to require node modules as shown in the tf comment above, but figured out a solution.

Will describe my whole flow since the iPad required a work around which may be useful to someone.

Installing ijavascript

Just as shown above, but with one difference - note the familiar-log module I installed, which is to be used in the final step.

!npm init -y
!npm install ijavascript -g zeromq familiar-log --unsafe-perm
!ijsinstall
!jupyter-kernelspec list
!npm root -g

Modifying your .ipynb file without a computer

My solution was to save the notebook to GitHub Gists, edit the file there to set the kernel as described here, save it, then tap the Open in Colab button to send it back.

Importing npm modules into your script

See in step 1 where I installed the familiar-log module. Note the !npm root -g.

After confirming that JS works in my new notebook console.log(‘hello world’) I imported the module by using the value output by the root command. In my case: /tools/node/lib/node_modules. So instead of require(‘familiar-log’) I specified the location.

var log = require('/tools/node/lib/node_modules/familiar-log').log

log('hello');

log('hello').json({ world: true });

@jasonhargrove @LunaLuan @KokoDoko I made a simple to bootstrap template that allows you to run TensroflowJS on Google Colab, install modules in notebook, and run long running async code

https://dev.to/obenjiro/silence-of-the-fans-part-1-javascript-quickstart-5f3m

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neilljordan picture neilljordan  Â·  4Comments

RELNO picture RELNO  Â·  3Comments

pranayaryal picture pranayaryal  Â·  4Comments

take-kuma picture take-kuma  Â·  3Comments

JasonShin picture JasonShin  Â·  4Comments