Skip to content
Snippets Groups Projects
99 Run-Tensorboard.ipynb 5.27 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Running Tensorboard from Jupyter lab\n",
    "====================================\n",
    "---\n",
    "Introduction au Deep Learning  (IDLE) - S. Arias, E. Maldonado, JL. Parouty - CNRS/SARI/DEVLOG - 2020  \n",
    "Vesion : 1.0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Méthode 1 : Shell execute\n",
    "**Start**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensorbord started with pid 84593\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "tensorboard_start --logdir ./run/logs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tensorboard process not found...\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "tensorboard_stop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "\n",
    "# ---- Port number, \n",
    "PORT_JPY=\"$(id -u)\"\n",
    "PORT_TSB=\"$(( $PORT_J + 10000 ))\"\n",
    "HOST_G=\"$(hostname)\"\n",
    "SSH_CMD=\"/usr/bin/ssh -NL 8888:$HOST_G:$PORT_J -L 6006:$HOST_G:$PORT_T dahu.ciment\"\n",
    "\n",
    "tensorboard --port 21277 --host 0.0.0.0 --logdir ./run/logs &>/dev/null &"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Check**"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "84593\n"
     ]
    }
   ],
   "source": [
    "!echo $(ps ax | grep 'tensorboard --port 21277' | grep -v grep | awk '{print $1}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 83294 pts/0    Ss+    0:00 /bin/sh -c ps ax | grep tensorboard\n",
      " 83296 pts/0    S+     0:00 grep tensorboard\n",
      "/home/paroutyj/fidle/GTSRB\n"
     ]
    }
   ],
   "source": [
    "!ps ax | grep tensorboard\n",
    "!pwd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Stop**"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ended (82555)\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "p=\"$(ps ax | grep 'tensorboard --port 21277' | grep -v grep | awk '{print $1}')\"\n",
    "if [ -z ${p} ]; then echo \"No process\"; else kill $p; echo \"Ended ($p)\" ;  fi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Méthode 2 : Magic command\n",
    "**Start**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext tensorboard"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%tensorboard --port 21277 --host 0.0.0.0 --logdir ./run/logs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Stop**  \n",
    "No way... use bash method\n",
    "\n",
    "## Methode 3  : Tensorboard module\n",
    "\n",
    "**Start**"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorboard.notebook as tsb"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "      <iframe id=\"tensorboard-frame-d4ce7dab09616bd4\" width=\"100%\" height=\"800\" frameborder=\"0\">\n",
       "      </iframe>\n",
       "      <script>\n",
       "        (function() {\n",
       "          const frame = document.getElementById(\"tensorboard-frame-d4ce7dab09616bd4\");\n",
       "          const url = new URL(\"/\", window.location);\n",
       "          url.port = 21277;\n",
       "          frame.src = url;\n",
       "        })();\n",
       "      </script>\n",
       "  "
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
    "tsb.start('--port 21277 --host 0.0.0.0 --logdir ./run/logs')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Check**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a=tsb.list()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Stop**  \n",
    "No way... use bash method"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}