Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active November 22, 2022 08:43
Show Gist options
  • Save korakot/22abd6eccac229e9cb9a027b088b50d6 to your computer and use it in GitHub Desktop.
Save korakot/22abd6eccac229e9cb9a027b088b50d6 to your computer and use it in GitHub Desktop.
TFJS node.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "TFJS node.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "javascript",
"display_name": "Javascript"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/korakot/22abd6eccac229e9cb9a027b088b50d6/notebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ZVkF16NwcMsZ",
"colab_type": "code",
"colab": {}
},
"source": [
"#/* run this once, then reload, and then skip this\n",
"!npm install -g --unsafe-perm ijavascript\n",
"!ijsinstall --install=global # as fake comment */"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "skqAs_UHc8_P",
"colab_type": "code",
"colab": {}
},
"source": [
"// need this for running shell command\n",
"var { spawn } = require('child_process');\n",
"var sh = (cmd) => { \n",
" $$.async();\n",
" var sp = spawn(cmd, { cwd: process.cwd(), stdio: 'pipe', shell: true, encoding: 'utf-8' });\n",
" sp.stdout.on('data', data => console.log(data.toString()));\n",
" sp.stderr.on('data', data => console.error(data.toString()));\n",
" sp.on('close', () => $$.done());\n",
"};\n",
"sh('npm init -y');"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "FX9NhyWsU1BM",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "93a07cbd-8c8e-4a9f-f03b-ce61a8ec887b"
},
"source": [
"console.log(\"Hello World\")"
],
"execution_count": 32,
"outputs": [
{
"output_type": "stream",
"text": [
"Hello World\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "mz_hl90xmPFW",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
var run_async = async (pf) => {
$$.async();
await pf();
$$.done();
};
// in case you want tensorflow
sh('npm install @tensorflow/tfjs-node-gpu')
var tf = require('@tensorflow/tfjs-node-gpu');
console.log(tf.backend().isUsingGpuDevice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment